Configuration

Classes loader

Mandango uses namespaces and class names standards in PHP 5.3, and includes the ClassLoader component of Symfony2:

require_once('/path/to/mandango/vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php');

use Symfony\Component\ClassLoader\UniversalClassLoader;

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
    'Mandango\Mondator' => '/path/to/mondator/src',
    'Mandango'          => '/path/to/mandango/src',
    'Model'             => dirname('/path/to/Model'),
));
$loader->register();

Tip

You can use any class loader that implements the standards in PHP 5.3.

The Mandango

To use Mandango you have to create a mandango object and assign it any connection.

To create the mandango object you have to pass it the metadata factory object and a cache object. The metadata factory class is generated by Mandango, and for the cache you can use any implementation of the Mandango\Cache\CacheInterface interface:

use Mandango\Cache\FilesystemCache;
use Mandango\Connection;
use Mandango\Mandango;
use Model\Mapping\MetadataFactory;

$metadataFactory = new MetadataFactory();
$cache = new FilesystemCache('/path/to/query/cache/dir');
$mandango = new Mandango($metadataFactory, $cache);
$connection = new Connection('mongodb://localhost:27017', 'database_name');
$mandango->setConnection('my_connection', $connection);

If you want to specify a default connection in the mandango object you have to do it explicitly:

$mandango->setDefaultConnectionName('my_connection');

Connections

With Mandango you can use the number of connections that you want. They are lazy, so they only connect to the server when they are going to be used:

use Mandango\Mandango;
use Mandango\Connection;

// assigning several connections
$mandango->setConnections(array(
    'local'  => new Connection('mongodb://localhost:27017', 'database_local'),
    'global' => new Connection('mongodb://localhost:27017', 'database_global'),
));

Options

You can also pass as a third parameter the options in the connection:

use Mandango\Connection;

$connection = new Connection('mongodb://localhost:27017', 'database', array(
    'persistent' => true,
));

Note

You can see all the options that you can use in the connections in the MongoDB documentation in PHP