diff options
author | Andrew Dolgov <[email protected]> | 2022-03-22 12:24:31 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2022-03-22 12:24:31 +0300 |
commit | 1c4f7ab3b838b23afb2ee4dab14acbf75956e952 (patch) | |
tree | 0a19274107d717efe92d2c0376cd3105fead5a11 /vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception | |
parent | 711662948768492e8d05b778a7d80eacaec368d2 (diff) |
* add phpunit as a dev dependency
* add some basic tests for UrlHelper::rewrite_relative()
* fix UrlHelper::rewrite_relative() to work better on non-absolute
relative URL paths
Diffstat (limited to 'vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception')
3 files changed, 121 insertions, 0 deletions
diff --git a/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/ExceptionInterface.php b/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/ExceptionInterface.php new file mode 100644 index 000000000..e6a5195f2 --- /dev/null +++ b/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/ExceptionInterface.php @@ -0,0 +1,12 @@ +<?php + +namespace Doctrine\Instantiator\Exception; + +use Throwable; + +/** + * Base exception marker interface for the instantiator component + */ +interface ExceptionInterface extends Throwable +{ +} diff --git a/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php b/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php new file mode 100644 index 000000000..33de31c0b --- /dev/null +++ b/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php @@ -0,0 +1,50 @@ +<?php + +namespace Doctrine\Instantiator\Exception; + +use InvalidArgumentException as BaseInvalidArgumentException; +use ReflectionClass; + +use function interface_exists; +use function sprintf; +use function trait_exists; + +/** + * Exception for invalid arguments provided to the instantiator + */ +class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface +{ + public static function fromNonExistingClass(string $className): self + { + if (interface_exists($className)) { + return new self(sprintf('The provided type "%s" is an interface, and cannot be instantiated', $className)); + } + + if (trait_exists($className)) { + return new self(sprintf('The provided type "%s" is a trait, and cannot be instantiated', $className)); + } + + return new self(sprintf('The provided class "%s" does not exist', $className)); + } + + /** + * @phpstan-param ReflectionClass<T> $reflectionClass + * + * @template T of object + */ + public static function fromAbstractClass(ReflectionClass $reflectionClass): self + { + return new self(sprintf( + 'The provided class "%s" is abstract, and cannot be instantiated', + $reflectionClass->getName() + )); + } + + public static function fromEnum(string $className): self + { + return new self(sprintf( + 'The provided class "%s" is an enum, and cannot be instantiated', + $className + )); + } +} diff --git a/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/UnexpectedValueException.php b/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/UnexpectedValueException.php new file mode 100644 index 000000000..4e55ac525 --- /dev/null +++ b/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/UnexpectedValueException.php @@ -0,0 +1,59 @@ +<?php + +namespace Doctrine\Instantiator\Exception; + +use Exception; +use ReflectionClass; +use UnexpectedValueException as BaseUnexpectedValueException; + +use function sprintf; + +/** + * Exception for given parameters causing invalid/unexpected state on instantiation + */ +class UnexpectedValueException extends BaseUnexpectedValueException implements ExceptionInterface +{ + /** + * @phpstan-param ReflectionClass<T> $reflectionClass + * + * @template T of object + */ + public static function fromSerializationTriggeredException( + ReflectionClass $reflectionClass, + Exception $exception + ): self { + return new self( + sprintf( + 'An exception was raised while trying to instantiate an instance of "%s" via un-serialization', + $reflectionClass->getName() + ), + 0, + $exception + ); + } + + /** + * @phpstan-param ReflectionClass<T> $reflectionClass + * + * @template T of object + */ + public static function fromUncleanUnSerialization( + ReflectionClass $reflectionClass, + string $errorString, + int $errorCode, + string $errorFile, + int $errorLine + ): self { + return new self( + sprintf( + 'Could not produce an instance of "%s" via un-serialization, since an error was triggered ' + . 'in file "%s" at line "%d"', + $reflectionClass->getName(), + $errorFile, + $errorLine + ), + 0, + new Exception($errorString, $errorCode) + ); + } +} |