Skip to content

Commit

Permalink
also consider alias in Container::has()
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Jun 12, 2013
1 parent 8d29c64 commit aa79393
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Expand Up @@ -88,6 +88,7 @@ public function __construct(ParameterBagInterface $parameterBag = null)
$this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;

$this->services = array();
$this->aliases = array();
$this->scopes = array();
$this->scopeChildren = array();
$this->scopedServices = array();
Expand Down Expand Up @@ -228,7 +229,10 @@ public function has($id)
{
$id = strtolower($id);

return array_key_exists($id, $this->services) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
return array_key_exists($id, $this->services)
|| array_key_exists($id, $this->aliases)
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')
;
}

/**
Expand Down
Expand Up @@ -477,6 +477,14 @@ protected function getField($obj, $field)

return $reflection->getValue($obj);
}

public function testAlias()
{
$c = new ProjectServiceContainer();

$this->assertTrue($c->has('alias'));
$this->assertSame($c->get('alias'), $c->get('bar'));
}
}

class ProjectServiceContainer extends Container
Expand All @@ -490,6 +498,7 @@ public function __construct()
$this->__bar = new \stdClass();
$this->__foo_bar = new \stdClass();
$this->__foo_baz = new \stdClass();
$this->aliases = array('alias' => 'bar');
}

protected function getScopedService()
Expand Down

0 comments on commit aa79393

Please sign in to comment.