Skip to content

Commit

Permalink
instance allow to force create a new instance
Browse files Browse the repository at this point in the history
  • Loading branch information
rochamarcelo authored Aug 28, 2017
1 parent 42a7a1b commit 5a50417
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Di/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ public function __construct(Container $container = null)
}
$this->container = $container;
}

/**
* Get static instance of this class
*
* @param string $name Instance identifier name
*
* @param string $name Instance identifier name
* @param bool $forceNew Should ignore old instance and force new one
* @return Di
*/
public static function instance($name = null)
public static function instance($name = null, $forceNew = false)
{
static $instance;
if ($name === null) {
Expand All @@ -55,7 +54,7 @@ public static function instance($name = null)
throw new \InvalidArgumentException('$name must be a string value');
}

if (!isset($instance[$name])) {
if (!isset($instance[$name]) || $forceNew === true) {
$instance[$name] = new static();
}

Expand Down

0 comments on commit 5a50417

Please sign in to comment.