PHPackages                             coderxlsn/phly-mongo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. coderxlsn/phly-mongo

ActiveLibrary[Database &amp; ORM](/categories/database)

coderxlsn/phly-mongo
====================

ZF2 Module providing services and paginators surrounding MongoDB

1.1.4(9y ago)19MITPHPPHP &gt;=5.5

Since Jul 17Pushed 9y agoCompare

[ Source](https://github.com/coderxlsn/PhlyMongo)[ Packagist](https://packagist.org/packages/coderxlsn/phly-mongo)[ Docs](https://github.com/weierophinney/PhlyMongo)[ RSS](/packages/coderxlsn-phly-mongo/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (12)Versions (9)Used By (0)

PhlyMongo - ZF2 Module for Mongo Integration
============================================

[](#phlymongo---zf2-module-for-mongo-integration)

[![Build Status](https://camo.githubusercontent.com/4f0f7e2e7d370b10eae2c6a6b3aa3a8c86a341d7963ff667c6c2fb58f6c99867/68747470733a2f2f7472617669732d63692e6f72672f636f646572786c736e2f50686c794d6f6e676f2e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/coderxlsn/PhlyMongo)

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
------------

[](#installation)

Simplest is to add the following to `composer.json`:

```
{
    "minimum-stability": "dev",
    "require": {
        "coderxlsn/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/coderxlsn/PhlyMongo vendor/PhlyMongo
```

Usage
-----

[](#usage)

### Services

[](#services)

In order to remain as flexible as possible, the service factories require that you pass information to the constructors. As such, you should typically configure and setup the factories via your `Module.php` definition:

```
namespace My;

use PhlyMongo\MongoCollectionFactory;
use PhlyMongo\MongoDbFactory;

class Module
{
    public function getServiceConfig()
    {
        return array('factories' => array(
            'My\Mongo'           => 'PhlyMongo\MongoConnectionFactory',
            'My\MongoDB'         => new MongoDbFactory('my-site', 'My\Mongo'),
            'My\MongoCollection' => new MongoCollectionFactory('some-stuff', 'My\MongoDB'),
        ));
    }
}
```

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

```
namespace My;

use PhlyMongo\MongoCollectionFactory;
use PhlyMongo\MongoConnectionFactory;
use PhlyMongo\MongoDbFactory;

class Module
{
    public function getServiceConfig()
    {
        return array('factories' => array(
            'My\Mongo'           => function ($services) {
                $config = $services->get('config');
                $config = $config['my']['mongo'];
                $factory = new MongoConnectionFactory($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 Mongo classes.

### Hydrating Cursor

[](#hydrating-cursor)

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

Pass a `MongoCursor` instance to the constructor, along with a hydrator and a prototype object, and you're set:

```
use PhlyMongo\HydratingMongoCursor;
use Zend\Stdlib\Hydrator\ObjectProperty;

class Status
{
    public $_id;
    public $name;
    public $email;
    public $status;
}

$resultset = new HydratingMongoCursor(
    $collection->find(),
    new ObjectProperty,
    new Status
);
foreach ($resultset as $status) {
    printf('%s : %s', $status->name, $status->email, $status->status);
}
```

### Paginator Adapter

[](#paginator-adapter)

The paginator adapter allows you to use a `MongoCursor` with `Zend\Paginator`.

Pass a `MongoCursor` to the constructor, and then pass the adapter to the paginator instance.

```
use PhlyMongo\PaginatorAdapter as MongoPaginatorAdapter;
use Zend\Paginator\Paginator;

$adapter   = new MongoPaginatorAdapter($collection->find());
$paginator = new Paginator($adapter);
$paginator->setCurrentPageNumber(5);
$paginator->setItemCountPerPage(10);

foreach ($paginator as $item) {
    // only receiving up to 10 items, starting at offset 50
}
```

### Hydrating Paginator Adapter

[](#hydrating-paginator-adapter)

This builds on the paginator adapter, and simply alters it to accept specifically a `PhlyMongo\HydratingMongoCursor` in the constructor, allowing you to return objects of a specific type during iteration.

```
use PhlyMongo\HydratingMongoCursor;
use PhlyMongo\HydratingPaginatorAdapter as MongoPaginatorAdapter;
use Zend\Paginator\Paginator;

$adapter   = new MongoPaginatorAdapter(new HydratingMongoCursor(
    $collection->find(),
    new ObjectProperty,
    new Status
));
$paginator = new Paginator($adapter);
$paginator->setCurrentPageNumber(5);
$paginator->setItemCountPerPage(10);

foreach ($paginator as $item) {
    // only receiving up to 10 items, starting at offset 50
    printf('%s : %s', $status->name, $status->email, $status->status);
}
```

###  Health Score

27

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 76.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~108 days

Recently: every ~70 days

Total

7

Last Release

3617d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.3.23

1.1.0PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d37e5975c58d2fd7815071be71a720608c51d2911484b21dcf41b95bf822366?d=identicon)[coderxlsn](/maintainers/coderxlsn)

---

Top Contributors

[![weierophinney](https://avatars.githubusercontent.com/u/25943?v=4)](https://github.com/weierophinney "weierophinney (55 commits)")[![manchuck](https://avatars.githubusercontent.com/u/192776?v=4)](https://github.com/manchuck "manchuck (10 commits)")[![coderxlsn](https://avatars.githubusercontent.com/u/2877158?v=4)](https://github.com/coderxlsn "coderxlsn (7 commits)")

---

Tags

zendmongodbmodulezf2mongo

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/coderxlsn-phly-mongo/health.svg)

```
[![Health](https://phpackages.com/badges/coderxlsn-phly-mongo/health.svg)](https://phpackages.com/packages/coderxlsn-phly-mongo)
```

###  Alternatives

[hounddog/doctrine-data-fixture-module

Zend Framework 2 Module that provides Doctrine Data-Fixture functionality

37335.2k9](/packages/hounddog-doctrine-data-fixture-module)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
