2017 © Pedro Peláez
 

symfony-bundle boomgo-bundle

Bundle for Boomgo the lightweight PHP ODM for MongoDB

image

plemi/boomgo-bundle

Bundle for Boomgo the lightweight PHP ODM for MongoDB

  • Sunday, July 8, 2012
  • by dguyon
  • Repository
  • 2 Watchers
  • 2 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PlemiBoomgoBundle

This bundle provides Symfony2 integration for Boomgo : it's a lightweight and simple datamapper for PHP and MongoDB., (*1)

Build Status, (*2)

Gentle introduction

What you could find in this bundle :, (*3)

  • a manager to ease the use of Repository class defined as a public service (DIC FTW)
  • console commands that will generate Mapper and Repository from your Document annoted classes

Symfony2 developers, reviews and pull requests are welcomed !, (*4)

How to install ?

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(),
      ...
);

Show me how to use it

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

Wait, what about unit tests ?

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

Is it over yet ?

As a roadmap, planned features are :, (*20)

  • a true query logger
  • a dedicated tab within Symfony2 WebDebugToolbar

The Versions

08/07 2012

dev-master

9999999-dev

Bundle for Boomgo the lightweight PHP ODM for MongoDB

  Sources   Download

The Requires

 

The Development Requires

  • mageekguy/atoum dev-master

mongodb odm boomgo