Ejemplo n.º 1
0
 public function register(Application $app)
 {
     $app['orm.em.paths'] = $app->share(function () {
         return array();
     });
     $app['orm.event_manager'] = $app->share(function () use($app) {
         return new EventManager();
     });
     $app['orm.config'] = $app->share(function () use($app) {
         return Setup::createConfiguration($app['debug']);
     });
     $app['orm.anotation_reader'] = $app->share(function () use($app) {
         $annotationReader = new AnnotationReader();
         $cache = $app['orm.config']->getMetadataCacheImpl();
         return new CachedReader($annotationReader, $cache);
     });
     $app['orm.default_anotation_driver'] = $app->share(function () use($app) {
         AnnotationRegistry::registerFile($app['vendor_dir'] . '/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
         return new AnnotationDriver($app['orm.anotation_reader'], $app['orm.em.paths']);
     });
     $app['orm.em'] = $app->share(function () use($app) {
         $annotationReader = $app['orm.anotation_reader'];
         $eventManager = $app['orm.event_manager'];
         $driverChain = new MappingDriverChain();
         $driverChain->setDefaultDriver($app['orm.default_anotation_driver']);
         DoctrineExtensions::registerMappingIntoDriverChainORM($driverChain, $annotationReader);
         $loggableListener = new LoggableListener();
         $loggableListener->setAnnotationReader($annotationReader);
         $loggableListener->setUsername('admin');
         $eventManager->addEventSubscriber($loggableListener);
         $config = $app['orm.config'];
         $config->setMetadataDriverImpl($driverChain);
         return EntityManager::create($app['db.default_options'], $config, $eventManager);
     });
 }
 /**
  * Boot the service provider
  *
  * @param ManagerRegistry $registry
  */
 public function boot(ManagerRegistry $registry)
 {
     foreach ($registry->getManagers() as $manager) {
         $chain = $manager->getConfiguration()->getMetadataDriverImpl();
         $reader = $chain->getReader();
         if ($this->app->make('config')->get('doctrine.gedmo.all_mappings', false)) {
             DoctrineExtensions::registerMappingIntoDriverChainORM($chain, $reader);
         } else {
             DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($chain, $reader);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     $doctrine = (require CONFIG_PATH . DIRECTORY_SEPARATOR . 'doctrine.php');
     $mappings = $doctrine['orm']['orm.em.options']['mappings'];
     $paths = [];
     foreach ($mappings as $mapping) {
         $paths[] = $mapping['path'];
     }
     $reader = new CachedReader(new AnnotationReader(), new ArrayCache());
     $driverChain = new DriverChain();
     DoctrineExtensions::registerMappingIntoDriverChainORM($driverChain, $reader);
     $annotationDriver = new AnnotationDriver($reader, $paths);
     foreach ($mappings as $mapping) {
         $driverChain->addDriver($annotationDriver, $mapping['namespace']);
     }
     if (!isset($app['orm.em'])) {
         throw new FatalErrorException('The DoctrineOrmServiceProvider is not registered in this application');
     }
     $app['orm.em']->getConfiguration()->setMetadataDriverImpl($driverChain);
 }
Ejemplo n.º 4
0
 /**
  * Todo: Should be removed once GedmoExtension in the laravel-doctrine/extensions repo is tested to work
  * @param bool $all
  */
 public function enableGedmoExtensions($all = true)
 {
     if ($all) {
         DoctrineExtensions::registerMappingIntoDriverChainORM($this->driverChain->getChain(), $this->driverChain->getReader());
     } else {
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($this->driverChain->getChain(), $this->driverChain->getReader());
     }
 }
Ejemplo n.º 5
0
 /**
  * Enable Gedmo Doctrine Extensions
  *
  * @param array $namespaces
  * @param bool  $all
  */
 public function bootGedmoExtensions($namespaces = ['App'], $all = true)
 {
     if ($all) {
         DoctrineExtensions::registerMappingIntoDriverChainORM($this->chain, $this->reader);
     } else {
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($this->chain, $this->reader);
     }
     $driver = $this->metadata->getMetadataDriverImpl();
     foreach ($namespaces as $namespace) {
         $this->chain->addDriver($driver, $namespace);
     }
     $this->metadata->setMetadataDriverImpl($this->chain);
     $this->dispatcher->fire('doctrine.driver-chain::booted', [$driver, $this->chain]);
 }