-
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
11 changed files
with
273 additions
and
25 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 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
57 changes: 57 additions & 0 deletions
57
src/Container/Exceptions/CannotResolveTaggedDependency.php
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,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Container\Exceptions; | ||
|
||
use Exception; | ||
use Tempest\Container\Dependency; | ||
use Tempest\Container\DependencyChain; | ||
|
||
final class CannotResolveTaggedDependency extends Exception | ||
{ | ||
public function __construct(DependencyChain $chain, Dependency $brokenDependency, string $tag) | ||
{ | ||
$stack = $chain->all(); | ||
$stack[] = $brokenDependency; | ||
|
||
$message = PHP_EOL . PHP_EOL. "Could not resolve tagged dependency {$brokenDependency->getName()}#{$tag}, did you forget to define an initializer for it?" . PHP_EOL; | ||
|
||
if (count($stack) < 2) { | ||
parent::__construct($message); | ||
|
||
return; | ||
} | ||
|
||
$i = 0; | ||
|
||
foreach ($stack as $currentDependency) { | ||
$pipe = match ($i) { | ||
0 => '┌──', | ||
count($stack) - 1 => '└──', | ||
default => '├──', | ||
}; | ||
|
||
$message .= PHP_EOL . "\t{$pipe} " . $currentDependency->getShortName(); | ||
|
||
$i++; | ||
} | ||
|
||
$selectionLine = preg_replace_callback( | ||
pattern: '/(?<prefix>(.*))(?<selection>'. $brokenDependency->getTypeName() .'\s\$\w+)(.*)/', | ||
callback: function ($matches) { | ||
return str_repeat(' ', strlen($matches['prefix']) + 4) | ||
. str_repeat('▒', strlen($matches['selection'])); | ||
}, | ||
subject: $chain->last()->getShortName(), | ||
); | ||
|
||
$message .= PHP_EOL; | ||
$message .= "\t{$selectionLine}"; | ||
$message .= PHP_EOL; | ||
$message .= "Originally called in {$chain->getOrigin()}"; | ||
$message .= PHP_EOL; | ||
|
||
parent::__construct($message); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Container; | ||
|
||
use Attribute; | ||
|
||
#[Attribute] | ||
final readonly class Tag | ||
{ | ||
public function __construct(public string $name) | ||
{ | ||
} | ||
} |
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.