dev-master
9999999-devBundle for Boomgo the lightweight PHP ODM for MongoDB
The Requires
The Development Requires
- mageekguy/atoum dev-master
by Contributors
by Plemi
mongodb odm boomgo
Wallogit.com
2017 © Pedro Peláez
Bundle for Boomgo the lightweight PHP ODM for MongoDB
This bundle provides Symfony2 integration for Boomgo : it's a lightweight and simple datamapper for PHP and MongoDB., (*1)
What you could find in this bundle :, (*3)
Symfony2 developers, reviews and pull requests are welcomed !, (*4)
Prefered way is using Composer as it also downloads dependencies and have a built-in autoloader. At your project root level, create/update a composer.json file with :, (*5)
{
"require": {
"plemi/boomgo-bundle": "dev-master"
}
}
Otherwise, you can use Git directly with cloning in your vendor directory both Boomgo and PlemiBoomgoBundle, but as you've done that before and as there's plenty of a examples, we won't describe it here., (*6)
Here are the 2 namespaces that you have to register in your autoloader :, (*7)
<?php // app/autoload.php 'Boomgo' => 'path/to/vendor/Retentio/Boomgo/src', 'Plemi' => 'path/to/vendor/bundles',
Last but not least, register it in your AppKernel :, (*8)
<?php
// app/AppKernel.php
$bundles = array(
...
new Plemi\Bundle\BoomgoBundle\PlemiBoomgoBundle(),
...
);
This bundle works with just one requirement: you have to define at least one connection (but can register as many as you need)., (*9)
A Connection represents a database name, a server and various options, the same as PHP Mongo., (*10)
plemi_boomgo:
connections:
myLocalConnection:
database: myMongoDatabase
This bundle works with a default_connection name by default default. Changes in the previous snippet are :, (*11)
plemi_boomgo:
default_connection: myLocalConnection
connections:
myLocalConnection:
database: myMongoDatabase
Need more customization on your connection ? Here's what we can call a full sample :, (*12)
plemi_boomgo:
default_connection: myLocalConnection
connections:
myLocalConnection:
database: myMongoDatabase
myRemoteConnection:
server: my.remotedomain.com
database: myMongoDatabase
options:
connect: true
replicatSet: myReplicaSet
You have to defined mapping for your document following Boomgo explanations. Oh by the way, an official documentation website is coming., (*13)
Then we need to generate Mapper and Repository classes :, (*14)
php app/console boomgo:generate:mappers MyBundleName php app/console boomgo:generate:repositories MyBundleName
Now that we have defined the configuration, generated mappers and repositories, what's the trick ? This bundle gives the hard work to the repository class : but it's up to you !, (*15)
You can call the manager service, asking for the repository class of a valid document on demand or store your implementation directly within the generated repository class. Beware of future generation process, as it rewrites the whole file., (*16)
Well, let's imagine we want to query a user collection and get the five latest :, (*17)
<?php
// My\Bundle\Repository\UserRepository.php
public function findOneByNameAndAge($name, $age)
{
// Declare your query
$query = array('name' => $name, 'age' => $age)
// Process it
$results = $this->getMongoCollection()->findOne($query);
// MongoCursor to Document object
$document = $this->getMapper()->unserialize($results)
return $document;
}
Then we are able to call :, (*18)
<?php
// My\Bundle\Controller\UserController.php
$repository = $this->container->get('plemi_boomgo.manager')->getRepository('My\Bundle\Document\User');
$user = $repository->findOneByNameAndAge('foo', 23);
In order to run unit tests, you have to install atoum via Composer and then execute it that way :, (*19)
php composer.phar update --dev php vendor/bin/atoum -d Tests
As a roadmap, planned features are :, (*20)
Bundle for Boomgo the lightweight PHP ODM for MongoDB
mongodb odm boomgo