コード例 #1
0
 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);
 }
コード例 #2
0
ファイル: BaseTest.php プロジェクト: JanJakes/mongodb-odm
    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();
    }
コード例 #3
0
 public function setUp()
 {
     if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0RC4-DEV', '>=')) {
         $this->markTestSkipped('Doctrine common is 2.1.0RC4-DEV version, skipping.');
     } else {
         if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
             $reader = new AnnotationReader();
             $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
             $reader->setIgnoreNotImportedAnnotations(true);
             $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
             $reader->setEnableParsePhpImports(false);
             $reader->setAutoloadAnnotations(true);
             $reader = new CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache());
         } else {
             $reader = new AnnotationReader();
             $reader->setAutoloadAnnotations(true);
             $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
             $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
         }
     }
     $config = new \Doctrine\ORM\Configuration();
     $config->setProxyDir(TESTS_TEMP_DIR);
     $config->setProxyNamespace('Gedmo\\Mapping\\Proxy');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader));
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     $evm = new \Doctrine\Common\EventManager();
     $this->timestampable = new \Gedmo\Timestampable\TimestampableListener();
     $evm->addEventSubscriber($this->timestampable);
     $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema(array($this->em->getClassMetadata(self::ARTICLE)));
 }
コード例 #4
0
	static private function loadDriver($namespace)
	{
		$cache  = new ArrayCache();
        $reader = new AnnotationReader($cache);
        $reader->setDefaultAnnotationNamespace($namespace);

        return new AnnotationDriver($reader);
	}
コード例 #5
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');
     $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();
 }
コード例 #6
0
ファイル: Doctrine.php プロジェクト: jgat2012/hp_oms
 public function __construct()
 {
     // Is the config file in the environment folder?
     if (!defined('ENVIRONMENT') or !file_exists($file_path = APPPATH . 'config/' . ENVIRONMENT . '/database.php')) {
         $file_path = APPPATH . 'config/database.php';
     }
     // load database configuration from CodeIgniter
     require $file_path;
     // Set up class loading
     require_once APPPATH . 'third_party/doctrine-orm/Doctrine/Common/ClassLoader.php';
     $loader = new ClassLoader('Doctrine', APPPATH . 'third_party/doctrine-orm');
     $loader->register();
     // Set up models loading
     $loader = new ClassLoader('models', APPPATH);
     $loader->register();
     foreach (glob(APPPATH . 'modules/*', GLOB_ONLYDIR) as $m) {
         $module = str_replace(APPPATH . 'modules/', '', $m);
         $loader = new ClassLoader($module, APPPATH . 'modules');
         $loader->register();
     }
     // Set up proxies loading
     $loader = new ClassLoader('Proxies', APPPATH . 'Proxies');
     $loader->register();
     // Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // Set up driver
     $reader = new AnnotationReader($cache);
     $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
     // Set up models
     $models = array(APPPATH . 'models');
     foreach (glob(APPPATH . 'modules/*/models', GLOB_ONLYDIR) as $m) {
         array_push($models, $m);
     }
     $driver = new AnnotationDriver($reader, $models);
     $config->setMetadataDriverImpl($driver);
     // Proxy configuration
     $config->setProxyDir(APPPATH . '/Proxies');
     $config->setProxyNamespace('Proxies');
     // Set up logger
     //$logger = new EchoSqlLogger;
     //$config->setSqlLogger($logger);
     $config->setAutoGenerateProxyClasses(TRUE);
     // Database connection information
     $connection = array('driver' => 'pdo_mysql', 'user' => $db[$active_group]['username'], 'password' => $db[$active_group]['password'], 'host' => $db[$active_group]['hostname'], 'dbname' => $db[$active_group]['database']);
     // Create EntityManager
     $this->em = EntityManager::create($connection, $config);
     // Force UTF-8
     $this->em->getEventManager()->addEventSubscriber(new MysqlSessionInit('utf8', 'utf8_unicode_ci'));
     // Schema Tool
     $this->tool = new SchemaTool($this->em);
     //auto generate entities from database
     //$this->generate_entities();
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 public function create()
 {
     if (!isset($this->options['connection_options'])) {
         throw new \Exception("The connection_options configuration setting is not defined.");
     }
     if (!isset($this->options['metadata']['driver'])) {
         throw new \Exception("The metadata.driver configuration setting is not defined.");
     }
     if (!isset($this->options['metadata']['paths'])) {
         throw new \Exception("The metadata.paths configuration setting is not defined.");
     }
     if (!isset($this->options['directories']['proxies'])) {
         throw new \Exception("The directories.proxies configuration setting is not defined.");
     }
     $config = new Configuration();
     // Setup the caches
     if (extension_loaded("apc")) {
         $cache = new ApcCache();
     } else {
         $cache = new ArrayCache();
     }
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // Setup the proxies
     $config->setProxyDir(APP_PATH . "/" . $this->options['directories']['proxies']);
     $config->setProxyNamespace("Proxies");
     $config->setAutoGenerateProxyClasses(isset($this->options['autoGenerateProxies']) && $this->options['autoGenerateProxies']);
     // Get the paths from the metadata.paths configuration entry.  This can either be a single item (paths: entities), or a
     // list of paths (paths: [path1, path2]).  The code below deals with both cases, and prepends the APP_PATH to them.
     $paths = is_array($this->options['metadata']['paths']) ? $this->options['metadata']['paths'] : array($this->options['metadata']['paths']);
     array_walk($paths, function (&$item, $key) {
         $item = APP_PATH . DIRECTORY_SEPARATOR . $item;
     });
     // Set the metadata driver implementation based on the metadata.driver configuration entry.  Note that Annotations are
     // slightly different to the others implementations so are dealt with seperately.
     switch ($this->options['metadata']['driver']) {
         case 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver':
             $reader = new AnnotationReader();
             $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
             //$driverImpl = new $this->options['metadata']['driver']($reader, $paths);
             $driverImpl = $config->newDefaultAnnotationDriver($paths);
             break;
         default:
             $driverImpl = new $this->options['metadata']['driver']($paths);
             break;
     }
     // Set the metadata driver implementation
     $config->setMetadataDriverImpl($driverImpl);
     // Finally create and return the EntityManager.  If a $connectionOptions variable is set in the registry this takes precedence over
     // config.yml, which allows us to override database setting for test suites
     return EntityManager::create(Zend_Registry::isRegistered("connectionOptions") ? Zend_Registry::get("connectionOptions") : $this->options['connection_options'], $config);
 }
コード例 #9
0
 public function setUp()
 {
     parent::setUp();
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
     $annotationDriver = new AnnotationDriver($reader);
     $xmlDriver = new XmlDriver(__DIR__ . '/../Driver/Xml');
     $chain = new DriverChain();
     $chain->addDriver($annotationDriver, 'Gedmo\\Loggable');
     $chain->addDriver($xmlDriver, 'Mapping\\Fixture\\Xml');
     $this->loggable = new LoggableListener();
     $this->evm = new EventManager();
     $this->evm->addEventSubscriber($this->loggable);
     $this->em = $this->getMockSqliteEntityManager(array('Gedmo\\Loggable\\Entity\\LogEntry', 'Mapping\\Fixture\\Xml\\Loggable', 'Mapping\\Fixture\\Xml\\Status'), $chain);
 }
コード例 #10
0
 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);
 }
コード例 #11
0
 public function createDocumentManager()
 {
     $couchDBClient = $this->createCouchDBClient();
     $httpClient = $couchDBClient->getHttpClient();
     $database = $couchDBClient->getDatabase();
     $httpClient->request('DELETE', '/' . $database);
     $resp = $httpClient->request('PUT', '/' . $database);
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\CouchDB\\Mapping\\');
     $paths = __DIR__ . "/../../Models";
     $metaDriver = new AnnotationDriver($reader, $paths);
     $config = new Configuration();
     $config->setProxyDir(\sys_get_temp_dir());
     $config->setMetadataDriverImpl($metaDriver);
     $setMetadataCacheImpl = $config->setMetadataCacheImpl(new ArrayCache());
     $config->setLuceneHandlerName('_fti');
     return DocumentManager::create($couchDBClient, $config);
 }
コード例 #12
0
ファイル: MongoManager.php プロジェクト: 42medien/spreadly
 /**
  * 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);
 }
コード例 #13
0
 public function setUp()
 {
     parent::setUp();
     // EM with standard annotation mapping
     $this->em1 = $this->getMockSqliteEntityManager(array('Sluggable\\Fixture\\Article'));
     // EM with yaml and annotation mapping
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
     $annotationDriver = new AnnotationDriver($reader);
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
     $annotationDriver2 = new AnnotationDriver($reader);
     $yamlDriver = new YamlDriver(__DIR__ . '/Driver/Yaml');
     $chain = new DriverChain();
     $chain->addDriver($annotationDriver, 'Translatable\\Fixture');
     $chain->addDriver($yamlDriver, 'Mapping\\Fixture\\Yaml');
     $chain->addDriver($annotationDriver2, 'Gedmo\\Translatable');
     $this->em2 = $this->getMockSqliteEntityManager(array('Translatable\\Fixture\\PersonTranslation', 'Mapping\\Fixture\\Yaml\\User'), $chain);
     // DM with standard annotation mapping
     $this->dm1 = $this->getMockDocumentManager('gedmo_extensions_test');
 }
コード例 #14
0
ファイル: config.php プロジェクト: jackbravo/symfony-sandbox
<?php

require_once __DIR__ . '/../../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
use Doctrine\Common\ClassLoader, Doctrine\Common\Annotations\AnnotationReader, Doctrine\ODM\MongoDB\Configuration, Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver, Doctrine\MongoDB\Connection, Doctrine\ODM\MongoDB\DocumentManager;
$classLoader = new ClassLoader('Doctrine\\Common', __DIR__ . '/../../lib/vendor/doctrine-common/lib');
$classLoader->register();
$classLoader = new ClassLoader('Doctrine\\ODM\\MongoDB', __DIR__ . '/../../lib');
$classLoader->register();
$classLoader = new ClassLoader('Doctrine\\MongoDB', __DIR__ . '/../../lib/vendor/doctrine-mongodb/lib');
$classLoader->register();
$classLoader = new ClassLoader('Symfony', __DIR__ . '/../../lib/vendor');
$classLoader->register();
$classLoader = new ClassLoader('Documents', __DIR__);
$classLoader->register();
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(__DIR__ . '/Hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setDefaultDB('doctrine_odm_sandbox');
/*
$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'));
$dm = DocumentManager::create(new Connection(), $config);
コード例 #15
0
    protected function getDocumentManager()
    {
        $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\\');
        $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
        return DocumentManager::create($this->getConnection(), $config);
    }
コード例 #16
0
 /**
  * Get annotation mapping configuration
  *
  * @return Doctrine\ORM\Configuration
  */
 private function getMockAnnotatedConfig()
 {
     $config = $this->getMock('Doctrine\\ODM\\MongoDB\\Configuration');
     $config->expects($this->once())->method('getProxyDir')->will($this->returnValue(__DIR__ . '/../../temp'));
     $config->expects($this->once())->method('getProxyNamespace')->will($this->returnValue('Proxy'));
     $config->expects($this->once())->method('getHydratorDir')->will($this->returnValue(__DIR__ . '/../../temp'));
     $config->expects($this->once())->method('getHydratorNamespace')->will($this->returnValue('Hydrator'));
     $config->expects($this->any())->method('getDefaultDB')->will($this->returnValue('gedmo_extensions_test'));
     $config->expects($this->once())->method('getAutoGenerateProxyClasses')->will($this->returnValue(true));
     $config->expects($this->once())->method('getAutoGenerateHydratorClasses')->will($this->returnValue(true));
     $config->expects($this->once())->method('getClassMetadataFactoryName')->will($this->returnValue('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadataFactory'));
     $config->expects($this->any())->method('getMongoCmd')->will($this->returnValue('$'));
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $mappingDriver = new AnnotationDriver($reader);
     $config->expects($this->any())->method('getMetadataDriverImpl')->will($this->returnValue($mappingDriver));
     return $config;
 }
コード例 #17
0
 /**
  * Add a new default annotation driver with a correctly configured annotation reader.
  * 
  * @param array $paths
  * @return Mapping\Driver\AnnotationDriver
  */
 public function newDefaultAnnotationDriver($paths = array())
 {
     if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0-DEV', '>=')) {
         // Register the ORM Annotations in the AnnotationRegistry
         AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
         $reader = new AnnotationReader();
         $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ApcCache());
     } else {
         if (version_compare(\Doctrine\Common\Version::VERSION, '2.3.0-DEV', '>=')) {
             // Register the ORM Annotations in the AnnotationRegistry
             // Done manually according to MongoDB ODM but that breaks existing code quickly
             AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
             $reader = new SimpleAnnotationReader();
             $reader->addNamespace('Doctrine\\OXM\\Mapping');
             $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ApcCache());
         } else {
             if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-DEV', '>=')) {
                 // Register the ORM Annotations in the AnnotationRegistry
                 AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
                 $reader = new AnnotationReader();
                 $reader->setDefaultAnnotationNamespace('Doctrine\\OXM\\Mapping\\');
                 $reader->setIgnoreNotImportedAnnotations(true);
                 $reader->setEnableParsePhpImports(false);
                 $reader = new \Doctrine\Common\Annotations\CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new \Doctrine\Common\Cache\ApcCache());
             } else {
                 $reader = new AnnotationReader();
                 $reader->setDefaultAnnotationNamespace('Doctrine\\OXM\\Mapping\\');
             }
         }
     }
     return new AnnotationDriver($reader, (array) $paths);
 }
コード例 #18
0
 /**
  * Create default annotation reader for extensions
  *
  * @return \Doctrine\Common\Annotations\AnnotationReader
  */
 private function getDefaultAnnotationReader()
 {
     if (null === self::$defaultAnnotationReader) {
         if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
             $reader = new \Doctrine\Common\Annotations\AnnotationReader();
             \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('Gedmo\\Mapping\\Annotation', __DIR__ . '/../../');
             $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache());
         } else {
             if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0RC4-DEV', '>=')) {
                 $reader = new \Doctrine\Common\Annotations\AnnotationReader();
                 \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('Gedmo\\Mapping\\Annotation', __DIR__ . '/../../');
                 $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
                 $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache());
             } else {
                 if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
                     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
                     $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
                     $reader->setIgnoreNotImportedAnnotations(true);
                     $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
                     $reader->setEnableParsePhpImports(false);
                     $reader->setAutoloadAnnotations(true);
                     $reader = new \Doctrine\Common\Annotations\CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache());
                 } else {
                     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
                     $reader->setAutoloadAnnotations(true);
                     $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
                     $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
                 }
             }
         }
         self::$defaultAnnotationReader = $reader;
     }
     return self::$defaultAnnotationReader;
 }
コード例 #19
0
 /**
  * Get annotation mapping configuration for ORM
  *
  * @param Doctrine\ORM\Mapping\Driver\Driver $mappingDriver
  * @return Doctrine\ORM\Configuration
  */
 private function getMockAnnotatedORMConfig(MappingDriverORM $mappingDriver = null)
 {
     $config = $this->getMock('Doctrine\\ORM\\Configuration');
     $config->expects($this->once())->method('getProxyDir')->will($this->returnValue(__DIR__ . '/../../temp'));
     $config->expects($this->once())->method('getProxyNamespace')->will($this->returnValue('Proxy'));
     $config->expects($this->once())->method('getAutoGenerateProxyClasses')->will($this->returnValue(true));
     $config->expects($this->once())->method('getClassMetadataFactoryName')->will($this->returnValue('Doctrine\\ORM\\Mapping\\ClassMetadataFactory'));
     if (is_null($mappingDriver)) {
         $reader = new AnnotationReader();
         $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
         $mappingDriver = new AnnotationDriverORM($reader);
     }
     $config->expects($this->any())->method('getMetadataDriverImpl')->will($this->returnValue($mappingDriver));
     return $config;
 }
コード例 #20
0
ファイル: DoctrineContainer.php プロジェクト: correar/P3
 /**
  * Take the configuration and return a mapping driver
  *
  * @param array &$config the driver options
  *
  * @return Doctrine\ORM\Mapping\Driver\Driver
  */
 private function _getMappingDriver(array &$config)
 {
     $drivers = array('XmlDriver' => 'Doctrine\\ORM\\Mapping\\Driver\\XmlDriver', 'YamlDriver' => 'Doctrine\\ORM\\Mapping\\Driver\\YamlDriver');
     if (is_array($config['mappingPaths']) === true) {
         foreach ($config['mappingPaths'] as $index => $path) {
             $config['mappingPaths'][$index] = \Yii::getPathOfAlias($path);
         }
     } else {
         $config['mappingPaths'] = \Yii::getPathOfAlias($config['mappingPaths']);
     }
     // set default annotation driver
     if (array_key_exists($config['mappingDriver'], $drivers) === false || $config['mappingDriver'] === 'AnnotationDriver') {
         $reader = new AnnotationReader();
         $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
         $driver = new AnnotationDriver($reader, $config['mappingPaths']);
         unset($config['mappingDriver']);
         unset($config['mappingPaths']);
         return $driver;
     }
     $mappingClass = $drivers[$config['mappingDriver']];
     $driver = new $mappingClass($config['mappingPaths']);
     if (isset($config['mappingDriverOptions']) === true) {
         foreach ($config['mappingDriverOptions'] as $key => $value) {
             $method = 'set' . ucfirst($key);
             if (method_exists($driver, $method) === true) {
                 $driver->{$method}($value);
             }
         }
         unset($config['mappingDriverOptions']);
     }
     unset($config['mappingDriver']);
     unset($config['mappingDriverPaths']);
     return $driver;
 }
コード例 #21
0
 /**
  * @return AnnotationReader
  */
 public function createAnnotationReader()
 {
     $reader = new AnnotationReader(new \Doctrine\Common\Cache\ArrayCache());
     $reader->setDefaultAnnotationNamespace('Doctrine\\Tests\\Common\\Annotations\\');
     return $reader;
 }
コード例 #22
0
 /**
  * DocumentManager
  *
  * @return DocumentManager
  */
 protected function getMockMongoDocumentManager()
 {
     $config = $this->getMock('Doctrine\\ODM\\MongoDB\\Configuration');
     $config->expects($this->once())->method('getProxyDir')->will($this->returnValue(__DIR__ . '/temp'));
     $config->expects($this->once())->method('getProxyNamespace')->will($this->returnValue('DocumentProxy'));
     $config->expects($this->once())->method('getHydratorDir')->will($this->returnValue(__DIR__ . '/temp'));
     $config->expects($this->once())->method('getHydratorNamespace')->will($this->returnValue('Hydrator'));
     $config->expects($this->any())->method('getDefaultDB')->will($this->returnValue('knp_paginator_bundle_test'));
     $config->expects($this->once())->method('getAutoGenerateProxyClasses')->will($this->returnValue(true));
     $config->expects($this->once())->method('getAutoGenerateHydratorClasses')->will($this->returnValue(true));
     $config->expects($this->once())->method('getClassMetadataFactoryName')->will($this->returnValue('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadataFactory'));
     $config->expects($this->any())->method('getMongoCmd')->will($this->returnValue('$'));
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $mappingDriver = new AnnotationDriverODM($reader);
     $config->expects($this->any())->method('getMetadataDriverImpl')->will($this->returnValue($mappingDriver));
     $conn = new Connection();
     try {
         $dm = DocumentManager::create($conn, $config);
         $dm->getConnection()->connect();
     } catch (\MongoException $e) {
         $this->markTestSkipped('Doctrine MongoDB ODM failed to connect');
     }
     return $dm;
 }
 /**
  * Add a new default annotation driver with a correctly configured annotation reader.
  * 
  * @param array $paths
  * @return Mapping\Driver\AnnotationDriver
  */
 public function newDefaultAnnotationDriver($paths = array())
 {
     if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0-DEV', '>=')) {
         // Register the ORM Annotations in the AnnotationRegistry
         AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
         $reader = new AnnotationReader();
         $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache());
     } else {
         if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-DEV', '>=')) {
             // Register the ORM Annotations in the AnnotationRegistry
             AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
             $reader = new AnnotationReader();
             $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
             $reader->setIgnoreNotImportedAnnotations(true);
             $reader->setEnableParsePhpImports(false);
             $reader = new \Doctrine\Common\Annotations\CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache());
         } else {
             $reader = new AnnotationReader();
             $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
         }
     }
     return new AnnotationDriver($reader, (array) $paths);
 }
コード例 #24
0
 public function testEmailAsAnnotation()
 {
     $reader = new AnnotationReader(new \Doctrine\Common\Cache\ArrayCache());
     $reader->setDefaultAnnotationNamespace('Doctrine\\Tests\\Common\\Annotations\\');
     $class = new ReflectionClass('Doctrine\\Tests\\Common\\Annotations\\Regression\\DummyClassWithEmail');
     $classAnnots = $reader->getClassAnnotations($class);
     $this->assertEquals(1, count($classAnnots));
 }
コード例 #25
0
 /**
  * Factory method for the Annotation Driver
  *
  * @param array|string $paths
  * @param AnnotationReader $reader
  * @return AnnotationDriver
  */
 public static function create($paths = array(), AnnotationReader $reader = null)
 {
     if ($reader == null) {
         $reader = new AnnotationReader();
         $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
     }
     return new self($reader, $paths);
 }
コード例 #26
0
 protected function getDocumentManager()
 {
     $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'));
     return DocumentManagerMock::create($this->getConnection(), $config);
 }