Beispiel #1
0
 /**
  * @param array $paths
  * @return \Doctrine\ORM\Mapping\Driver\AnnotationDriver
  */
 protected function createAnnotationDriver($paths = array(), $alias = null)
 {
     if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0', '>=')) {
         $reader = new \Doctrine\Common\Annotations\CachedReader(new \Doctrine\Common\Annotations\AnnotationReader(), new ArrayCache());
     } else {
         if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
             // Register the ORM Annotations in the AnnotationRegistry
             $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
             $reader->addNamespace('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->setIgnoreNotImportedAnnotations(true);
                 $reader->setEnableParsePhpImports(false);
                 if ($alias) {
                     $reader->setAnnotationNamespaceAlias('Doctrine\\ORM\\Mapping\\', $alias);
                 } else {
                     $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
                 }
                 $reader = new \Doctrine\Common\Annotations\CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache());
             } else {
                 $reader = new \Doctrine\Common\Annotations\AnnotationReader();
                 if ($alias) {
                     $reader->setAnnotationNamespaceAlias('Doctrine\\ORM\\Mapping\\', $alias);
                 } else {
                     $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
                 }
             }
         }
     }
     \Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . "/../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
     return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array) $paths);
 }
 /**
  * @param array $paths
  * @return \Doctrine\Common\Annotations\AnnotationReader
  */
 protected function createAnnotationDriver($paths = array(), $alias = null)
 {
     if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0', '>=')) {
         $reader = new \Doctrine\Common\Annotations\CachedReader(new \Doctrine\Common\Annotations\AnnotationReader(), new ArrayCache());
     } else {
         if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
             $reader = new \Doctrine\Common\Annotations\AnnotationReader();
             $reader->setIgnoreNotImportedAnnotations(true);
             $reader->setEnableParsePhpImports(false);
             if ($alias) {
                 $reader->setAnnotationNamespaceAlias('Doctrine\\ORM\\Mapping\\', $alias);
             } else {
                 $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
             }
             $reader = new \Doctrine\Common\Annotations\CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache());
         } else {
             $reader = new \Doctrine\Common\Annotations\AnnotationReader();
             if ($alias) {
                 $reader->setAnnotationNamespaceAlias('Doctrine\\ORM\\Mapping\\', $alias);
             } else {
                 $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
             }
         }
     }
     return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array) $paths);
 }
Beispiel #3
0
        $classLoader = new \Doctrine\Common\ClassLoader($name);
    }
    $classLoader->register();
}
foreach ($entitiesPath as $name => $path) {
    $classLoader = new \Doctrine\Common\ClassLoader($name, $path);
    $classLoader->register();
}
// Setup Entity Manager
// ****************************************************************
$ormConfig = new \Doctrine\ORM\Configuration();
// custom zend form annotations
$annoReader = new \Doctrine\Common\Annotations\AnnotationReader();
$annoReader->setAutoloadAnnotations(true);
$annoReader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
$annoReader->setAnnotationNamespaceAlias('Awe\\Annotations\\', 'awe');
$annoDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($annoReader, $entitiesPath);
$ormConfig->setMetadataDriverImpl($annoDriver);
// logging
$ormConfig->setSQLLogger(new \Doctrine\DBAL\Logging\FileSQLLogger($logPath));
// caching
if (is_array($cacheType)) {
    $ormConfig->setQueryCacheImpl(new $cacheType['query']());
    $ormConfig->setMetadataCacheImpl(new $cacheType['metadata']());
} else {
    $ormConfig->setQueryCacheImpl(new $cacheType());
    $ormConfig->setMetadataCacheImpl(new $cacheType());
}
// proxies
$ormConfig->setAutoGenerateProxyClasses(true);
$ormConfig->setProxyDir($proxiesPath . '/Proxies');
 /**
  * Gets the 'doctrine.orm.default_configuration' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @return Doctrine\ORM\Configuration A Doctrine\ORM\Configuration instance.
  */
 protected function getDoctrine_Orm_DefaultConfigurationService()
 {
     $a = new \Doctrine\Common\Cache\ArrayCache();
     $a->setNamespace('sf2orm_default_40ceb0fc2536c243bed418a2d3ecc2f2');
     $b = new \Doctrine\Common\Cache\ArrayCache();
     $b->setNamespace('sf2orm_default_40ceb0fc2536c243bed418a2d3ecc2f2');
     $c = new \Doctrine\Common\Cache\ArrayCache();
     $c->setNamespace('sf2orm_default_40ceb0fc2536c243bed418a2d3ecc2f2');
     $d = new \Doctrine\Common\Annotations\AnnotationReader();
     $d->setAnnotationNamespaceAlias('Doctrine\\ORM\\Mapping\\', 'orm');
     $e = new \Doctrine\ORM\Mapping\Driver\DriverChain();
     $e->addDriver(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($d, array(0 => '/var/www/symfony2.0/alf/src/Alf/ShopBundle/Entity')), 'Alf\\ShopBundle\\Entity');
     $this->services['doctrine.orm.default_configuration'] = $instance = new \Doctrine\ORM\Configuration();
     $instance->setEntityNamespaces(array('AlfShopBundle' => 'Alf\\ShopBundle\\Entity'));
     $instance->setMetadataCacheImpl($a);
     $instance->setQueryCacheImpl($b);
     $instance->setResultCacheImpl($c);
     $instance->setMetadataDriverImpl($e);
     $instance->setProxyDir('/var/www/symfony2.0/alf/app/cache/dev/doctrine/orm/Proxies');
     $instance->setProxyNamespace('Proxies');
     $instance->setAutoGenerateProxyClasses(true);
     $instance->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
     return $instance;
 }
 /**
  * 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());
         } elseif (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());
         } elseif (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;
 }
    public function testLoadPrefixedMetadata()
    {
        $this->generator->setAnnotationPrefix('mongodb:');
        $metadata = $this->generateBookDocumentFixture();

        $book = $this->newInstance($metadata);

        $cm = new \Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo($metadata->name);
        $reader = new \Doctrine\Common\Annotations\AnnotationReader();
        $reader->setAnnotationNamespaceAlias("Doctrine\\ODM\\MongoDB\\Mapping\\", "mongodb");
        $driver = new \Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver($reader);
        $driver->loadMetadataForClass($cm->name, $cm);

        $this->assertEquals($cm->getCollection(), $metadata->getCollection());
        $this->assertEquals($cm->lifecycleCallbacks, $metadata->lifecycleCallbacks);
        $this->assertEquals($cm->identifier, $metadata->identifier);
        $this->assertEquals($cm->idGenerator, $metadata->idGenerator);
        $this->assertEquals($cm->customRepositoryClassName, $metadata->customRepositoryClassName);
    }
 public function testLoadPrefixedMetadata()
 {
     $this->_generator->setAnnotationPrefix('orm:');
     $metadata = $this->generateBookEntityFixture();
     $book = $this->newInstance($metadata);
     $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name);
     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
     $reader->setAnnotationNamespaceAlias("Doctrine\\ORM\\Mapping\\", "orm");
     $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
     $driver->loadMetadataForClass($cm->name, $cm);
     $this->assertEquals($cm->columnNames, $metadata->columnNames);
     $this->assertEquals($cm->getTableName(), $metadata->getTableName());
     $this->assertEquals($cm->lifecycleCallbacks, $metadata->lifecycleCallbacks);
     $this->assertEquals($cm->identifier, $metadata->identifier);
     $this->assertEquals($cm->idGenerator, $metadata->idGenerator);
     $this->assertEquals($cm->customRepositoryClassName, $metadata->customRepositoryClassName);
 }