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; }
/** * 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']); }); }
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(); }
/** * 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()); } }); }
public function setUp() { $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../../../../../Proxies'); $config->setProxyNamespace('Proxies'); $config->setHydratorDir(__DIR__ . '/../../../../../Hydrators'); $config->setHydratorNamespace('Hydrators'); $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); } $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); }
/** * * @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); }
/** * * @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); }
/** * 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')); }); }
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 */ protected function createDocumentManager($server) { AnnotationDriver::registerAnnotationClasses(); $configuration = new Configuration(); $configuration->setProxyDir(sys_get_temp_dir()); $configuration->setProxyNamespace('Proxies'); $configuration->setHydratorDir(sys_get_temp_dir()); $configuration->setHydratorNamespace('Hydrators'); $configuration->setMetadataDriverImpl(AnnotationDriver::create()); return DocumentManager::create(new Connection($server), $configuration); }
/** * * @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; }
/** * Get configuration of database * @param String $dataBaseName * @return array */ private function getConn() { AnnotationDriver::registerAnnotationClasses(); $conn = (require self::$dir); $dataBase = (object) $conn['mongodb']; $config = new Configuration(); $config->setProxyDir($dataBase->proxy['dir']); $config->setProxyNamespace($dataBase->proxy['namespace']); $config->setHydratorDir($dataBase->hydrator['dir']); $config->setHydratorNamespace($dataBase->hydrator['namespace']); $config->setMetadataDriverImpl(AnnotationDriver::create($dataBase->entityDir)); }
/** * @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 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 EntityManager */ public static function createTestDocumentManager($paths = array()) { $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); }
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); }
/** * @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); }
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; }
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); }
public function setUp() { $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../../../../../Proxies'); $config->setProxyNamespace('Proxies'); $config->setHydratorDir(__DIR__ . '/../../../../../Hydrators'); $config->setHydratorNamespace('Hydrators'); $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 Connection(), $config); }
public static function create(Connection $conn = null, Configuration $config = null, EventManager $eventManager = null) { if (is_null($config)) { $config = new \Doctrine\ODM\MongoDB\Configuration(); $config->setProxyDir(__DIR__ . '/../Proxies'); $config->setProxyNamespace('Doctrine\\Tests\\Proxies'); $config->setHydratorDir(__DIR__ . '/../Hydrators'); $config->setHydratorNamespace('Doctrine\\Tests\\Hydrators'); $config->setMetadataDriverImpl(\Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::create()); } if (is_null($eventManager)) { $eventManager = new \Doctrine\Common\EventManager(); } return new DocumentManagerMock($conn, $config, $eventManager); }
/** * @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); }
/** * @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); }
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; }); }
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 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(); }
/** * 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'); }