fractalzombie /
frzb-dependency-injection
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /** |
||
| 6 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
| 7 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
| 8 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||
| 9 | * |
||
| 10 | * Copyright (c) 2024 Mykhailo Shtanko [email protected] |
||
| 11 | * |
||
| 12 | * For the full copyright and license information, please view the LICENSE.MD |
||
| 13 | * file that was distributed with this source code. |
||
| 14 | */ |
||
| 15 | |||
| 16 | namespace FRZB\Component\DependencyInjection\Exception; |
||
| 17 | |||
| 18 | use FRZB\Component\DependencyInjection\Attribute\AsAlias; |
||
| 19 | use FRZB\Component\DependencyInjection\Attribute\AsService; |
||
| 20 | use JetBrains\PhpStorm\Immutable; |
||
| 21 | |||
| 22 | #[Immutable] |
||
| 23 | final class AttributeException extends \LogicException |
||
| 24 | { |
||
| 25 | private function __construct(string $message, ?\Throwable $previous = null) |
||
| 26 | { |
||
| 27 | parent::__construct($message, (int) $previous?->getCode(), $previous); |
||
| 28 | } |
||
| 29 | |||
| 30 | public static function unexpected(AsAlias|AsService $attribute, ?\Throwable $previous = null): self |
||
| 31 | { |
||
| 32 | $message = $previous |
||
| 33 | ? sprintf('"%s" attribute has unexpected exception: %s', $attribute::class, $previous?->getMessage()) |
||
| 34 | : sprintf('"%s" attribute has unexpected exception', $attribute::class); |
||
| 35 | |||
| 36 | return new self($message, $previous); |
||
| 37 | } |
||
| 38 | |||
| 39 | public static function invalidImplementation(AsAlias|AsService $attribute, \ReflectionClass $aliasClass, ?\Throwable $previous = null): self |
||
| 40 | { |
||
| 41 | $message = sprintf('Class "%s" must implement or be subclass of "%s"', $attribute->service, $aliasClass->getName()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 42 | |||
| 43 | return new self($message, $previous); |
||
| 44 | } |
||
| 45 | |||
| 46 | public static function noDefinitionInContainer(AsAlias|AsService $attribute, ?\Throwable $previous = null): self |
||
| 47 | { |
||
| 48 | $message = sprintf('There is no definition "%s" in container', $attribute->service); |
||
|
0 ignored issues
–
show
|
|||
| 49 | |||
| 50 | return new self($message, $previous); |
||
| 51 | } |
||
| 52 | |||
| 53 | public static function mustBeOfType(string $type, object $attribute, ?\Throwable $previous = null): self |
||
| 54 | { |
||
| 55 | $message = sprintf('Tags must be of type "%s" given "%s"', $type, $attribute::class); |
||
| 56 | |||
| 57 | return new self($message, $previous); |
||
| 58 | } |
||
| 59 | } |
||
| 60 |