mongator / pimple
Provider to use Mongator with Pimple/Silex framework
v2.0.0
2014-05-21 12:52 UTC
Requires
- php: >=5.3.0
- mongator/mongator: 1.*
- pimple/pimple: 2.*
- symfony/console: 2.4.*
Requires (Dev)
- cilex/console-service-provider: 2.0.*@dev
Suggests
- ext-yaml: Needed to reaad class configs in YAML files
This package is not auto-updated.
Last update: 2024-12-17 08:23:17 UTC
README
Provider for using Mongator with Pimple/Silex framework
Requirements
- PHP 5.3.x
- Unix system
- fabpot/pimple
- mongator/mongator
Installation
The recommended way to install Mongator/Silex is through composer. You can see the package information on Packagist.
{ "require": { "mongator/pimple": "2.*" } }
Parameters
mongator.connection.dsn
(default 'mongodb://localhost:27017'): database connection stringmongator.connection.database
: the database namemongator.connection.name
(default 'default'): the name of the connectionmongator.metadata.class
: The metadata factory class namemongator.logger
(default null): instance of a logger classmongator.cache.fields
(default ArrayCache): instance of a mongator cache driver used in fields cachemongator.cache.data
(default ArrayCache): instance of a mongator cache driver used in data cachemongator.extensions
(default Array()): array of extension instancesmongator.models.output
: output path of the classesmongator.classes.config
(default Array()): The config classes contain the information of the classesmongator.classes.yaml.path
: A valid dir with YAML definitions of the config classes
Registrating
$app->register(new Mongator\Pimple\MondatorServiceProvider()); $app->register(new Mongator\Pimple\MongatorServiceProvider(), array( 'mongator.metadata.class' => 'Model\Mapping\Metadata', 'mongator.models.output' => 'src/', 'mongator.connection.database' => 'your_db' ));
Usage
use Symfony\Component\HttpFoundation\Response; $app->post('/article', function ($id) use ($app) { $articleRepository = $app['mongator']->getRepository('Model\Article'); $article = $articleRepository->findOneById($id); return new Response('', 201); });
** Remember, before using the models you must generate them. (You can use the command provided with this package.) **
Commands
With this package you can find three useful commands:
mongator:generate
: Processes config classes and generates the files of the classes.mongator:indexes
: Ensures the indexes of all repositoriesmongator:fix
: Fixes all the missing references.
You need the suggested package cilex/console-service-provider
to use console commands on you Silex setup.
Tests
Tests are in the tests
folder.
To run them, you need PHPUnit.
Example:
$ phpunit --configuration phpunit.xml.dist
License
MIT, see LICENSE