first commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace WordPress\AiClientDependencies\Http\Discovery\Exception;
|
||||
|
||||
use WordPress\AiClientDependencies\Http\Discovery\Exception;
|
||||
/**
|
||||
* Thrown when a class fails to instantiate.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
final class ClassInstantiationFailedException extends \RuntimeException implements Exception
|
||||
{
|
||||
}
|
||||
45
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/DiscoveryFailedException.php
vendored
Normal file
45
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/DiscoveryFailedException.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace WordPress\AiClientDependencies\Http\Discovery\Exception;
|
||||
|
||||
use WordPress\AiClientDependencies\Http\Discovery\Exception;
|
||||
/**
|
||||
* Thrown when all discovery strategies fails to find a resource.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
34
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/NoCandidateFoundException.php
vendored
Normal file
34
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/NoCandidateFoundException.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace WordPress\AiClientDependencies\Http\Discovery\Exception;
|
||||
|
||||
use WordPress\AiClientDependencies\Http\Discovery\Exception;
|
||||
/**
|
||||
* When we have used a strategy but no candidates provided by that strategy could be used.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
16
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/NotFoundException.php
vendored
Normal file
16
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/NotFoundException.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace WordPress\AiClientDependencies\Http\Discovery\Exception;
|
||||
|
||||
use WordPress\AiClientDependencies\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 <mark.sagikazar@gmail.com>
|
||||
*/
|
||||
/* final */
|
||||
class NotFoundException extends \RuntimeException implements Exception
|
||||
{
|
||||
}
|
||||
12
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/PuliUnavailableException.php
vendored
Normal file
12
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/PuliUnavailableException.php
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace WordPress\AiClientDependencies\Http\Discovery\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when we can't use Puli for discovery.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
final class PuliUnavailableException extends StrategyUnavailableException
|
||||
{
|
||||
}
|
||||
14
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/StrategyUnavailableException.php
vendored
Normal file
14
wp-includes/php-ai-client/third-party/Http/Discovery/Exception/StrategyUnavailableException.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace WordPress\AiClientDependencies\Http\Discovery\Exception;
|
||||
|
||||
use WordPress\AiClientDependencies\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 <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class StrategyUnavailableException extends \RuntimeException implements Exception
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user