public function __construct(EntityManagerProvider $provider)
 {
     $this->provider = $provider;
     $connection = $provider->getDriver()->connection();
     $eventManager = $connection->getEventManager();
     $config = $provider->getConfiguration()->config();
     parent::__construct($connection, $config, $eventManager);
 }
 /**
  * @dataProvider provider
  * @test
  */
 public function should_create_new_instance_with_method_on($driver, $configuration, $dbParams)
 {
     $provider = EntityManagerProvider::getInstance();
     $em = new ProxyEntityManager($provider);
     $emRead = $em->on('read');
     $this->assertInstanceOf('Doctrine\\ORM\\EntityManager', $emRead);
     $this->assertTrue(in_array($dbParams['read']['database'], $emRead->getConnection()->getParams()));
     $this->assertEquals($dbParams['read']['username'], $emRead->getConnection()->getUsername());
 }
 /**
  * @dataProvider provider
  * @test
  */
 public function should_create_read_entity_manager($cache, $dbParams, $params)
 {
     $driver = new DriverManagerProvider($dbParams);
     $configuration = new ConfigurationProvider($cache, $params);
     $provider = EntityManagerProvider::getInstance();
     $provider->driver($driver);
     $provider->configuration($configuration);
     $em = $provider->create('read');
     $this->assertInstanceOf('Doctrine\\ORM\\EntityManager', $em);
     $this->assertTrue(in_array($dbParams['read']['database'], $em->getConnection()->getParams()));
 }
Ejemplo n.º 4
0
 public function getCommandProvider()
 {
     $cache = CacheFactory::make('array');
     $dbParams = $this->getDbParams();
     $params = $this->getDoctrineParams();
     $driver = new DriverManagerProvider($dbParams);
     $configuration = new ConfigurationProvider($cache, $params);
     $emProvider = EntityManagerProvider::getInstance();
     $emProvider->driver($driver);
     $emProvider->configuration($configuration);
     $emProxy = new ProxyEntityManager($emProvider);
     $commandProvider = new DoctrineCommandProvider($emProxy);
     return $commandProvider;
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     /**
      * @param Application $app Laravel Application
      * @param array $params Connection to be used
      *
      * @return EntityManager
      */
     $this->app->singleton('Doctrine\\ORM\\EntityManager', function ($app) {
         $provider = $app->make('Paolooo\\LaravelDoctrine\\Providers\\EntityManagerProvider');
         return new ProxyEntityManager($provider);
     });
     /**
      * Provides a config for EntityManager
      *
      * @return EntityManagerProvider
      */
     $this->app->singleton('Paolooo\\LaravelDoctrine\\Providers\\EntityManagerProvider', function () {
         // Cache
         $cacheType = config('cache.default');
         $path = config("cache.stores.{$cacheType}.path");
         $cache = CacheFactory::make($cacheType, $path);
         // DB Driver
         $dbType = config('database.default');
         $dbParams = config("database.connections.{$dbType}");
         $driver = new DriverManagerProvider($dbParams);
         // Doctrin Params
         $params = config('doctrine');
         $configuration = new ConfigurationProvider($cache, $params);
         $provider = EntityManagerProvider::getInstance();
         $provider->driver($driver);
         $provider->configuration($configuration);
         return $provider;
     });
     $this->commands(['Paolooo\\LaravelDoctrine\\Console\\DoctrineCommand']);
 }