setDefaultDB() public méthode

Sets the default DB to use for all Documents that do not specify a database.
public setDefaultDB ( string $defaultDB )
$defaultDB string
 /**
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return object
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $manifest = $serviceLocator->get('manifest');
     $config = new Configuration();
     $config->setProxyDir(__DIR__ . '/../../../../Proxies');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir(__DIR__ . '/../../../../Hydrators');
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB(self::DEFAULT_DB);
     $config->setMetadataCacheImpl(new ArrayCache());
     //create driver chain
     $chain = new MappingDriverChain();
     foreach ($manifest['documents'] as $namespace => $path) {
         $driver = new AnnotationDriver(new AnnotationReader(), $path);
         $chain->addDriver($driver, $namespace);
     }
     $config->setMetadataDriverImpl($chain);
     //register filters
     foreach ($manifest['filters'] as $name => $class) {
         $config->addFilter($name, $class);
     }
     //create event manager
     $eventManager = new EventManager();
     foreach ($manifest['subscribers'] as $subscriber) {
         $eventManager->addEventSubscriber($serviceLocator->get($subscriber));
     }
     //register annotations
     AnnotationRegistry::registerLoader(function ($className) {
         return class_exists($className);
     });
     $conn = new Connection(null, array(), $config);
     return DocumentManager::create($conn, $config, $eventManager);
 }
 /**
  * Called on framework init.
  */
 public function register()
 {
     // Note:    If you'd like to use annotation, XML or YAML mappings, simply bind another
     //          implementation of this interface in your project and we'll use it! :)
     $this->app->singleton('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver', function (Application $app) {
         return new ConfigMapping(config('mongodb.mappings'));
     });
     $this->app->singleton('Doctrine\\MongoDB\\Configuration', function (Application $app) {
         $config = new Configuration();
         $config->setProxyDir(storage_path('cache/MongoDbProxies'));
         $config->setProxyNamespace('MongoDbProxy');
         $config->setHydratorDir(storage_path('cache/MongoDbHydrators'));
         $config->setHydratorNamespace('MongoDbHydrator');
         $config->setDefaultDB(config('mongodb.default_db', 'laravel'));
         // Request whatever mapping driver is bound to the interface.
         $config->setMetadataDriverImpl($app->make('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver'));
         return $config;
     });
     $this->app->singleton('MongoClient', function (Application $app) {
         return new MongoClient(config('mongodb.host', 'localhost'));
     });
     $this->app->singleton('Doctrine\\MongoDB\\Connection', function (Application $app) {
         return new Connection($app->make('MongoClient'));
     });
     // Because of our bindings above, this one's actually a cinch!
     $this->app->singleton('Doctrine\\ODM\\MongoDB\\DocumentManager', function (Application $app) {
         return DocumentManager::create($app->make('Doctrine\\MongoDB\\Connection'), $app->make('Doctrine\\MongoDB\\Configuration'));
     });
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->bind('odm.documentmanager', function ($app) {
         $conn = Config::get('laravel-odm::connection');
         return DocumentManager::create(new Connection($conn['server'], $conn['options']), App::make('odm.config'));
     });
     $this->app->bind('odm.config', function ($app) {
         $conn = Config::get('laravel-odm::connection');
         $dir = Config::get('laravel-odm::dir');
         $config = new Configuration();
         $config->setProxyDir($dir['proxy']);
         $config->setProxyNamespace('Proxies');
         $config->setHydratorDir($dir['hydrator']);
         $config->setHydratorNamespace('Hydrators');
         $config->setMetadataDriverImpl(App::make('odm.annotation'));
         $config->setDefaultDB($conn['options']['db']);
         return $config;
     });
     $this->app->bind('odm.annotation', function ($app) {
         $dir = Config::get('laravel-odm::dir');
         AnnotationDriver::registerAnnotationClasses();
         $reader = new AnnotationReader();
         return new AnnotationDriver($reader, $dir['document']);
     });
 }
 /**
  *
  * @param  \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return object
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $manifest = $serviceLocator->get('manifest');
     $extension = $serviceLocator->get('extension.odmcore');
     $config = new Configuration();
     $config->setProxyDir($extension->getProxyDir());
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir($extension->getHydratorDir());
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB($extension->getDefaultDb());
     $config->setClassMetadataFactoryName($extension->getClassMetadataFactory());
     $config->setMetadataCacheImpl(new ArrayCache());
     //create driver chain
     $chain = new MappingDriverChain();
     foreach ($manifest->getModels() as $namespace => $path) {
         $driver = new AnnotationDriver(new AnnotationReader(), $path);
         $chain->addDriver($driver, $namespace);
     }
     $config->setMetadataDriverImpl($chain);
     //register filters
     foreach ($extension->getFilters() as $name => $class) {
         $config->addFilter($name, $class);
     }
     //create event manager
     $eventManager = new EventManager();
     foreach ($manifest->getSubscribers() as $subscriber) {
         $eventManager->addEventSubscriber($serviceLocator->get($subscriber));
     }
     //register annotations
     AnnotationRegistry::registerLoader(function ($className) {
         return class_exists($className);
     });
     $conn = new Connection(null, array(), $config);
     return ModelManager::create($conn, $config, $eventManager);
 }
 /**
  * Datasource constructor, creates the Configuration, Connection and DocumentManager objects
  *
  * ### You can pass the following configuration options
  *
  *	- server: name of the server that will be used to connect to Mongo (default: `localhost`)
  *	- database: name of the database to use when connecting to Mongo (default: `cake`)
  *	- documentPaths: array containing a list of full path names where Document classes can be located (default: `App::path('Model')`)
  *	- proxyDir: full path to the directory that will contain the generated proxy classes for each document (default: `TMP . 'cache'`)
  *	- proxyNamespace: string representing the namespace the proxy classes will reside in (default: `Proxies`)
  *	- hydratorDir: directory well the hydrator classes will be generated in (default: `TMP . 'cache'`)
  *	- hydratorNamespace:  string representing the namespace the hydrator classes will reside in (default: `Hydrators`)
  *
  * @param arary $config
  * @param boolean $autoConnect whether this object should attempt connection on creation
  * @throws MissingConnectionException if it was not possible to connect to MongoDB
  */
 public function __construct($config = array(), $autoConnect = true)
 {
     $modelPaths = $this->_cleanupPaths(App::path('Model'));
     $this->_baseConfig = array('proxyDir' => TMP . 'cache', 'proxyNamespace' => 'Proxies', 'hydratorDir' => TMP . 'cache', 'hydratorNamespace' => 'Hydrators', 'server' => 'localhost', 'database' => 'cake', 'documentPaths' => $modelPaths, 'prefix' => null);
     foreach (CakePlugin::loaded() as $plugin) {
         $this->_baseConfig['documentPaths'] = array_merge($this->_baseConfig['documentPaths'], $this->_cleanupPaths(App::path('Model', $plugin)));
     }
     parent::__construct($config);
     extract($this->config, EXTR_OVERWRITE);
     $configuration = new Configuration();
     $configuration->setProxyDir($proxyDir);
     $configuration->setProxyNamespace($proxyNamespace);
     $configuration->setHydratorDir($hydratorDir);
     $configuration->setHydratorNamespace($hydratorNamespace);
     $configuration->setDefaultDB($database);
     $configuration->setMetadataDriverImpl($this->_getMetadataReader($documentPaths));
     if (Configure::read('debug') === 0) {
         $configuration->setAutoGenerateHydratorClasses(false);
         $configuration->setAutoGenerateProxyClasses(false);
         $configuration->setMetadataCacheImpl(new ApcCache());
     }
     $this->configuration = $configuration;
     $this->connection = new Connection($server, array(), $configuration);
     $this->documentManager = DocumentManager::create($this->connection, $configuration);
     $this->documentManager->getEventManager()->addEventListener(array(Events::prePersist, Events::preUpdate, Events::preRemove, Events::postPersist, Events::postUpdate, Events::postRemove), $this);
     try {
         if ($autoConnect) {
             $this->connect();
         }
     } catch (Exception $e) {
         throw new MissingConnectionException(array('class' => get_class($this)));
     }
     $this->setupLogger();
 }
Exemple #6
0
    public function setUp()
    {
        $config = new Configuration();

        $config->setProxyDir(__DIR__ . '/../../../../Proxies');
        $config->setProxyNamespace('Proxies');

        $config->setHydratorDir(__DIR__ . '/../../../../Hydrators');
        $config->setHydratorNamespace('Hydrators');

        $config->setDefaultDB('doctrine_odm_tests');

        /*
        $config->setLoggerCallable(function(array $log) {
            print_r($log);
        });
        $config->setMetadataCacheImpl(new ApcCache());
        */

        $reader = new AnnotationReader();
        $reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\');
        $this->annotationDriver = new AnnotationDriver($reader, __DIR__ . '/../../../../Documents');
        $config->setMetadataDriverImpl($this->annotationDriver);

        $conn = new Connection(null, array(), $config);
        $this->dm = DocumentManager::create($conn, $config);
        $this->uow = $this->dm->getUnitOfWork();
    }
Exemple #7
0
 /**
  * Connect to MongoDb
  * @return DocumentManager
  */
 public function _initDb()
 {
     $container = $this;
     $this['documentManager'] = $this->share(function () use($container) {
         $dbConfigs = $container['configs']['database'];
         try {
             if (empty($dbConfigs['user'])) {
                 $connection_url = "mongodb://{$dbConfigs['host']}:{$dbConfigs['port']}/{$dbConfigs['name']}";
             } else {
                 $connection_url = "mongodb://{$dbConfigs['user']}:{$dbConfigs['passwd']}@{$dbConfigs['host']}:{$dbConfigs['port']}/{$dbConfigs['name']}";
             }
             AnnotationDriver::registerAnnotationClasses();
             $config = new Configuration();
             $config->setProxyDir(BIN_PATH . '/src/Blueridge/Documents/Proxies');
             $config->setProxyNamespace('Proxies');
             $config->setHydratorDir(BIN_PATH . '/src/Blueridge/Documents/Hydrators');
             $config->setHydratorNamespace('Hydrators');
             $config->setMetadataDriverImpl(AnnotationDriver::create(BIN_PATH . '/src/Blueridge/Documents'));
             $config->setDefaultDB($dbConfigs['name']);
             return DocumentManager::create(new Connection($connection_url), $config);
         } catch (Exception $e) {
             error_log($e->getMessage());
         }
     });
 }
Exemple #8
0
 protected function getDocumentManager()
 {
     if (is_null($this->_documentManager)) {
         $options = $this->getOptions();
         // ODM Class
         $classLoader = new ClassLoader('Doctrine\\ODM\\MongoDB', APPLICATION_PATH . '/../library');
         $classLoader->register();
         // Common Class
         $classLoader = new ClassLoader('Doctrine\\Common', APPLICATION_PATH . '/../library');
         $classLoader->register();
         // MongoDB Class
         $classLoader = new ClassLoader('Doctrine\\MongoDB', APPLICATION_PATH . '/../library');
         $classLoader->register();
         $classLoader = new ClassLoader('Documents', $options['documentPath']);
         $classLoader->register();
         $config = new Configuration();
         $config->setProxyDir($options['proxyDir']);
         $config->setProxyNamespace($options['proxyNamespace']);
         $config->setHydratorDir($options['hydratorDir']);
         $config->setHydratorNamespace($options['hydratorNamespace']);
         $reader = new AnnotationReader();
         AnnotationDriver::registerAnnotationClasses();
         $config->setMetadataDriverImpl(new AnnotationDriver($reader, $options['documentPath']));
         $config->setDefaultDB($options['dbname']);
         $this->_documentManager = DocumentManager::create(new Connection($options['server']), $config);
     }
     return $this->_documentManager;
 }
 public function setUp()
 {
     $config = new Configuration();
     $config->setProxyDir(__DIR__ . '/../../../../../Proxies');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir(__DIR__ . '/../../../../../Hydrators');
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB('doctrine_odm_tests');
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
     $this->dm = DocumentManager::create(new Connection(), $config);
     $currencies = array('USD' => 1, 'EURO' => 1.7, 'JPN' => 0.0125);
     foreach ($currencies as $name => &$multiplier) {
         $multiplier = new Currency($name, $multiplier);
         $this->dm->persist($multiplier);
     }
     $stockItems = array(new StockItem('stock_item_0', new Money(9.99 * 0 + 5, $currencies['USD']), 5), new StockItem('stock_item_1', new Money(9.99 * 1 + 5, $currencies['USD']), 15 * 1 - 4), new StockItem('stock_item_2', new Money(9.99 * 2 + 5, $currencies['USD']), 15 * 2 - 4), new StockItem('stock_item_3', new Money(9.99 * 3 + 5, $currencies['USD']), 15 * 3 - 4), new StockItem('stock_item_4', new Money(9.99 * 4 + 5, $currencies['USD']), 15 * 4 - 4), new StockItem('stock_item_5', new Money(9.99 * 5 + 5, $currencies['USD']), 15 * 5 - 4), new StockItem('stock_item_6', new Money(9.99 * 6 + 5, $currencies['USD']), 15 * 6 - 4), new StockItem('stock_item_7', new Money(9.99 * 7 + 5, $currencies['USD']), 15 * 7 - 4), new StockItem('stock_item_8', new Money(9.99 * 8 + 5, $currencies['USD']), 15 * 8 - 4), new StockItem('stock_item_9', new Money(9.99 * 9 + 5, $currencies['USD']), 15 * 9 - 4));
     $options = array(new Option('option_0', new Money(13.99, $currencies['USD']), $stockItems[0]), new Option('option_1', new Money(14.99, $currencies['USD']), $stockItems[1]), new Option('option_2', new Money(15.99, $currencies['USD']), $stockItems[2]), new Option('option_3', new Money(16.99, $currencies['USD']), $stockItems[3]), new Option('option_4', new Money(17.99, $currencies['USD']), $stockItems[4]), new Option('option_5', new Money(18.99, $currencies['USD']), $stockItems[5]), new Option('option_6', new Money(19.99, $currencies['USD']), $stockItems[6]), new Option('option_7', new Money(20.99, $currencies['USD']), $stockItems[7]), new Option('option_8', new Money(21.99, $currencies['USD']), $stockItems[8]), new Option('option_9', new Money(22.99, $currencies['USD']), $stockItems[9]));
     $products = array(new ConfigurableProduct('product_0'), new ConfigurableProduct('product_1'), new ConfigurableProduct('product_2'), new ConfigurableProduct('product_3'), new ConfigurableProduct('product_4'), new ConfigurableProduct('product_5'), new ConfigurableProduct('product_6'), new ConfigurableProduct('product_7'), new ConfigurableProduct('product_8'), new ConfigurableProduct('product_9'));
     $products[0]->addOption($options[0]);
     $products[0]->addOption($options[4]);
     $products[0]->addOption($options[6]);
     $products[1]->addOption($options[1]);
     $products[1]->addOption($options[2]);
     $products[1]->addOption($options[5]);
     $products[1]->addOption($options[7]);
     $products[1]->addOption($options[8]);
     $products[2]->addOption($options[3]);
     $products[2]->addOption($options[5]);
     $products[2]->addOption($options[7]);
     $products[2]->addOption($options[9]);
     $products[3]->addOption($options[0]);
     $products[3]->addOption($options[1]);
     $products[3]->addOption($options[2]);
     $products[3]->addOption($options[3]);
     $products[3]->addOption($options[4]);
     $products[3]->addOption($options[5]);
     $products[4]->addOption($options[4]);
     $products[4]->addOption($options[7]);
     $products[4]->addOption($options[2]);
     $products[4]->addOption($options[8]);
     $products[5]->addOption($options[9]);
     $products[6]->addOption($options[7]);
     $products[6]->addOption($options[8]);
     $products[6]->addOption($options[9]);
     $products[7]->addOption($options[4]);
     $products[7]->addOption($options[5]);
     $products[8]->addOption($options[2]);
     $products[9]->addOption($options[4]);
     $products[9]->addOption($options[3]);
     $products[9]->addOption($options[7]);
     foreach ($products as $product) {
         $this->dm->persist($product);
     }
     $this->dm->flush();
     $this->dm->clear();
 }
 /**
  *
  * @param array $config
  * @return DocumentManager
  */
 public static function createDocumentManager($config, Container $container)
 {
     $configuration = new Configuration();
     if (is_null($config['eventManager'])) {
         $evm = new EventManager();
     } else {
         $evm = $config['eventManager'];
     }
     $configuration->setProxyDir($config['proxyDir']);
     $configuration->setProxyNamespace($config['proxyNamespace']);
     $configuration->setHydratorDir($config['hydratorDir']);
     $configuration->setHydratorNamespace($config['hydratorNamespace']);
     $configuration->setAutoGenerateHydratorClasses($config['autoGenerateHydratorClasses']);
     $configuration->setAutoGenerateProxyClasses($config['autoGenerateProxyClasses']);
     if (isset($config['metaDataCache'])) {
         $metadataCache = $config['metaDataCache'];
     } else {
         $metadataCache = new $config['metaDataCacheClass']();
         $metadataCache->setNamespace($config['cachePrefix']);
     }
     $configuration->setMetadataCacheImpl($metadataCache);
     AnnotationDriver::registerAnnotationClasses();
     $reader = new AnnotationReader();
     if ($config['cacheAnnotations'] == TRUE) {
         $reader = new CachedReader($reader, $metadataCache, $config['debug']);
     }
     if ($config['indexAnnotations'] == TRUE) {
         $reader = new IndexedReader($reader);
     }
     if (class_exists(\Gedmo\DoctrineExtensions::class)) {
         \Gedmo\DoctrineExtensions::registerAnnotations();
         $configuration->addFilter('soft-deleteable', \Gedmo\SoftDeleteable\Filter\ODM\SoftDeleteableFilter::class);
         foreach ($config['listeners'] as $listenerName => $enabled) {
             if ($enabled) {
                 $listener = self::configureListener($listenerName, $reader);
                 $evm->addEventSubscriber($listener);
             }
         }
     }
     $driverImpl = new AnnotationDriver($reader, $config['documentsDir']);
     $configuration->setMetadataDriverImpl($driverImpl);
     $configuration->setDefaultDB($config['dbname']);
     $logger = new Logger($config['logger'], $config['loggerPrefix']);
     $configuration->setLoggerCallable([$logger, 'logQuery']);
     $mongo = new MongoClient($config['uri'], $config['mongoOptions']);
     $connection = new Connection($mongo);
     $dm = DocumentManager::create($connection, $configuration, $evm);
     foreach ($config['filters'] as $filter => $enabled) {
         if ($enabled) {
             $dm->getFilterCollection()->enable($filter);
         }
     }
     return $dm;
 }
 public function __construct()
 {
     AnnotationDriver::registerAnnotationClasses();
     $config = new Configuration();
     $config->setProxyDir(app_path() . '/storage/cache/Doctrine/Proxies');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir(app_path() . '/storage/cache/Doctrine/Hydrators');
     $config->setHydratorNamespace('Hydrators');
     $config->setMetadataDriverImpl(AnnotationDriver::create(app_path() . '/app/Model/Entity'));
     $config->setDefaultDB(config('database.db_name'));
     parent::__construct(new Connection(\Config::get('database.host')), $config);
 }
Exemple #12
0
 public function setUp()
 {
     $config = new Configuration();
     $config->setProxyDir(__DIR__ . '/../../../../../Proxies');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir(__DIR__ . '/../../../../../Hydrators');
     $config->setHydratorNamespace('Hydrators');
     $reader = new AnnotationReader();
     $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
     $config->setDefaultDB('testing');
     $this->dm = DocumentManager::create(new Connection(), $config);
 }
 public function setUp()
 {
     $config = new Configuration();
     $config->setProxyDir(__DIR__ . '/../../../../../Proxies');
     $config->setProxyNamespace('Proxies');
     $config->setEnvironment('test');
     $config->setDefaultDB($this->defaultDB);
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
     $this->dm = DocumentManager::create(new Mongo(), $config);
 }
 /**
  * @param array $params
  * @return mixed
  */
 public function produce(array $params = array())
 {
     $configuration = new Configuration();
     $configuration->setProxyDir($params['proxy_dir']);
     $configuration->setProxyNamespace($params['proxy_namespace']);
     $configuration->setHydratorDir($params['hydrator_dir']);
     $configuration->setHydratorNamespace($params['hydrator_namespace']);
     $configuration->setDefaultDB($params['default_db']);
     $configuration->setMetadataDriverImpl(AnnotationDriver::create($params['document_dir']));
     AnnotationDriver::registerAnnotationClasses();
     return $configuration;
 }
 public function __construct($cacheDir)
 {
     $config = new Configuration();
     $config->setProxyDir($cacheDir);
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir($cacheDir);
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB(DB_NAME);
     $reader = new IndexedReader(new AnnotationReader());
     $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/../../Models'));
     $connection = new \Doctrine\MongoDB\Connection(DoctrineNativeConnect::GetInstance()->mongo, array(), $config);
     $this->Doctrinemodel = DocumentManager::create($connection, $config);
 }
Exemple #16
0
 protected function getConfiguration()
 {
     $config = new Configuration();
     $config->setProxyDir(__DIR__ . '/../../../../Proxies');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir(__DIR__ . '/../../../../Hydrators');
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB(DOCTRINE_MONGODB_DATABASE);
     $config->setMetadataDriverImpl($this->createMetadataDriverImpl());
     $config->addFilter('testFilter', 'Doctrine\\ODM\\MongoDB\\Tests\\Query\\Filter\\Filter');
     $config->addFilter('testFilter2', 'Doctrine\\ODM\\MongoDB\\Tests\\Query\\Filter\\Filter');
     return $config;
 }
Exemple #17
0
 public function setUp()
 {
     $this->app()->bind(EntityManagerInterface::class, function () {
         $config = new Configuration();
         $config->setProxyDir(__DIR__ . '/Entities/Proxies');
         $config->setProxyNamespace('Tests\\Proxy');
         $config->setHydratorDir(__DIR__ . '/Entities/Hydrators');
         $config->setHydratorNamespace('Tests\\Hydrators');
         $config->setDefaultDB('test-base-api-php');
         $config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/Entities/Stubs'));
         $connection = new Connection();
         AnnotationDriver::registerAnnotationClasses();
         return EntityManager::create($connection, $config);
     });
 }
 public function register(Application $app)
 {
     $app['mongo.dm'] = $app->share(function () {
         AnnotationDriver::registerAnnotationClasses();
         $config = new Configuration();
         $config->setDefaultDB('descartemap');
         $config->setProxyDir(ROOT . '/var/proxies');
         $config->setProxyNamespace('Proxies');
         $config->setHydratorDir(ROOT . '/var/hydrators');
         $config->setHydratorNamespace('Hydrators');
         $config->setMetadataDriverImpl(AnnotationDriver::create(ROOT . '/var/cache/'));
         $dm = DocumentManager::create(new Connection(), $config);
         return $dm;
     });
 }
 /**
  * @return DocumentManager
  */
 public function getDm()
 {
     $params = ['server' => 'localhost', 'database' => 'doctrine_tutorial', 'metadata_paths' => [__DIR__ . '/../src/Menu/mapping']];
     $cacheDir = __DIR__ . '/../cache';
     $config = new Configuration();
     $config->setProxyDir($cacheDir . '/Proxies');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir($cacheDir . '/Hydrators');
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB($params['database']);
     $config->setMetadataDriverImpl(new YamlDriver($params['metadata_paths']));
     $connection = new Connection($params['server'], array(), $config);
     // Create instance
     return DocumentManager::create($connection, $config);
 }
 /**
  *
  * @param $config
  */
 public function __construct($config)
 {
     $server = $config['connection'][$config['default_connection']];
     $config = $config['configuration'][$config['default_connection']];
     $configuration = new Configuration();
     AnnotationDriver::registerAnnotationClasses();
     $anotationReader = new AnnotationDriver(new AnnotationReader(), app_path('Documents'));
     $configuration->setProxyDir($config['proxy_dir']);
     $configuration->setProxyNamespace('Proxies');
     $configuration->setHydratorDir($config['hydrator_dir']);
     $configuration->setHydratorNamespace('Hydrators');
     $configuration->setMetadataDriverImpl($anotationReader);
     $configuration->setDefaultDB($server['dbname']);
     $this->dm = DocumentManager::create(new Connection(), $configuration);
 }
 private function loadDoctrineMongoDBConfiguration(Application $app)
 {
     $app['doctrine.odm.mongodb.configuration'] = $app->share(function () use($app) {
         $config = new Configuration();
         $config->setMetadataCacheImpl($app['doctrine.odm.mongodb.metadata_cache']);
         if (isset($app['doctrine.odm.mongodb.connection_options']['database'])) {
             $config->setDefaultDB($app['doctrine.odm.mongodb.connection_options']['database']);
         }
         $chain = new MappingDriverChain();
         $usingAnnotations = false;
         foreach ((array) $app['doctrine.odm.mongodb.documents'] as $document) {
             switch ($document['type']) {
                 case 'annotation':
                     $driver = AnnotationDriver::create((array) $document['path']);
                     $chain->addDriver($driver, $document['namespace']);
                     $usingAnnotations = true;
                     break;
                 case 'yml':
                     $driver = new YamlDriver((array) $document['path'], '.yml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 case 'xml':
                     $driver = new XmlDriver((array) $document['path'], '.xml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $document['type']));
                     break;
             }
             // add namespace alias
             if (isset($document['alias'])) {
                 $config->addDocumentNamespace($document['alias'], $document['namespace']);
             }
         }
         if ($usingAnnotations) {
             AnnotationDriver::registerAnnotationClasses();
         }
         $config->setMetadataDriverImpl($chain);
         $config->setProxyDir($app['doctrine.odm.mongodb.proxies_dir']);
         $config->setProxyNamespace($app['doctrine.odm.mongodb.proxies_namespace']);
         $config->setAutoGenerateProxyClasses($app['doctrine.odm.mongodb.auto_generate_proxies']);
         $config->setHydratorDir($app['doctrine.odm.mongodb.hydrators_dir']);
         $config->setHydratorNamespace($app['doctrine.odm.mongodb.hydrators_namespace']);
         $config->setAutoGenerateHydratorClasses($app['doctrine.odm.mongodb.auto_generate_hydrators']);
         $config->setLoggerCallable($app['doctrine.odm.mongodb.logger_callable']);
         return $config;
     });
 }
Exemple #22
0
 /**
  * @param array $options
  */
 public function __construct(array $options = [])
 {
     AnnotationDriver::registerAnnotationClasses();
     $options = array_merge(['mongodb_url' => 'mongodb://localhost/crowi', 'password_seed' => 'this is default session secret', 'temporary_dir' => sys_get_temp_dir() . '/crowi', 'doctrine_configration' => null], $options);
     if (!$options['doctrine_configration'] instanceof Configuration) {
         $config = new Configuration();
         $config->setDefaultDB(trim(parse_url($options['mongodb_url'], PHP_URL_PATH), '/'));
         $config->setProxyDir($options['temporary_dir'] . '/Proxies');
         $config->setProxyNamespace('Proxies');
         $config->setHydratorDir($options['temporary_dir'] . '/Hydrators');
         $config->setHydratorNamespace('Hydrators');
         $config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/Document'));
         $options['doctrine_configration'] = $config;
     }
     $this->dm = DocumentManager::create(new Connection($options['mongodb_url']), $options['doctrine_configration']);
 }
Exemple #23
0
 public function setUp()
 {
     $config = new Configuration();
     $config->setProxyDir(__DIR__ . '/../../../../Proxies');
     $config->setProxyNamespace('Proxies');
     $config->setDefaultDB('doctrine_odm_tests');
     /*
     $config->setLoggerCallable(function(array $log) {
         print_r($log);
     });
     $config->setMetadataCacheImpl(new ApcCache());
     */
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
     $this->dm = DocumentManager::create(new Mongo(), $config);
 }
Exemple #24
0
 public function setUp()
 {
     Type::hasType('object') ? Type::overrideType('object', 'Payum\\Bridge\\Doctrine\\Types\\ObjectType') : Type::addType('object', 'Payum\\Bridge\\Doctrine\\Types\\ObjectType');
     $conf = new Configuration();
     $conf->setProxyDir(\sys_get_temp_dir());
     $conf->setProxyNamespace('PayumTestsProxies');
     $conf->setHydratorDir(\sys_get_temp_dir());
     $conf->setHydratorNamespace('PayumTestsHydrators');
     $conf->setMetadataDriverImpl($this->getMetadataDriverImpl());
     $conf->setMetadataCacheImpl(new ArrayCache());
     $conf->setDefaultDB('payum_tests');
     $conn = new Connection(null, array(), $conf);
     $this->dm = DocumentManager::create($conn, $conf);
     foreach ($this->dm->getConnection()->selectDatabase('payum_tests')->listCollections() as $collection) {
         $collection->drop();
     }
 }
Exemple #25
0
/**
 * @return DocumentManager
 */
function getDM()
{
    static $dm;
    if (!isset($dm)) {
        $connection = new Connection();
        $config = new Configuration();
        $config->setProxyDir(__DIR__ . '/Proxies');
        $config->setProxyNamespace('Proxies');
        $config->setHydratorDir(__DIR__ . '/Hydrators');
        $config->setHydratorNamespace('Hydrators');
        $config->setDefaultDB('tw-react');
        $config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/Documents'));
        AnnotationDriver::registerAnnotationClasses();
        $dm = DocumentManager::create($connection, $config);
    }
    return $dm;
}
 public function loadDoctrineMongoDBConfiguration(Application $app)
 {
     $app['doctrine.odm.mongodb.configuration'] = $app->share(function () use($app) {
         $config = new Configuration();
         if ($app['doctrine.odm.mongodb.metadata_cache'] == 'apc') {
             $cache = new ApcCache();
         } else {
             $cache = new ArrayCache();
         }
         $config->setMetadataCacheImpl($cache);
         if (isset($app['doctrine.odm.mongodb.connection_options']['database'])) {
             $config->setDefaultDB($app['doctrine.odm.mongodb.connection_options']['database']);
         }
         $chain = new DriverChain();
         foreach ((array) $app['doctrine.odm.mongodb.documents'] as $document) {
             switch ($document['type']) {
                 case 'annotation':
                     $reader = new AnnotationReader();
                     $driver = new AnnotationDriver($reader, (array) $document['path']);
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 case 'yml':
                     $driver = new YamlDriver((array) $document['path']);
                     $driver->setFileExtension('.yml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 case 'xml':
                     $driver = new XmlDriver((array) $document['path'], $document['namespace']);
                     $driver->setFileExtension('.xml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $document['type']));
                     break;
             }
         }
         $config->setMetadataDriverImpl($chain);
         $config->setProxyDir($app['doctrine.odm.mongodb.proxies_dir']);
         $config->setProxyNamespace($app['doctrine.odm.mongodb.proxies_namespace']);
         $config->setAutoGenerateProxyClasses($app['doctrine.odm.mongodb.auto_generate_proxies']);
         $config->setHydratorDir($app['doctrine.odm.mongodb.hydrators_dir']);
         $config->setHydratorNamespace($app['doctrine.odm.mongodb.hydrators_namespace']);
         return $config;
     });
 }
 /**
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Doctrine\ODM\MongoDB\Configuration
  * @throws \Exception
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var $options \DoctrineMongoODMModule\Options\Configuration */
     $options = $this->getOptions($serviceLocator, 'configuration');
     $config = new Configuration();
     // logger
     if ($options->getLogger()) {
         $logger = $serviceLocator->get($options->getLogger());
         $config->setLoggerCallable(array($logger, 'log'));
     }
     // proxies
     $config->setAutoGenerateProxyClasses($options->getGenerateProxies());
     $config->setProxyDir($options->getProxyDir());
     $config->setProxyNamespace($options->getProxyNamespace());
     // hydrators
     $config->setAutoGenerateHydratorClasses($options->getGenerateHydrators());
     $config->setHydratorDir($options->getHydratorDir());
     $config->setHydratorNamespace($options->getHydratorNamespace());
     // default db
     $config->setDefaultDB($options->getDefaultDb());
     // caching
     $config->setMetadataCacheImpl($serviceLocator->get($options->getMetadataCache()));
     // retries
     $config->setRetryConnect($options->getRetryConnect());
     $config->setRetryQuery($options->getRetryQuery());
     // Register filters
     foreach ($options->getFilters() as $alias => $class) {
         $config->addFilter($alias, $class);
     }
     // the driver
     $config->setMetadataDriverImpl($serviceLocator->get($options->getDriver()));
     // metadataFactory, if set
     if ($factoryName = $options->getClassMetadataFactoryName()) {
         $config->setClassMetadataFactoryName($factoryName);
     }
     // custom types
     foreach ($options->getTypes() as $name => $class) {
         if (Type::hasType($name)) {
             Type::overrideType($name, $class);
         } else {
             Type::addType($name, $class);
         }
     }
     return $config;
 }
Exemple #28
0
 /**
  * generates the needed document manager
  *
  * @param string $db
  * @return Doctrine\ODM\MongoDB\DocumentManager
  */
 private static function instantiateDocumentManager($db = null)
 {
     if ($db == "stats") {
         $db = sfConfig::get("app_mongodb_database_name_stats");
     } else {
         $db = sfConfig::get("app_mongodb_database_name");
     }
     $config = new Configuration();
     $config->setProxyDir(sfConfig::get('sf_lib_dir') . '/mongo/Proxies');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir(sfConfig::get('sf_lib_dir') . '/mongo/Hydrators');
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB($db);
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
     return DocumentManager::create(new Connection(sfConfig::get("app_mongodb_host")), $config);
 }
Exemple #29
0
function DocumentManager()
{
    if (!file_exists($file = __DIR__ . '/vendor/autoload.php')) {
        throw new RuntimeException('Install dependencies to run this script.');
    }
    $loader = (require_once $file);
    $loader->add('Documents', __DIR__);
    $connection = new Connection();
    $config = new Configuration();
    $config->setProxyDir(__DIR__ . '/Proxies');
    $config->setProxyNamespace('Proxies');
    $config->setHydratorDir(__DIR__ . '/Hydrators');
    $config->setHydratorNamespace('Hydrators');
    $config->setDefaultDB('todos');
    $config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/Documents'));
    AnnotationDriver::registerAnnotationClasses();
    $dm = DocumentManager::create($connection, $config);
    return $dm;
}
Exemple #30
0
 /**
  * @return DocumentManager
  */
 private function connect()
 {
     $config = new Configuration();
     $config->setProxyDir($this->app['cache']['doctrine'] . '/mongodb/proxy');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir($this->app['cache']['doctrine'] . '/mongodb/hydrators');
     $config->setHydratorNamespace('Hydrators');
     $anno = [];
     foreach ($this->config['modules'] as $app) {
         $dir = $this->app['BASE_DIR'] . $this->app['Modules'] . $app . '/Document';
         if (file_exists($dir)) {
             $anno[] = $dir;
         }
     }
     $driverImpl = $config->newDefaultAnnotationDriver($anno);
     $config->setMetadataDriverImpl($driverImpl);
     $config->setDefaultDB($this->config['database']['name']);
     $config->setDefaultCommitOptions(array('safe' => true, 'fsync' => true));
     return DocumentManager::create(new Connection($this->config['database']['host']), $config);
 }