Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 17, 2025. It is now read-only.
/PhlyMongoPublic archive

ZF2 module for handling Mongo services, resultsets, and pagination

NotificationsYou must be signed in to change notification settings

phly/PhlyMongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️Archived 2025-08-17

Use at your own risk.

Build Status

PhlyMongo provides the following to assist with Mongo usage in ZF2:

  • Hydrating Mongo resultset
  • Mongo paginator adapter
  • Mongo paginator adapter for hydrating resultsets
  • Configurable service factories for the Mongo, MongoDB, and MongoCollection classes

Installation

Simplest is to add the following tocomposer.json:

{"minimum-stability":"dev","require":{"phly/phly-mongo":"~1.0-dev"}}

And then run:

php composer.phar install

Alternately, use git to install this as a submodule:

git submodule add git://github.com/phly/PhlyMongo vendor/PhlyMongo

Usage

Services

In order to remain as flexible as possible, the service factories require thatyou pass information to the constructors. As such, you should typicallyconfigure and setup the factories via yourModule.php definition:

namespaceMy;usePhlyMongo\MongoCollectionFactory;usePhlyMongo\MongoDbFactory;class Module{publicfunctiongetServiceConfig()    {returnarray('factories' =>array('My\Mongo'           =>'PhlyMongo\MongoConnectionFactory','My\MongoDB'         =>newMongoDbFactory('my-site','My\Mongo'),'My\MongoCollection' =>newMongoCollectionFactory('some-stuff','My\MongoDB'),        ));    }}

If you want the server, server options, database, collection, or any servicenames to be dynamic, consider wrapping the factories in closures, and passingin configuration:

namespaceMy;usePhlyMongo\MongoCollectionFactory;usePhlyMongo\MongoConnectionFactory;usePhlyMongo\MongoDbFactory;class Module{publicfunctiongetServiceConfig()    {returnarray('factories' =>array('My\Mongo'           =>function ($services) {$config =$services->get('config');$config =$config['my']['mongo'];$factory =newMongoConnectionFactory($config['server'],$config['server_options']);return$factory->createService($services);            },// and so on //        ));    }}

However, if you need to do this, you might just as easily use the native Mongoclasses.

Hydrating Cursor

The hydrating cursor is useful as a way to map result sets to objects.

Pass aMongoCursor instance to the constructor, along with a hydrator and aprototype object, and you're set:

usePhlyMongo\HydratingMongoCursor;useZend\Stdlib\Hydrator\ObjectProperty;class Status{public$_id;public$name;public$email;public$status;}$resultset =newHydratingMongoCursor($collection->find(),newObjectProperty,newStatus);foreach ($resultsetas$status) {printf('%s <%s>: %s',$status->name,$status->email,$status->status);}

Paginator Adapter

The paginator adapter allows you to use aMongoCursor withZend\Paginator.

Pass aMongoCursor to the constructor, and then pass the adapter to thepaginator instance.

usePhlyMongo\PaginatorAdapterasMongoPaginatorAdapter;useZend\Paginator\Paginator;$adapter   =newMongoPaginatorAdapter($collection->find());$paginator =newPaginator($adapter);$paginator->setCurrentPageNumber(5);$paginator->setItemCountPerPage(10);foreach ($paginatoras$item) {// only receiving up to 10 items, starting at offset 50}

Hydrating Paginator Adapter

This builds on the paginator adapter, and simply alters it to acceptspecifically aPhlyMongo\HydratingMongoCursor in the constructor, allowingyou to return objects of a specific type during iteration.

usePhlyMongo\HydratingMongoCursor;usePhlyMongo\HydratingPaginatorAdapterasMongoPaginatorAdapter;useZend\Paginator\Paginator;$adapter   =newMongoPaginatorAdapter(newHydratingMongoCursor($collection->find(),newObjectProperty,newStatus));$paginator =newPaginator($adapter);$paginator->setCurrentPageNumber(5);$paginator->setItemCountPerPage(10);foreach ($paginatoras$item) {// only receiving up to 10 items, starting at offset 50printf('%s <%s>: %s',$status->name,$status->email,$status->status);}

About

ZF2 module for handling Mongo services, resultsets, and pagination

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors5

Languages


[8]ページ先頭

©2009-2025 Movatter.jp