|
@@ -183,14 +183,26 @@ class Container implements ContainerInterface
|
|
*/
|
|
*/
|
|
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
|
|
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
|
|
{
|
|
{
|
|
|
|
+ static $loading = array();
|
|
|
|
+
|
|
$id = strtolower($id);
|
|
$id = strtolower($id);
|
|
|
|
|
|
if (isset($this->services[$id])) {
|
|
if (isset($this->services[$id])) {
|
|
return $this->services[$id];
|
|
return $this->services[$id];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (isset($loading[$id])) {
|
|
|
|
+ throw new \LogicException(sprintf('Circular reference detected for service "%s" (services currently loading: %s).', $id, implode(', ', array_keys($loading))));
|
|
|
|
+ }
|
|
|
|
+
|
|
if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
|
|
if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
|
|
- return $this->$method();
|
|
|
|
|
|
+ $loading[$id] = true;
|
|
|
|
+
|
|
|
|
+ $service = $this->$method();
|
|
|
|
+
|
|
|
|
+ unset($loading[$id]);
|
|
|
|
+
|
|
|
|
+ return $service;
|
|
}
|
|
}
|
|
|
|
|
|
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
|
|
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
|