-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
Removing some old methods such as share() in favor of the more common and documented singleton().
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,7 +143,9 @@ public function bound($abstract) | |
{ | ||
$abstract = $this->normalize($abstract); | ||
|
||
return isset($this->bindings[$abstract]) || isset($this->instances[$abstract]) || $this->isAlias($abstract); | ||
return isset($this->bindings[$abstract]) || | ||
isset($this->instances[$abstract]) || | ||
$this->isAlias($abstract); | ||
} | ||
|
||
/** | ||
|
@@ -160,7 +162,8 @@ public function resolved($abstract) | |
$abstract = $this->getAlias($abstract); | ||
} | ||
|
||
return isset($this->resolved[$abstract]) || isset($this->instances[$abstract]); | ||
return isset($this->resolved[$abstract]) || | ||
isset($this->instances[$abstract]); | ||
} | ||
|
||
/** | ||
|
@@ -188,15 +191,6 @@ public function bind($abstract, $concrete = null, $shared = false) | |
|
||
$concrete = $this->normalize($concrete); | ||
|
||
// If the given types are actually an array, we will assume an alias is being | ||
// defined and will grab this "real" abstract class name and register this | ||
// alias with the container so that it can be used as a shortcut for it. | ||
if (is_array($abstract)) { | ||
list($abstract, $alias) = $this->extractAlias($abstract); | ||
|
||
$this->alias($abstract, $alias); | ||
} | ||
|
||
// If no concrete type was given, we will simply set the concrete type to the | ||
// abstract type. After that, the concrete type to be registered as shared | ||
// without being forced to state their classes in both of the parameters. | ||
|
@@ -291,28 +285,6 @@ public function singleton($abstract, $concrete = null) | |
$this->bind($abstract, $concrete, true); | ||
} | ||
|
||
/** | ||
* Wrap a Closure such that it is shared. | ||
* | ||
* @param \Closure $closure | ||
* @return \Closure | ||
*/ | ||
public function share(Closure $closure) | ||
{ | ||
return function ($container) use ($closure) { | ||
// We'll simply declare a static variable within the Closures and if it has | ||
// not been set we will execute the given Closures to resolve this value | ||
// and return it back to these consumers of the method as an instance. | ||
static $object; | ||
|
||
if (is_null($object)) { | ||
$object = $closure($container); | ||
} | ||
|
||
return $object; | ||
}; | ||
} | ||
|
||
/** | ||
* "Extend" an abstract type in the container. | ||
* | ||
|
@@ -344,27 +316,14 @@ public function extend($abstract, Closure $closure) | |
*/ | ||
public function instance($abstract, $instance) | ||
{ | ||
$abstract = $this->normalize($abstract); | ||
|
||
// First, we will extract the alias from the abstract if it is an array so we | ||
// are using the correct name when binding the type. If we get an alias it | ||
// will be registered with the container so we can resolve it out later. | ||
if (is_array($abstract)) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
GrahamCampbell
Member
|
||
list($abstract, $alias) = $this->extractAlias($abstract); | ||
|
||
$this->alias($abstract, $alias); | ||
} | ||
|
||
unset($this->aliases[$abstract]); | ||
unset($this->aliases[$abstract = $this->normalize($abstract)]); | ||
|
||
// We'll check to determine if this type has been bound before, and if it has | ||
// we will fire the rebound callbacks registered with the container and it | ||
// can be updated with consuming classes that have gotten resolved here. | ||
$bound = $this->bound($abstract); | ||
|
||
$this->instances[$abstract] = $instance; | ||
|
||
if ($bound) { | ||
if ($this->bound($abstract)) { | ||
$this->rebound($abstract); | ||
} | ||
} | ||
|
@@ -422,17 +381,6 @@ public function alias($abstract, $alias) | |
$this->aliases[$alias] = $this->normalize($abstract); | ||
} | ||
|
||
/** | ||
* Extract the type and alias from a given definition. | ||
* | ||
* @param array $definition | ||
* @return array | ||
*/ | ||
protected function extractAlias(array $definition) | ||
{ | ||
return [key($definition), current($definition)]; | ||
} | ||
|
||
/** | ||
* Bind a new callback to an abstract's rebind event. | ||
* | ||
|
@taylorotwell The users like me who are using $abstract argument as an array, going to start to get an error? What is the reason of deleting this statement? Btw, I am going to update my service providers if it is deprecated.