instance() public static méthode

create instance if not exists
public static instance ( Illuminate\Database\DatabaseManager $databaseManager, TransactionHandler $transaction, ProxyManager $proxy, Xpressengine\Support\CacheInterface $cache ) : DatabaseCoupler
$databaseManager Illuminate\Database\DatabaseManager database manager
$transaction TransactionHandler transaction handler
$proxy ProxyManager proxy manager
$cache Xpressengine\Support\CacheInterface cache
Résultat DatabaseCoupler
 /**
  * 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'));
     });
 }
 /**
  * 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());
 }