Creates a new Document that operates on the given Mongo connection
and uses the given Configuration.
public static create ( |
||
$conn | ||
$config | ||
$eventManager | Doctrine\Common\EventManager | |
Результат |
public function setUp() { $config = new Configuration(); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Proxies'); $reader = new AnnotationReader(); $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\'); $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents')); $this->dm = DocumentManager::create(new Mongo(), $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); } $product = new ConfigurableProduct('T-Shirt'); $product->addOption(new Option('small', new Money(12.99, $currencies['USD']), new StockItem('T-shirt Size S', new Money(9.99, $currencies['USD']), 15))); $product->addOption(new Option('medium', new Money(14.99, $currencies['USD']), new StockItem('T-shirt Size M', new Money(11.99, $currencies['USD']), 15))); $product->addOption(new Option('large', new Money(17.99, $currencies['USD']), new StockItem('T-shirt Size L', new Money(13.99, $currencies['USD']), 15))); $this->dm->persist($product); $this->dm->flush(); foreach ($currencies as $currency) { $this->dm->detach($currency); } $this->dm->detach($product); unset($currencies, $product); }
/** * 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()); } }); }
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; }
/** * @param $name * @return $this */ protected function loadDocumentManager($name) { $connectionConfig = $this->getConfig()->get("dm/{$name}/connection"); $configurationConfig = $this->getConfig()->get("dm/{$name}/configuration"); $this->documentManagers[$name] = DocumentManager::create($this->getProducer($connectionConfig['producer'])->produce($connectionConfig['params']), $this->getProducer($configurationConfig['producer'])->produce($configurationConfig['params'])); return $this; }
/** * 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(); }
/** * 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']); }); }
/** * DocumentManager mock object with * annotation mapping driver * * @param EventManager $evm * @return DocumentManager */ protected function getMockMappedDocumentManager(EventManager $evm = null, $config = null) { $conn = $this->getMock('Doctrine\\MongoDB\\Connection'); $config = $config ? $config : $this->getMockAnnotatedConfig(); $this->dm = DocumentManager::create($conn, $config, $evm ?: $this->getEventManager()); return $this->dm; }
/** * * @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); }
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(); }
/** * EntityManager mock object together with * annotation mapping driver and pdo_sqlite * database in memory * * @param EventManager $evm * @return EntityManager */ protected function getDoctrine() { $config = $this->getMockAnnotatedConfig(); $dm = \Doctrine\ODM\MongoDB\DocumentManager::create(null, $config); return $this->doctrine = m::mock(array('getManager' => $dm, 'getManagers' => array($dm), 'getManagerForClass' => $dm)); // $conn = array( // 'driver' => 'pdo_sqlite', // 'memory' => true, // // 'path' => __DIR__.'/../db.sqlite', // ); // $config = $this->getMockAnnotatedConfig(); // $em = EntityManager::create($conn, $config); // $entities = array( // 'Khepin\\Fixture\\Entity\\Car', // 'Khepin\\Fixture\\Entity\\Driver' // ); // $schema = array_map(function($class) use ($em) { // return $em->getClassMetadata($class); // }, $entities); // $schemaTool = new SchemaTool($em); // $schemaTool->dropSchema(array()); // $schemaTool->createSchema($schema); // return $this->doctrine = m::mock(array( // 'getEntityManager' => $em, // 'getManager' => $em, // ) // ); }
/** * 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')); }); }
/** * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator * @return \Doctrine\ODM\MongoDB\DocumentManager */ public function createService(ServiceLocatorInterface $serviceLocator) { $options = $this->getOptions($serviceLocator, 'documentmanager'); $connection = $serviceLocator->get($options->getConnection()); $config = $serviceLocator->get($options->getConfiguration()); $eventManager = $serviceLocator->get($options->getEventManager()); return DocumentManager::create($connection, $config, $eventManager); }
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(); }
/** * Creates the doctrine document mananger for working on the database * * @return DocumentManager */ protected function createDocumentManager() { AnnotationDriver::registerAnnotationClasses(); $configuration = new Configuration(); $configuration->setProxyDir($this->configuration['doctrine']['proxyDir']); $configuration->setProxyNamespace($this->configuration['doctrine']['proxyNamespace']); $configuration->setHydratorDir($this->configuration['doctrine']['hydratorDir']); $configuration->setHydratorNamespace($this->configuration['doctrine']['hydratorNamespace']); $configuration->setMetadataDriverImpl(AnnotationDriver::create()); return DocumentManager::create(new Connection($this->configuration['doctrine']['connection']['server']), $configuration); }
/** * @return DocumentManager */ public static function createTestDocumentManager($paths = array()) { $config = new \Doctrine\ODM\MongoDB\Configuration(); $config->setAutoGenerateProxyClasses(true); $config->setProxyDir(\sys_get_temp_dir()); $config->setHydratorDir(\sys_get_temp_dir()); $config->setProxyNamespace('SymfonyTests\\Doctrine'); $config->setHydratorNamespace('SymfonyTests\\Doctrine'); $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), $paths)); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); return 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); }
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); }
/** * @return ObjectManager */ protected function createObjectManager() { $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../proxies'); $config->setProxyNamespace('Proxy'); $config->setHydratorDir(__DIR__ . '/../hydrators'); $config->setHydratorNamespace('Hydrator'); $fileLocator = new SymfonyFileLocator(array(__DIR__ . '/../../metadata' => 'XApi\\Repository\\Api\\Mapping'), '.mongodb.xml'); $driver = new XmlDriver($fileLocator); $config->setMetadataDriverImpl($driver); return DocumentManager::create(new Connection(), $config); }
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); }
/** * * @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); }
/** * @return EntityManager */ public static function createTestDocumentManager($paths = array()) { if (!class_exists('PDO') || !in_array('pgsql', \PDO::getAvailableDrivers())) { self::markTestSkipped('This test requires PgSQL support in your environment'); } $config = new Configuration(); $config->setAutoGenerateProxyClasses(true); $config->setProxyDir(\sys_get_temp_dir()); $config->setHydratorDir(\sys_get_temp_dir()); $config->setProxyNamespace('GenemuFormBundleTests\\Doctrine'); $config->setHydratorNamespace('GenemuFormBundleTests\\Doctrine'); $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), $paths)); $config->setMetadataCacheImpl(new ArrayCache()); return DocumentManager::create(new Connection(), $config); }
/** * @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); }
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; }); }
/** * Get EntityManage for DataBase * @param String dataBase * @return EntityManager */ public function getDocumentManager() { try { if (isset(self::$documentManager)) { return self::$documentManager; } else { $conf = $this->getConn(); self::$documentManager = DocumentManager::create(new Connection(), $conf); } } catch (\Exception $e) { echo $e->getMessage(); die; } return self::$documentManager; }
public function setUp() { $config = new Configuration(); $config->setHydratorDir(sys_get_temp_dir()); $config->setHydratorNamespace('Hydrators'); $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('Proxies'); $locatorXml = new SymfonyFileLocator(array(__DIR__ . '/../../../../../lib/Vespolina/Sync/Mapping' => 'Vespolina\\Sync\\Entity'), '.mongodb.xml'); $xmlDriver = new XmlDriver($locatorXml); $config->setMetadataDriverImpl($xmlDriver); $config->setMetadataCacheImpl(new ArrayCache()); $config->setAutoGenerateProxyClasses(true); $doctrineODM = DocumentManager::create(null, $config); $this->gateway = new SyncDoctrineMongoDBGateway($doctrineODM, 'Vespolina\\Entity\\Action\\Action'); parent::setUp(); }
public function setUp() { $config = new Configuration(); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Proxies'); /* $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); }
/** * setup mongo-odm and load fixtures * * @return void */ public function setUp() { AnnotationDriver::registerAnnotationClasses(); $config = new Configuration(); $config->setHydratorDir('/tmp/hydrators'); $config->setHydratorNamespace('Hydrators'); $config->setProxyDir('/tmp/proxies'); $config->setProxyNamespace('Proxies'); $config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/Documents/')); $dm = DocumentManager::create(new Connection(), $config); $loader = new Loader(); $loader->addFixture(new MongoOdmFixtures()); $executor = new MongoDBExecutor($dm, new MongoDBPurger()); $executor->execute($loader->getFixtures()); $this->builder = $dm->createQueryBuilder('Graviton\\Rql\\Documents\\Foo'); }
/** * @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']); }
/** * Create a Doctrine document manager. * * @param array $options * * @throws \InvalidArgumentException * * @return \Doctrine\ODM\MongoDB\DocumentManager */ public static function build(array $options) { $options = array_merge(static::$defaultOptions, $options); if ($options['cache_driver'] !== null && !$options['cache_driver'] instanceof Cache) { throw new \InvalidArgumentException('Cache Driver provided is not valid'); } static::setupAnnotationMetadata($options); $config = static::createConfiguration($options); if (!$config instanceof Configuration) { throw new \InvalidArgumentException('No Metadata Driver defined'); } static::setupDefaultDatabase($config, $options); static::setupProxy($config, $options); static::setupHydrator($config, $options); static::setupLogger($config, $options); return DocumentManager::create(self::getConnection($options), $config, $options['event_manager']); }
/** * @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; }