Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,15 @@ public function tagged($tag)
* @param string $abstract
* @param string $alias
* @return void
*
* @throws \LogicException
*/
public function alias($abstract, $alias)
{
if ($alias === $abstract) {
throw new LogicException("[{$abstract}] is aliased to itself.");
}

$this->aliases[$alias] = $abstract;

$this->abstractAliases[$abstract][] = $alias;
Expand Down Expand Up @@ -1095,19 +1101,13 @@ public function getBindings()
*
* @param string $abstract
* @return string
*
* @throws \LogicException
*/
public function getAlias($abstract)
{
if (! isset($this->aliases[$abstract])) {
return $abstract;
}

if ($this->aliases[$abstract] === $abstract) {
throw new LogicException("[{$abstract}] is aliased to itself.");
}

return $this->getAlias($this->aliases[$abstract]);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Contracts/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function bound($abstract);
* @param string $abstract
* @param string $alias
* @return void
*
* @throws \LogicException
*/
public function alias($abstract, $alias);

Expand Down
6 changes: 2 additions & 4 deletions tests/Container/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,11 @@ public function testGetAlias()

public function testItThrowsExceptionWhenAbstractIsSameAsAlias()
{
$container = new Container;
$container->alias('name', 'name');

$this->expectException('LogicException');
$this->expectExceptionMessage('[name] is aliased to itself.');

$container->getAlias('name');
$container = new Container;
$container->alias('name', 'name');
}

public function testContainerGetFactory()
Expand Down