コード例 #1
0
 protected function registerMongator()
 {
     $this->app['mongator'] = $this->app->share(function ($app) {
         $mongator = new Mongator($app['mongator.metadata'], $this->getLogger());
         $mongator->setFieldsCache($app['mongator.cache.fields']);
         $mongator->setDataCache($app['mongator.cache.data']);
         $mongator->setConnection($app['config']['mongator::connection_name'], $app['mandango.connection']);
         $mongator->setDefaultConnectionName($app['config']['mongator::connection_name']);
         return $mongator;
     });
 }
コード例 #2
0
 public function register(Container $app)
 {
     $app['mongator'] = function ($app) {
         $mongator = new Mongator($app['mongator.metadata'], $app['mongator.logger']);
         $mongator->setFieldsCache($app['mongator.cache.fields']);
         $mongator->setDataCache($app['mongator.cache.data']);
         $mongator->setConnection($app['mongator.connection.name'], $app['mandango.connection']);
         $mongator->setDefaultConnectionName($app['mongator.connection.name']);
         return $mongator;
     };
     $app['mongator.metadata'] = function ($app) {
         if (!class_exists($app['mongator.metadata.class'])) {
             throw new \LogicException('You must register a valid "mongator.metadata.class" to this provider, maybe you forget to generate your models?');
         }
         return new $app['mongator.metadata.class']();
     };
     $app['mandango.connection'] = function ($app) {
         if (!$app['mongator.connection.dsn']) {
             throw new \LogicException('You must register "mongator.connection.dsn" to this provider');
         }
         if (!$app['mongator.connection.database']) {
             throw new \LogicException('You must register "mongator.connection.database" to this provider');
         }
         return new Connection($app['mongator.connection.dsn'], $app['mongator.connection.database']);
     };
     $app['mongator.cache.fields'] = function ($app) {
         return new ArrayCache();
     };
     $app['mongator.cache.data'] = function ($app) {
         return new ArrayCache();
     };
     $app['mongator.metadata.class'] = null;
     $app['mongator.logger'] = null;
     $app['mongator.connection.name'] = 'default';
     $app['mongator.connection.dsn'] = 'mongodb://localhost:27017';
     $app['mongator.connection.database'] = null;
     $app['mongator.classes.config'] = array();
     $app['mongator.classes.yaml.path'] = null;
 }
コード例 #3
0
ファイル: RepositoryTest.php プロジェクト: mongator/mongator
 public function testCollection()
 {
     $mongator = new Mongator($this->metadataFactory, $this->cache);
     $connection = new Connection($this->server, $this->dbName . '_collection');
     $mongator->setConnection('default', $connection);
     $mongator->setDefaultConnectionName('default');
     $collection = $mongator->getRepository('Model\\Article')->getCollection();
     $this->assertEquals($connection->getMongoDB()->selectCollection('articles'), $collection);
     $this->assertSame($collection, $mongator->getRepository('Model\\Article')->getCollection());
 }
コード例 #4
0
ファイル: MongatorTest.php プロジェクト: mongator/mongator
 public function testGetDataCache()
 {
     $mongator = new Mongator($this->metadataFactory);
     $cache = new ArrayCache();
     $mongator->setDataCache($cache);
     $this->assertSame($cache, $mongator->getDataCache());
 }