* 생성된 VirtualConnection 관리 및 DatabaseManager 를 이용한 Connection 생성 * VirtualConnection 에서 접근해야 할 자원들 모음
Author: XE Developers (developers@xpressengine.com)
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     DynamicModel::clearBootedModels();
     $this->app->singleton('xe.db.proxy', function ($app) {
         return ProxyManager::instance($app['xe.register']);
     });
     $this->app->singleton(['xe.db' => DatabaseHandler::class], function ($app) {
         $coupler = DatabaseCoupler::instance($app['db'], TransactionHandler::instance(), $app['xe.db.proxy'], new LaravelCache($app['cache']->driver('schema')));
         $proxyClass = $app['xe.interception']->proxy(DatabaseHandler::class, 'XeDB');
         return new $proxyClass($coupler, $app['config']->get('xe.database'));
     });
 }
 /**
  * set database table schema
  *
  * @param string $table table name
  * @param bool   $force force
  * @return bool
  */
 public function setSchemaCache($table, $force = false)
 {
     $cache = $this->coupler->getCache();
     if ($force === true) {
         $cache->forget($table);
     }
     $schema = $this->getConnection('master')->getSchemaBuilder()->getColumnListing($table);
     if (count($schema) === 0) {
         return false;
     }
     $cache->put($table, $schema);
     return true;
 }
 /**
  * test manager connector
  *
  * @return void
  */
 public function testManageConnector()
 {
     $defaultConnection = m::mock('Illuminate\\Database\\Connection');
     $defaultConnection->shouldReceive('getName')->andReturn('default');
     $defaultConnection->shouldReceive('transactionLevel')->andReturn(0);
     $someConnection = m::mock('Illuminate\\Database\\Connection');
     $someConnection->shouldReceive('getName')->andReturn('some');
     $someConnection->shouldReceive('transactionLevel')->andReturn(0);
     $databaseManager = m::mock('Illuminate\\Database\\DatabaseManager');
     $databaseManager->shouldReceive('connection')->with(null)->andReturn($defaultConnection);
     $databaseManager->shouldReceive('connection')->with('some')->andReturn($someConnection);
     $transactionHandler = m::mock('Xpressengine\\Database\\TransactionHandler');
     $transactionHandler->shouldReceive('init')->andReturn();
     $transactionHandler->shouldReceive('setCurrent')->andReturn();
     $proxyManager = m::mock('Xpressengine\\Database\\ProxyManager');
     $cache = m::mock('Xpressengine\\Support\\CacheInterface');
     /**
      * @var \Illuminate\Database\DatabaseManager $databaseManager
      * @var \Xpressengine\Database\TransactionHandler $transactionHandler
      * @var \Xpressengine\Database\ProxyManager $proxyManager
      */
     $coupler = DatabaseCoupler::instance($databaseManager, $transactionHandler, $proxyManager, $cache);
     $newConnector = m::mock('Xpressengine\\Database\\VirtualConnection');
     $newConnector->shouldReceive('getName')->andReturn('default');
     $coupler->addConnector('default', $newConnector);
     $this->assertEquals(1, count($coupler->connectors()));
     $newConnector = m::mock('Xpressengine\\Database\\VirtualConnection');
     $newConnector->shouldReceive('getName')->andReturn('some');
     $coupler->addConnector('some', $newConnector);
     $this->assertEquals(2, count($coupler->connectors()));
     $connector = $coupler->getConnector();
     $this->assertEquals('default', $connector->getName());
     $connector = $coupler->getConnector('some');
     $this->assertEquals('some', $connector->getName());
     $connection = $coupler->connect('default');
     $this->assertEquals('default', $connection->getName());
     $connection = $coupler->connect('some');
     $this->assertEquals('some', $connection->getName());
 }
 /**
  * $connectionHandlers 가 갖고 있는 connection Rollbsack.
  * /Illuminate/Database/Connection 의 rollBack.
  *
  * @param DatabaseCoupler $coupler database coupler
  * @return void
  */
 public function rollBack(DatabaseCoupler $coupler)
 {
     if ($this->globalTransactions == 1) {
         $this->globalTransactions = 0;
         /** @var VirtualConnection $connector */
         foreach ($coupler->connectors() as $connector) {
             if ($connector->master()->transactionLevel() >= 1) {
                 $connector->master()->rollBack();
             }
         }
     } else {
         --$this->globalTransactions;
     }
 }
 /**
  * Illuminate\Database\ConnectionResolverInterface
  *
  * @param string $connectionName connection 이름
  * @return void
  */
 public function setDefaultConnection($connectionName)
 {
     $this->coupler->databaseManager()->setDefaultConnection($connectionName);
 }