-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
341 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Container; | ||
|
||
use Closure; | ||
use ReflectionType; | ||
use Reflector; | ||
use Tempest\Container\Exceptions\CircularDependencyException; | ||
|
||
final class DependencyChain | ||
{ | ||
/** | ||
* @var \Tempest\Container\Dependency[] | ||
*/ | ||
private array $dependencies = []; | ||
|
||
public function __construct(private string $origin) | ||
{ | ||
} | ||
|
||
public function add(Reflector|ReflectionType|Closure|string $dependency): self | ||
{ | ||
$dependency = new Dependency($dependency); | ||
|
||
if (isset($this->dependencies[$dependency->getName()])) { | ||
throw new CircularDependencyException($this, $dependency); | ||
} | ||
|
||
$this->dependencies[$dependency->getName()] = $dependency; | ||
|
||
return $this; | ||
} | ||
|
||
public function first(): Dependency | ||
{ | ||
return $this->dependencies[array_key_first($this->dependencies)]; | ||
} | ||
|
||
public function last(): Dependency | ||
{ | ||
return $this->dependencies[array_key_last($this->dependencies)]; | ||
} | ||
|
||
/** @return \Tempest\Container\Dependency[] */ | ||
public function all(): array | ||
{ | ||
return $this->dependencies; | ||
} | ||
|
||
public function getOrigin(): string | ||
{ | ||
return $this->origin; | ||
} | ||
|
||
public function clone(): self | ||
{ | ||
return clone $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.