Skip to content

Commit

Permalink
Move common method for a CapsuleManager to trait, this would reduce t…
Browse files Browse the repository at this point in the history
…he requirement to produce new CapsuleManager for other component in the future (e.g: laravel#5032)

Signed-off-by: crynobone <[email protected]>
  • Loading branch information
crynobone committed Jul 15, 2014
1 parent d46a280 commit e4694e6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 116 deletions.
62 changes: 0 additions & 62 deletions src/Illuminate/Database/Capsule/Manager.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace Illuminate\Database\Capsule;

use PDO;
use Illuminate\Support\Fluent;
use Illuminate\Events\Dispatcher;
use Illuminate\Cache\CacheManager;
use Illuminate\Container\Container;
Expand All @@ -11,27 +10,13 @@

class Manager {

/**
* The current globally used instance.
*
* @var \Illuminate\Database\Capsule\Manager
*/
protected static $instance;

/**
* The database manager instance.
*
* @var \Illuminate\Database\DatabaseManager
*/
protected $manager;

/**
* The container instance.
*
* @var \Illuminate\Container\Container
*/
protected $container;

/**
* Create a new database capsule manager.
*
Expand All @@ -50,22 +35,6 @@ public function __construct(Container $container = null)
$this->setupManager();
}

/**
* Setup the IoC container instance.
*
* @param \Illuminate\Container\Container|null $container
* @return void
*/
protected function setupContainer($container)
{
$this->container = $container ?: new Container;

if ( ! $this->container->bound('config'))
{
$this->container->instance('config', new Fluent);
}
}

/**
* Setup the default database configuration options.
*
Expand Down Expand Up @@ -182,16 +151,6 @@ public function setFetchMode($fetchMode)
return $this;
}

/**
* Make this capsule instance available globally.
*
* @return void
*/
public function setAsGlobal()
{
static::$instance = $this;
}

/**
* Get the database manager instance.
*
Expand Down Expand Up @@ -250,27 +209,6 @@ public function setCacheManager(CacheManager $cache)
$this->container->instance('cache', $cache);
}

/**
* Get the IoC container instance.
*
* @return \Illuminate\Container\Container
*/
public function getContainer()
{
return $this->container;
}

/**
* Set the IoC container instance.
*
* @param \Illuminate\Container\Container $container
* @return void
*/
public function setContainer(Container $container)
{
$this->container = $container;
}

/**
* Dynamically pass methods to the default connection.
*
Expand Down
56 changes: 2 additions & 54 deletions src/Illuminate/Queue/Capsule/Manager.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<?php namespace Illuminate\Queue\Capsule;

use Illuminate\Support\Fluent;
use Illuminate\Queue\QueueManager;
use Illuminate\Container\Container;
use Illuminate\Queue\QueueServiceProvider;
use Illuminate\Support\Traits\CapsuleManagerTrait;

class Manager {

/**
* The current globally used instance.
*
* @var \Illuminate\Queue\Capsule\Manager
*/
protected static $instance;
use CapsuleManagerTrait;

/**
* The queue manager instance.
Expand Down Expand Up @@ -41,22 +36,6 @@ public function __construct(Container $container = null)
$this->registerConnectors();
}

/**
* Setup the IoC container instance.
*
* @param \Illuminate\Container\Container $container
* @return void
*/
protected function setupContainer($container)
{
$this->container = $container ?: new Container;

if ( ! $this->container->bound('config'))
{
$this->container->instance('config', new Fluent);
}
}

/**
* Setup the default queue configuration options.
*
Expand Down Expand Up @@ -166,16 +145,6 @@ public function addConnection(array $config, $name = 'default')
$this->container['config']["queue.connections.{$name}"] = $config;
}

/**
* Make this capsule instance available globally.
*
* @return void
*/
public function setAsGlobal()
{
static::$instance = $this;
}

/**
* Get the queue manager instance.
*
Expand All @@ -186,27 +155,6 @@ public function getQueueManager()
return $this->manager;
}

/**
* Get the IoC container instance.
*
* @return \Illuminate\Container\Container
*/
public function getContainer()
{
return $this->container;
}

/**
* Set the IoC container instance.
*
* @param \Illuminate\Container\Container $container
* @return void
*/
public function setContainer(Container $container)
{
$this->container = $container;
}

/**
* Pass dynamic instance methods to the manager.
*
Expand Down
69 changes: 69 additions & 0 deletions src/Illuminate/Support/Traits/CapsuleManagerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php namespace Illuminate\Support\Traits;

use Illuminate\Container\Container;
use Illuminate\Support\Fluent;

trait CapsuleManagerTrait {

/**
* The current globally used instance.
*
* @var object
*/
protected static $instance;

/**
* The container instance.
*
* @var \Illuminate\Container\Container
*/
protected $container;

/**
* Setup the IoC container instance.
*
* @param \Illuminate\Container\Container|null $container
* @return void
*/
protected function setupContainer($container)
{
$this->container = $container ?: new Container;

if ( ! $this->container->bound('config'))
{
$this->container->instance('config', new Fluent);
}
}

/**
* Make this capsule instance available globally.
*
* @return void
*/
public function setAsGlobal()
{
static::$instance = $this;
}

/**
* Get the IoC container instance.
*
* @return \Illuminate\Container\Container
*/
public function getContainer()
{
return $this->container;
}

/**
* Set the IoC container instance.
*
* @param \Illuminate\Container\Container $container
* @return void
*/
public function setContainer(Container $container)
{
$this->container = $container;
}

}

0 comments on commit e4694e6

Please sign in to comment.