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)

Also remove duplicate "require-dev" component (when already explicitly declare in "require").

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jul 15, 2014
1 parent d46a280 commit 9ff8c7d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 118 deletions.
63 changes: 1 addition & 62 deletions src/Illuminate/Database/Capsule/Manager.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
<?php namespace Illuminate\Database\Capsule;

use PDO;
use Illuminate\Support\Fluent;
use Illuminate\Events\Dispatcher;
use Illuminate\Cache\CacheManager;
use Illuminate\Container\Container;
use Illuminate\Database\DatabaseManager;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Connectors\ConnectionFactory;
use Illuminate\Support\Traits\CapsuleManagerTrait;

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 +36,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 +152,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 +210,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
3 changes: 1 addition & 2 deletions src/Illuminate/Database/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"illuminate/cache": "4.2.*",
"illuminate/console": "4.2.*",
"illuminate/filesystem": "4.2.*",
"illuminate/pagination": "4.2.*",
"illuminate/support": "4.2.*"
"illuminate/pagination": "4.2.*"
},
"autoload": {
"psr-0": {
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 9ff8c7d

Please sign in to comment.