diff options
Diffstat (limited to 'vendor/php-http/discovery/src/Exception')
6 files changed, 155 insertions, 0 deletions
diff --git a/vendor/php-http/discovery/src/Exception/ClassInstantiationFailedException.php b/vendor/php-http/discovery/src/Exception/ClassInstantiationFailedException.php new file mode 100644 index 000000000..e95bf5d82 --- /dev/null +++ b/vendor/php-http/discovery/src/Exception/ClassInstantiationFailedException.php @@ -0,0 +1,14 @@ +<?php + +namespace Http\Discovery\Exception; + +use Http\Discovery\Exception; + +/** + * Thrown when a class fails to instantiate. + * + * @author Tobias Nyholm <[email protected]> + */ +final class ClassInstantiationFailedException extends \RuntimeException implements Exception +{ +} diff --git a/vendor/php-http/discovery/src/Exception/DiscoveryFailedException.php b/vendor/php-http/discovery/src/Exception/DiscoveryFailedException.php new file mode 100644 index 000000000..304b7276e --- /dev/null +++ b/vendor/php-http/discovery/src/Exception/DiscoveryFailedException.php @@ -0,0 +1,51 @@ +<?php + +namespace Http\Discovery\Exception; + +use Http\Discovery\Exception; + +/** + * Thrown when all discovery strategies fails to find a resource. + * + * @author Tobias Nyholm <[email protected]> + */ +final class DiscoveryFailedException extends \Exception implements Exception +{ + /** + * @var \Exception[] + */ + private $exceptions; + + /** + * @param string $message + * @param \Exception[] $exceptions + */ + public function __construct($message, array $exceptions = []) + { + $this->exceptions = $exceptions; + + parent::__construct($message); + } + + /** + * @param \Exception[] $exceptions + */ + public static function create($exceptions) + { + $message = 'Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors'; + foreach ($exceptions as $e) { + $message .= "\n - ".$e->getMessage(); + } + $message .= "\n\n"; + + return new self($message, $exceptions); + } + + /** + * @return \Exception[] + */ + public function getExceptions() + { + return $this->exceptions; + } +} diff --git a/vendor/php-http/discovery/src/Exception/NoCandidateFoundException.php b/vendor/php-http/discovery/src/Exception/NoCandidateFoundException.php new file mode 100644 index 000000000..32f65db7b --- /dev/null +++ b/vendor/php-http/discovery/src/Exception/NoCandidateFoundException.php @@ -0,0 +1,47 @@ +<?php + +namespace Http\Discovery\Exception; + +use Http\Discovery\Exception; + +/** + * When we have used a strategy but no candidates provided by that strategy could be used. + * + * @author Tobias Nyholm <[email protected]> + */ +final class NoCandidateFoundException extends \Exception implements Exception +{ + /** + * @param string $strategy + */ + public function __construct($strategy, array $candidates) + { + $classes = array_map( + function ($a) { + return $a['class']; + }, + $candidates + ); + + $message = sprintf( + 'No valid candidate found using strategy "%s". We tested the following candidates: %s.', + $strategy, + implode(', ', array_map([$this, 'stringify'], $classes)) + ); + + parent::__construct($message); + } + + private function stringify($mixed) + { + if (is_string($mixed)) { + return $mixed; + } + + if (is_array($mixed) && 2 === count($mixed)) { + return sprintf('%s::%s', $this->stringify($mixed[0]), $mixed[1]); + } + + return is_object($mixed) ? get_class($mixed) : gettype($mixed); + } +} diff --git a/vendor/php-http/discovery/src/Exception/NotFoundException.php b/vendor/php-http/discovery/src/Exception/NotFoundException.php new file mode 100644 index 000000000..ef8b9c584 --- /dev/null +++ b/vendor/php-http/discovery/src/Exception/NotFoundException.php @@ -0,0 +1,16 @@ +<?php + +namespace Http\Discovery\Exception; + +use Http\Discovery\Exception; + +/** + * Thrown when a discovery does not find any matches. + * + * @final do NOT extend this class, not final for BC reasons + * + * @author Márk Sági-Kazár <[email protected]> + */ +/* final */ class NotFoundException extends \RuntimeException implements Exception +{ +} diff --git a/vendor/php-http/discovery/src/Exception/PuliUnavailableException.php b/vendor/php-http/discovery/src/Exception/PuliUnavailableException.php new file mode 100644 index 000000000..a6ade7332 --- /dev/null +++ b/vendor/php-http/discovery/src/Exception/PuliUnavailableException.php @@ -0,0 +1,12 @@ +<?php + +namespace Http\Discovery\Exception; + +/** + * Thrown when we can't use Puli for discovery. + * + * @author Tobias Nyholm <[email protected]> + */ +final class PuliUnavailableException extends StrategyUnavailableException +{ +} diff --git a/vendor/php-http/discovery/src/Exception/StrategyUnavailableException.php b/vendor/php-http/discovery/src/Exception/StrategyUnavailableException.php new file mode 100644 index 000000000..89ecf3523 --- /dev/null +++ b/vendor/php-http/discovery/src/Exception/StrategyUnavailableException.php @@ -0,0 +1,15 @@ +<?php + +namespace Http\Discovery\Exception; + +use Http\Discovery\Exception; + +/** + * This exception is thrown when we cannot use a discovery strategy. This is *not* thrown when + * the discovery fails to find a class. + * + * @author Tobias Nyholm <[email protected]> + */ +class StrategyUnavailableException extends \RuntimeException implements Exception +{ +} |