df/silex-doctrine-mongodb-provider

Silex Doctrine MongoDB Provider

1.0.1 2016-08-03 09:40 UTC

This package is not auto-updated.

Last update: 2024-11-23 20:47:45 UTC


README

Just another Silex service provider for mongodb, based on Dominik Zogg dominik.zogg@gmail.com great repository saxulum-doctrine-mongodb-provider containing some improvements and refactoring to gain compatibility for silex 2.n/pimple 3.n and PHP 7.n

Software License System Version PHP 7 ready Build Status

Features

  • Support for MongoDB inside Silex (it does NOT PROVIDE the ODM integration)
  • Support for PHP7 using "alcaeus/mongo-php-adapter" as wrapper for deprecated ext-mongo module
  • ODM integration will provide by df/silex-doctrine-mongodb-odm-provider (take a look)

Requirements

  • PHP >= 5.5.n
  • Silex 2.n (pimple 3.n)
  • Doctrine MongoDb (>= 1.3.0)

Installation

Using composer df/silex-doctrine-mongodb-provider.

composer require df/silex-doctrine-mongodb-provider 

Setup

  • Example for one connection:
$app->register(new DoctrineMongoDbProvider(), [
    'mongodb.options' => [
        'server' => 'mongodb://localhost:27017',
        'options' => [
            'username' => 'your-username',
            'password' => 'your-password',
            'db' => 'mongo_db_01'
        ]
    ]
]);
  • Example for multiple connections:
$app->register(new DoctrineMongoDbProvider(), [
    'mongodbs.options' => [
        'mongodb1' => [
            'server' => 'mongodb://localhost:27017',
            'options' => [
                'username' => 'your-username',
                'password' => 'your-username',
                'db' => 'mongo_db_01'
            ]
        ],
        'mongodb2' => [
            'server' => 'mongodb://localhost:27018',
            'options' => [
                'username' => 'your-username',
                'password' => 'your-username',
                'db' => 'mongo_db_02'
            ]
        ]
    ]
));

Usage

  • Example for one connection:
$document = ['key' => 'value'];

$app['mongodb']
    ->selectDatabase('mongo_db_01')
    ->selectCollection('sample')
    ->insert($document)
;
  • Example for multiple connections:
$document = ['key' => 'value'];

$app['mongodbs']['mongo1']
    ->selectDatabase('mongo_db_01')
    ->selectCollection('sample')
    ->insert($document)
;

Copyright