Exemplo n.º 1
0
 /**
  * Create a entity manager used for the package installation,
  * update and unistall process.
  *
  * @return \Doctrine\ORM\EntityManager
  */
 public function getPackageEntityManager()
 {
     $providerFactory = new PackageProviderFactory($this->app, $this);
     $provider = $providerFactory->getEntityManagerProvider();
     $drivers = $provider->getDrivers();
     if (count($drivers)) {
         $config = Setup::createConfiguration(true, $this->app->make('config')->get('database.proxy_classes'));
         $driverImpl = new MappingDriverChain();
         $coreDriver = new CoreDriver($this->app);
         // Add the core driver to it so packages can extend the core and not break.
         $driverImpl->addDriver($coreDriver->getDriver(), $coreDriver->getNamespace());
         foreach ($drivers as $driver) {
             $driverImpl->addDriver($driver->getDriver(), $driver->getNamespace());
         }
         $config->setMetadataDriverImpl($driverImpl);
         $em = EntityManager::create(\Database::connection(), $config);
         return $em;
     }
 }
 /**
  *
  * @return \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain
  */
 public function getMetadataDriverImpl()
 {
     // Register the doctrine Annotations
     \Doctrine\Common\Annotations\AnnotationRegistry::registerFile('doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
     $legacyNamespace = $this->getConfigRepository()->get('app.enable_legacy_src_namespace');
     if ($legacyNamespace) {
         \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('Application\\Src', DIR_BASE . '/application/src');
     } else {
         \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('Application\\Entity', DIR_BASE . '/application/src/Entity');
     }
     // Remove all unkown annotations from the AnnotationReader used by the SimpleAnnotationReader
     // to prevent fatal errors
     $this->registerGlobalIgnoredAnnotations();
     // initiate the driver chain which will hold all driver instances
     $driverChain = $this->app->make('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriverChain');
     $coreDriver = new CoreDriver($this->app);
     $driver = $coreDriver->getDriver();
     $driver->addExcludePaths($this->getConfigRepository()->get('database.proxy_exclusions', array()));
     $driverChain->addDriver($driver, $coreDriver->getNamespace());
     // Register application metadata driver
     $config = $this->getConfigRepository();
     $applicationDriver = new ApplicationDriver($config, $this->app);
     $driver = $applicationDriver->getDriver();
     if (is_object($driver)) {
         // $driver might be null, if there's no application/src/Entity
         $driverChain->addDriver($driver, $applicationDriver->getNamespace());
     }
     return $driverChain;
 }