Beispiel #1
0
 public function getElement($className)
 {
     if (null === $this->_classCache) {
         $this->initialize();
     }
     if (!isset($this->_classCache[$className])) {
         $this->_classCache[$className] = parent::getElement($className);
     }
     return $this->_classCache[$className];
 }
 public function loadDoctrineConfiguration(Application $app)
 {
     $app['db.orm.config'] = $app->share(function () use($app) {
         $cache = $app['db.orm.cache'];
         $config = new ORMConfiguration();
         $config->setMetadataCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $chain = new MappingDriverChain();
         foreach ((array) $app['db.orm.entities'] as $entity) {
             switch ($entity['type']) {
                 case 'default':
                 case 'annotation':
                     $driver = $config->newDefaultAnnotationDriver((array) $entity['path'], false);
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                 case 'yml':
                     $driver = new YamlDriver((array) $entity['path']);
                     $driver->setFileExtension('.yml');
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                 case 'xml':
                     $driver = new XmlDriver((array) $entity['path'], $entity['namespace']);
                     $driver->setFileExtension('.xml');
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $entity['type']));
                     break;
             }
         }
         $config->setMetadataDriverImpl($chain);
         $config->setProxyDir($app['db.orm.proxies_dir']);
         $config->setProxyNamespace($app['db.orm.proxies_namespace']);
         $config->setAutoGenerateProxyClasses($app['db.orm.auto_generate_proxies']);
         $config->addCustomHydrationMode('SimpleArrayHydrator', 'App\\Provider\\SimpleArrayHydrator');
         // автолоад прокси
         $proxyDir = $app['db.orm.proxies_dir'];
         $proxyNamespace = $app['db.orm.proxies_namespace'];
         Autoloader::register($proxyDir, $proxyNamespace);
         return $config;
     });
 }
 public function loadDoctrineConfiguration(Application $app)
 {
     $self = $this;
     $app['db.orm.config'] = $app->share(function () use($app, $self) {
         $cache = $app['db.orm.cache'];
         $config = new ORMConfiguration();
         $config->setMetadataCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $chain = new DriverChain();
         foreach ((array) $app['db.orm.entities'] as $entity) {
             switch ($entity['type']) {
                 case 'default':
                 case 'annotation':
                     $driver = $config->newDefaultAnnotationDriver((array) $entity['path']);
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                 case 'yml':
                     $driver = new YamlDriver((array) $entity['path']);
                     $driver->setFileExtension('.yml');
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                 case 'xml':
                     $driver = new XmlDriver((array) $entity['path'], $entity['namespace']);
                     $driver->setFileExtension('.xml');
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $entity['type']));
                     break;
             }
             $self->autoloader->registerNamespace($entity['namespace'], $entity['path']);
         }
         $config->setMetadataDriverImpl($chain);
         $config->setProxyDir($app['db.orm.proxies_dir']);
         $config->setProxyNamespace($app['db.orm.proxies_namespace']);
         $config->setAutoGenerateProxyClasses($app['db.orm.auto_generate_proxies']);
         return $config;
     });
 }
Beispiel #4
0
 protected function _loadMappingFile($file)
 {
     $result = array();
     if (!is_array($file)) {
         $file = (array) $file;
     }
     $first = each($file);
     array_shift($file);
     $result = parent::_loadMappingFile($first[1]);
     reset($file);
     $className;
     foreach ($file as $mappingFile) {
         echo $mappingFile, "\n";
         $mapping = each(parent::_loadMappingFile($mappingFile));
         $className = $mapping['key'];
         $result[$className] = $this->_merge($result[$className], $mapping[1]);
     }
     echo $result[$className];
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION)
 {
     $locator = new SymfonyFileLocator((array) $prefixes, $fileExtension);
     parent::__construct($locator, $fileExtension);
 }
 public function loadDoctrineConfiguration(Application $app)
 {
     $app['doctrine.configuration'] = $app->share(function () use($app) {
         if (isset($app['doctrine.orm']) and true === $app['doctrine.orm']) {
             $config = new ORMConfiguration();
             $cache = new ApcCache();
             $config->setMetadataCacheImpl($cache);
             $config->setQueryCacheImpl($cache);
             $chain = new DriverChain();
             foreach ((array) $app['doctrine.orm.entities'] as $entity) {
                 switch ($entity['type']) {
                     case 'annotation':
                         $reader = new AnnotationReader();
                         $reader->setAnnotationNamespaceAlias('Doctrine\\ORM\\Mapping\\', 'orm');
                         $driver = new AnnotationDriver($reader, (array) $entity['path']);
                         $chain->addDriver($driver, $entity['namespace']);
                         break;
                     case 'yml':
                         $driver = new YamlDriver((array) $entity['path']);
                         $driver->setFileExtension('.yml');
                         $chain->addDriver($driver, $entity['namespace']);
                         break;
                     case 'xml':
                         $driver = new XmlDriver((array) $entity['path'], $entity['namespace']);
                         $driver->setFileExtension('.xml');
                         $chain->addDriver($driver, $entity['namespace']);
                         break;
                     default:
                         throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $type));
                         break;
                 }
             }
             $config->setMetadataDriverImpl($chain);
             $config->setProxyDir($app['doctrine.orm.proxies_dir']);
             $config->setProxyNamespace($app['doctrine.orm.proxies_namespace']);
             $config->setAutoGenerateProxyClasses($app['doctrine.orm.auto_generate_proxies']);
         } else {
             $config = new DBALConfiguration();
         }
         return $config;
     });
 }
 public function loadDoctrineConfiguration(Application $app)
 {
     $app['doctrine.configuration'] = $app->share(function () use($app) {
         if (isset($app['doctrine.orm']) and true === $app['doctrine.orm']) {
             // Check available cache drivers
             if (extension_loaded('apc')) {
                 $cache = new ApcCache();
             } else {
                 if (extension_loaded('xcache')) {
                     $cache = new XcacheCache();
                 } else {
                     if (extension_loaded('memcache')) {
                         $memcache = new \Memcache();
                         $memcache->connect('127.0.0.1');
                         $cache = new MemcacheCache();
                         $cache->setMemcache($memcache);
                     } else {
                         $cache = new ArrayCache();
                     }
                 }
             }
             $cache->setNamespace("dc2_");
             // to avoid collisions
             $config = new ORMConfiguration();
             $config->setMetadataCacheImpl($cache);
             $config->setQueryCacheImpl($cache);
             $config->setResultCacheImpl($cache);
             $chain = new DriverChain();
             foreach ((array) $app['doctrine.orm.entities'] as $entity) {
                 switch ($entity['type']) {
                     case 'annotation':
                         $reader = new AnnotationReader();
                         $driver = new AnnotationDriver($reader, (array) $entity['path']);
                         $chain->addDriver($driver, $entity['namespace']);
                         break;
                     case 'yml':
                         $driver = new YamlDriver((array) $entity['path']);
                         $driver->setFileExtension('.yml');
                         $chain->addDriver($driver, $entity['namespace']);
                         break;
                     case 'xml':
                         $driver = new XmlDriver((array) $entity['path'], $entity['namespace']);
                         $driver->setFileExtension('.xml');
                         $chain->addDriver($driver, $entity['namespace']);
                         break;
                     default:
                         throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $entity['type']));
                         break;
                 }
             }
             $config->setMetadataDriverImpl($chain);
             $config->setProxyDir($app['doctrine.orm.proxies_dir']);
             $config->setProxyNamespace($app['doctrine.orm.proxies_namespace']);
             $config->setAutoGenerateProxyClasses($app['doctrine.orm.auto_generate_proxies']);
         } else {
             $config = new DBALConfiguration();
         }
         return $config;
     });
 }