Zend框架:Zend_Nosql_Mongo组件建议
Zend_Nosql_Mongo Zend_Nosql_Mongo |
http://framework.zend.com/wiki/display/ZFDEV/Zend_Nosql_Mongo http://framework.zend.com/wiki/display/ZFDEV/Zend_Nosql_Mongo |
Valentin Golev 瓦伦丁Golev |
TBD待定 |
1.0 - 6 January 2010: Initial Draft. 1.0 - 2010年1月6日:初步草案。 (wiki revision: 9) (维基修订:9) |
<style type="text/css"> <!-- div.rbtoc1262799713448 {margin-left:0px; padding:0px} div.rbtoc1262799713448 ul {list-style:none; margin-left:0px; padding-left:0px} div.rbtoc1262799713448 li {margin-left:0px; padding-left:0px} --> </style>
Zend_Nosql_Mongo is a namespace containing wrappers and adapters for PHP Mongo classes, intended to make them more handy, simple and compatible with other ZF classes, such as Zend_Paginator. Zend_Nosql_Mongo是一个命名空间包含PHP蒙戈类的包装和适配器,旨在使他们更方便,简单,并与其他的ZF类,如Zend_Paginator,兼容。
Users create a link to Database, providing connection and db information to the Zend_Nosql_Mongo_Db.用户可以创建一个到数据库的链接,提供连接和DB信息的Zend_Nosql_Mongo_Db。
Then they can get a link to a specific collection (which will be created, if not exists).然后,他们可以得到一个链接到一个特定的集合(,如果不存在将创建)。
Users can create a Zend_Nosql_Mongo_Object from any array, as soon as all its values (recursively) can be converted to Mongo types.用户可以从任何数组创建一个Zend_Nosql_Mongo_Object,只要其所有值(递归)可以转换为蒙戈类型。 They can save Zend_Nosql_Mongo_Object to any collection.他们可以节省Zend_Nosql_Mongo_Object任何集合。 Saving operation, as well as retrieving, returns an instance of Zend_Nosql_Mongo_Document, which has a specific _id and knows a name of its collection.节能运行,以及检索,返回的Zend_Nosql_Mongo_Document实例,其中有一个具体_id的,并且知道其收集的名称。
Users can query any collection.用户可以查询任何集合。 They can add more and more conditions to the query.他们可以添加越来越多的条件查询。 When they are done, they can transform the query to a cursor and iterate or array-access it.当他们完成后,他们可以改变一个游标查询和迭代或数组访问。
Users can set a specific class for a document of specific collection.用户可以设置一个特定类的一个特定集合的文件。 It must implement Zend_Nosql_Mongo_Document_Interface or, even better, inherit from Zend_Nosql_Mongo_Document.它必须实现Zend_Nosql_Mongo_Document_Interface,或者甚至更好,从Zend_Nosql_Mongo_Document继承。 In this case, all cursors from queries on this collection will return the specified class.在这种情况下,所有游标在此集合的查询将返回指定的类。
Users can make document schema more strict by providing validators, strong typing and disallowing arbitrary fields for any collection.用户可以通过提供校验,强类型,不允许任何集合的任意领域更加严格的文档架构。 Values of each typed field will be tested if it has one of specified types.每个类型的字段的值将被测试,如果有指定的类型之一。 If not, it will be converted to the first of the type in the list.如果不是,它会被转换为类型列表中的第一。 If the conversion fails and 'null' is not allowed for the field, the exception is thrown instead of saving a document.如果转换失败,'null'是不是允许的领域,抛出异常,而不是保存文档。
$db
= Zend_Nosql_Mongo_Db(null,
'testdb'
);
$coll
=
$db
->getCollection(
'testcollection'
);
for
(
$i
= 0;
$i
< 100;
$i
++) {
echo
$coll
->save(
new
Zend_Nosql_Mongo_Object(
array
(
'field'
=>
$i
))->getId(),
" is another unique id\n"
;
}
$q
=
$coll
->ensureIndex(
'field'
)->query()->lowerThan(
'field'
, 10);
foreach
(
$q
as
$item
)
echo
$item
->field,
" must be lower than 10!\n"
;
|
class
Zend_Nosql_Mongo_Db {
public
function
__construct(
$host
= null,
$dbname
= null) {}
public
function
setOptions(
$options
) {}
public
function
getCollection(
$collectionName
) {}
}
class
Zend_Nosql_Mongo_Collection
implements
IteratorAggregate, Countable {
public
function
__construct(
$db
= null,
$name
= null) {}
public
function
setOptions(
$options
) {}
public
function
setDocumentClass() {}
public
function
ensureIndex(
$field
,
$direction
) {}
public
function
save(Zend_Nosql_Mongo_Object_Interface
$object
) {}
public
function
query() {}
public
function
count
() {}
public
function
getIterator() {}
public
function
setFieldTypes(
$field
,
$types
) {}
public
function
setFieldsTypes(
$fieldstypes
) {}
public
function
setFieldValidator(
$field
,
$validator
) {}
}
class
Zend_Nosql_Mongo_Document
extends
Zend_Nosql_Mongo_Object
implements
Zend_Nosql_Mongo_Document_Interface {
public
function
__construct(
$data
, Zend_Nosql_Mongo_Collection
$collection
) {}
public
function
getId() {}
public
function
getCollection() {}
public
function
save() {}
public
function
isChanged() {}
public
function
commit() {}
/*
* and functions for atomic operations
*/
}
interface
Zend_Nosql_Mongo_Document_Interface
extends
Zend_Nosql_Mongo_Object_Interface {
public
function
__construct(
$data
, Zend_Nosql_Mongo_Collection
$collection
) {}
public
function
getId() {}
public
function
getCollection() {}
public
function
save() {}
public
function
isChanged() {}
public
function
commit() {}
//and functions for atomic operations
}
class
Zend_Nosql_Mongo_Object {
public
function
__construct(
$data
) {}
function
__get() {}
function
__set() {}
}
interface
Zend_Nosql_Mongo_Object_Interface {
public
function
__construct(
$data
) {}
}
class
Zend_Nosql_Mongo_Query
implements
IteratorAggregate, Countable {
public
function
__construct(Zend_Nosql_Mongo_Collection
$collection
) {}
public
function
getCursor() {}
public
function
count
() {}
public
function
getIterator() {}
/*
* and functions for all conditions
*/
}
class
Zend_Nosql_Mongo_Cursor
implements
Iterator, Countable {
public
function
__construct(Zend_Nosql_Mongo_Collection
$collection
,
$query
) {}
public
function
current() {}
public
function
key() {}
public
function
next() {}
public
function
rewind
() {}
public
function
valid() {}
public
function
count
() {}
}
|
Jan 21, 2010 2010年01月21日,
Feb 23, 2010 2010年02月23日,
By the way my prototype mongodb adapter is coming along well.顺便说一下,我的原型mongodb的适配器是相处得很好。 It's taken a little longer than i expected它比我预想的长一点 . 。 However it has become a completely different beast to what Valentin layed out above.然而,它已成为什么瓦伦丁上面奠定了一个完全不同的野兽。 Shortly i will have it available to discuss.不久,我会讨论。 Currently it does not support advanced queries, however i know Valentin is the author of mongodloid and figured i'd leave that to his area of expertise.目前它不支持高级的查询,但是我知道瓦伦丁mongodloid作者和我离开,他的专长领域。
Feb 23, 2010 2010年02月23日,
Mar 03, 2010 2010年03月03,
Mar 12, 2010 2010年03月12日,
Sounds great, looking forward to testing it.听起来不错,期待测试。 Have you considered adding support for master/slave configurations?你有没有考虑加入支持主/从配置吗?
http://www.snailinaturtleneck.com/blog/2010/02/01/mongo-mailbag-masterslave-configuration/ http://www.snailinaturtleneck.com/blog/2010/02/01/mongo-mailbag-masterslave-configuration/
Mar 24, 2010 2010年03月24日
Mar 29, 2010 2010年03月29日
Sorry for taking so long.对不起,这么长时间。 I didn't actually spend all that time writing docs我其实没有花所有的时间写作文档 ... ... ... I found a bug that required a significant modification of the source.我发现了一个错误,需要重大修改的源。
Anyway here it is http://github.com/coen-hyde/Shanty-Mongo反正这里是http://github.com/coen-hyde/Shanty-Mongo
The docs are a bit lack luster but it should give you the idea.该文档是有点缺乏光泽,但它应该给你的想法。
Since this adapter is completely different to the proposal above i'll sign Zend's contributor form and create a separate proposal.由于此适配器是完全不同的上述建议,我会签署了Zend的贡献形式和创建一个单独的建议。
One problem with my proposal is it requires php5.3.我的建议的一个问题是它需要PHP5.3。 But i figured the Zend Framework would eventually move to 5.3 or would allow 5.3 only components in the extras.但我想,Zend框架,最终迁移到5.3,或将允许在额外5.3的组件。 It would be possible to modify the adapter to not use late static binding but it should be a last resort as it would significantly reduce the developer friendliness.这将有可能修改适配器,不使用后期静态绑定,但它应该是最后的手段,因为它会显着降低开发人员友好。
Any testing or feedback would is more than welcome.任何测试或反馈欢迎。 Unit tests would be worshiped.单元测试会被崇拜。
Mar 30, 2010 2010年03月30日,
Hi Dennis,您好丹尼斯,
Re Connections: Yeah i haven't put much thought into the connection aspect at all, completely open to suggestion from those who know better.重新连接:我没有连接方面投入过多考虑所有,完全开放,更懂得那些建议。
Re Validators and Filters: I did originally have them separate but it was a bit ugly having the configuration options for properties spread across multiple arrays.重新校验器和过滤器:我没有让他们分开,但它是一个有点难看分散在多个阵列的属性配置选项。 Plus there are other requirements that are not validators or filters such as the 'AsReference' and planned 'AsPartial'.再加上有其他不属于验证器或过滤器,如“AsReference'计划”AsPartial“的要求。 If it this is something that bothers people, maybe we can prefix the requirements, such as 'Filter:{$filterName}' and 'Validator:{$validatorName}'如果这是困扰人们的东西,也许我们可以前缀的要求,如“过滤器:{$ filterName}”和“验证:{$ validatorName}”
Yes closures are supported in 5.3.支持5.3是封。 The reason i have used closures in this instance is to allow the developers to supply custom requirement creators.我已经使用在这种情况下封的原因是为了让开发人员提供定制要求创作者。
Magnier Magnier