forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move common method for a CapsuleManager to trait, this would reduce t…
…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
Showing
3 changed files
with
71 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |