2017 © Pedro Peláez
 

library mongo-wrapper

MongoDB matryoshka wrapper

image

matryoshka-model/mongo-wrapper

MongoDB matryoshka wrapper

  • Thursday, April 28, 2016
  • by leodido
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,038 Installations
  • PHP
  • 31 Dependents
  • 3 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

, (*1)

, (*2)

Matryoshka wrapper for MongoDB

Latest Stable Version Build Status Coveralls branch Total Downloads Matryoshka Model's Slack, (*3)

Use MongoDB as data gateway for Matryoshka., (*4)

Community

For questions and support please visit the slack channel (get an invite here)., (*5)

Installation

Install it using composer., (*6)

Add the following to your composer.json file:, (*7)

"require": {
    "matryoshka-model/mongo-wrapper": "~0.8.0"
}

Configuration

This library provides two abstract factories for Zend\ServiceManager to make MongoDb and MongoCollection available as services. In order to use them in a ZF2 application, register the provided factories through the service_manager configuration node:, (*8)

'service_manager'    => [
    'abstract_factories' => [
        'Matryoshka\Model\Wrapper\Mongo\Service\MongoDbAbstractServiceFactory',
        'Matryoshka\Model\Wrapper\Mongo\Service\MongoCollectionAbstractServiceFactory',
    ],
],

Then in your configuration you can add the mongodb and mongocollection nodes and configure them as in example:, (*9)

'mongodb' => [
    'Application\MongoDb\YourDatabaseName' => [
        'hosts' => '127.0.0.1:27017',
        'database' => 'yourDatabaseName'
    ],
    ...
],

'mongocollection'    => [
    'Application\DataGateway\YourCollectionName' => [
        'database'   => 'Application\MongoDb\YourDatabaseName',
        'collection' => 'yourCollectionName'
    ],
    ...
],

Usage

This wrapper provides extensions and default implementations for using MongoCollection as a datagateway., (*10)

Main concepts:, (*11)

  1. Inject a Matryoshka\Model\Wrapper\Mongo\Criteria\ActiveRecordCriteria instance into your Matryoshka\Model\Object\AbstractActiveRecord objects, (*12)

    This way the matryoshka Active Record implementation will work with your MongoDB collections, (*13)

  2. Matryoshka\Model\Wrapper\Mongo\Paginator, (*14)

    MongoPaginatorAdapter is a paginator adapter that can be used within paginable criterias, (*15)

  3. Matryoshka\Model\Wrapper\Mongo\ResultSet, (*16)

    HydratingResultSet makes the counting functionality working correctly with MongoCursor datasources, (*17)

NOTES

It's important to always use the HydratingResultSet class included in this package because MongoCursor does not implement the Countable and MongoCursor::count() must be called passing true as parameter., (*18)

Components

  • Matryoshka\Model\Wrapper\Mongo\Criteria directory contains the aforementioned ActiveRecordCriteria matryoshka criteria., (*19)

  • Matryoshka\Model\Wrapper\Mongo\Hydrator directory contains, (*20)

    • ClassMethods, an hydrator that can be used with matryoshka objects when you have MongoDB collections as datagateways, (*21)

    • NamingStrategy\DefaultNamingStrategy and NamingStrategy\UnderscoreNamingStrategy, two strategies that can be overridden to setup the naming rules map of your fields. By default, both convert _id to id., (*22)

    • Strategy\*, some common strategies for MongoDB., (*23)

  • Matryoshka\Model\Wrapper\Mongo\Paginator directory contains the aforementioned MongoPaginatorAdapter adapter., (*24)

  • Matryoshka\Model\Wrapper\Mongo\ResultSet contains the aforementioned HydratingResultSet which extends matryoshka's HydratingResultSet to make the MongoCursor counting functionality working properly., (*25)

  • Matryoshka\Model\Wrapper\Mongo\Service contains abstract service factories generally aimed at instantiation of \MongoCollection and \MongoDb objects. Use mongocollection and mongodb configuration nodes to respectively setup them (see above)., (*26)

Continuous integration

CI provided through TravisCI., (*27)

This wrapper is tested against the following MongoDB PHP clients: 1.4.5, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 1.5.3, 1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.6.0, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9, 1.6.10, 1.6.11, 1.6.12, 1.6.13., (*28)


Analytics, (*29)

The Versions