예제 #1
0
 public function test_get_alias_namespace()
 {
     $this->container->shouldReceive('singleton');
     $this->registry->addManager('default');
     $em = m::mock(EntityManagerInterface::class);
     $configuration = m::mock(Configuration::class);
     $this->container->shouldReceive('make')->with('doctrine.managers.default')->andReturn($em);
     $em->shouldReceive('getConfiguration')->andReturn($configuration);
     $configuration->shouldReceive('getEntityNamespace')->with('Alias')->once()->andReturn('Namespace');
     $this->assertEquals('Namespace', $this->registry->getAliasNamespace('Alias'));
 }
 /**
  * Verify that getManager() returns a new instance after a call to resetManager().
  */
 public function test_get_manager_after_reset_should_return_new_manager()
 {
     $this->container->shouldReceive('singleton');
     $this->registry->addManager('default');
     $this->container->shouldReceive('make')->with('doctrine.managers.default')->andReturn(new stdClass(), new stdClass());
     $first = $this->registry->getManager();
     $this->container->shouldReceive('forgetInstance');
     $this->registry->resetManager();
     $second = $this->registry->getManager();
     $this->assertNotSame($first, $second);
 }
예제 #3
0
 /**
  * 
  *
  * @param string $defaultConnection
  * @static 
  */
 public static function setDefaultConnection($defaultConnection)
 {
     return \LaravelDoctrine\ORM\IlluminateRegistry::setDefaultConnection($defaultConnection);
 }
 /**
  * Register the manager registry
  */
 protected function registerManagerRegistry()
 {
     $this->app->singleton('registry', function ($app) {
         $registry = new IlluminateRegistry($app, $app->make(EntityManagerFactory::class));
         // Add all managers into the registry
         foreach ($app->make('config')->get('doctrine.managers', []) as $manager => $settings) {
             $registry->addManager($manager, $settings);
             $registry->addConnection($manager);
         }
         return $registry;
     });
     $this->app->alias('registry', ManagerRegistry::class);
     $this->app->alias('registry', IlluminateRegistry::class);
 }
예제 #5
0
 /**
  * Gets the object manager associated with a given class.
  *
  * @param string $class A persistent object class name.
  * @return \Doctrine\Common\Persistence\ObjectManager|null 
  * @static 
  */
 public static function getManagerForClass($class)
 {
     return \LaravelDoctrine\ORM\IlluminateRegistry::getManagerForClass($class);
 }
예제 #6
0
 /**
  * Setup the entity managers
  * @return array
  */
 protected function setUpEntityManagers()
 {
     $managers = [];
     $connections = [];
     foreach ($this->app->config->get('doctrine.managers', []) as $manager => $settings) {
         $managerName = IlluminateRegistry::getManagerNamePrefix() . $manager;
         $connectionName = IlluminateRegistry::getConnectionNamePrefix() . $manager;
         // Bind manager
         $this->app->singleton($managerName, function () use($settings) {
             $manager = EntityManager::create(ConnectionManager::resolve(array_get($settings, 'connection')), MetaDataManager::resolve(array_get($settings, 'meta')));
             $configuration = $manager->getConfiguration();
             // Listeners
             if (isset($settings['events']['listeners'])) {
                 foreach ($settings['events']['listeners'] as $event => $listener) {
                     $manager->getEventManager()->addEventListener($event, $listener);
                 }
             }
             // Subscribers
             if (isset($settings['events']['subscribers'])) {
                 foreach ($settings['events']['subscribers'] as $subscriber) {
                     if (class_exists($subscriber, false)) {
                         $subscriberInstance = new $subscriber();
                         $manager->getEventManager()->addEventSubscriber($subscriberInstance);
                     } else {
                         throw new ClassNotFound($subscriber);
                     }
                 }
             }
             // Filters
             if (isset($settings['filters'])) {
                 foreach ($settings['filters'] as $name => $filter) {
                     $configuration->getMetadataDriverImpl()->addFilter($name, $filter);
                     $manager->getFilters()->enable($name);
                 }
             }
             // Paths
             $paths = array_get($settings, 'paths', []);
             $meta = $configuration->getMetadataDriverImpl();
             if (method_exists($meta, 'addPaths')) {
                 $meta->addPaths($paths);
             } elseif (method_exists($meta, 'getLocator')) {
                 $meta->getLocator()->addPaths($paths);
             }
             // Repository
             $configuration->setDefaultRepositoryClassName(array_get($settings, 'repository', EntityRepository::class));
             // Proxies
             $configuration->setProxyDir(array_get($settings, 'proxies.path', storage_path('proxies')));
             $configuration->setAutoGenerateProxyClasses(array_get($settings, 'proxies.auto_generate', false));
             if ($namespace = array_get($settings, 'proxies.namespace', false)) {
                 $configuration->setProxyNamespace($namespace);
             }
             return $manager;
         });
         // Bind connection
         $this->app->singleton($connectionName, function ($app) use($manager) {
             $app->make(IlluminateRegistry::getManagerNamePrefix() . $manager)->getConnection();
         });
         $managers[$manager] = $manager;
         $connections[$manager] = $manager;
     }
     return [$managers, $connections];
 }