First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
57
vendor/consolidation/output-formatters/src/Exception/AbstractDataFormatException.php
vendored
Normal file
57
vendor/consolidation/output-formatters/src/Exception/AbstractDataFormatException.php
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
namespace Consolidation\OutputFormatters\Exception;
|
||||
|
||||
/**
|
||||
* Contains some helper functions used by exceptions in this project.
|
||||
*/
|
||||
abstract class AbstractDataFormatException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Return a description of the data type represented by the provided parameter.
|
||||
*
|
||||
* @param \ReflectionClass $data The data type to describe. Note that
|
||||
* \ArrayObject is used as a proxy to mean an array primitive (or an ArrayObject).
|
||||
* @return string
|
||||
*/
|
||||
protected static function describeDataType($data)
|
||||
{
|
||||
if (is_array($data) || ($data instanceof \ReflectionClass)) {
|
||||
if (is_array($data) || ($data->getName() == 'ArrayObject')) {
|
||||
return 'an array';
|
||||
}
|
||||
return 'an instance of ' . $data->getName();
|
||||
}
|
||||
if (is_string($data)) {
|
||||
return 'a string';
|
||||
}
|
||||
if (is_object($data)) {
|
||||
return 'an instance of ' . get_class($data);
|
||||
}
|
||||
throw new \Exception("Undescribable data error: " . var_export($data, true));
|
||||
}
|
||||
|
||||
protected static function describeAllowedTypes($allowedTypes)
|
||||
{
|
||||
if (is_array($allowedTypes) && !empty($allowedTypes)) {
|
||||
if (count($allowedTypes) > 1) {
|
||||
return static::describeListOfAllowedTypes($allowedTypes);
|
||||
}
|
||||
$allowedTypes = $allowedTypes[0];
|
||||
}
|
||||
return static::describeDataType($allowedTypes);
|
||||
}
|
||||
|
||||
protected static function describeListOfAllowedTypes($allowedTypes)
|
||||
{
|
||||
$descriptions = [];
|
||||
foreach ($allowedTypes as $oneAllowedType) {
|
||||
$descriptions[] = static::describeDataType($oneAllowedType);
|
||||
}
|
||||
if (count($descriptions) == 2) {
|
||||
return "either {$descriptions[0]} or {$descriptions[1]}";
|
||||
}
|
||||
$lastDescription = array_pop($descriptions);
|
||||
$otherDescriptions = implode(', ', $descriptions);
|
||||
return "one of $otherDescriptions or $lastDescription";
|
||||
}
|
||||
}
|
19
vendor/consolidation/output-formatters/src/Exception/IncompatibleDataException.php
vendored
Normal file
19
vendor/consolidation/output-formatters/src/Exception/IncompatibleDataException.php
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
namespace Consolidation\OutputFormatters\Exception;
|
||||
|
||||
use Consolidation\OutputFormatters\Formatters\FormatterInterface;
|
||||
|
||||
/**
|
||||
* Represents an incompatibility between the output data and selected formatter.
|
||||
*/
|
||||
class IncompatibleDataException extends AbstractDataFormatException
|
||||
{
|
||||
public function __construct(FormatterInterface $formatter, $data, $allowedTypes)
|
||||
{
|
||||
$formatterDescription = get_class($formatter);
|
||||
$dataDescription = static::describeDataType($data);
|
||||
$allowedTypesDescription = static::describeAllowedTypes($allowedTypes);
|
||||
$message = "Data provided to $formatterDescription must be $allowedTypesDescription. Instead, $dataDescription was provided.";
|
||||
parent::__construct($message, 1);
|
||||
}
|
||||
}
|
15
vendor/consolidation/output-formatters/src/Exception/InvalidFormatException.php
vendored
Normal file
15
vendor/consolidation/output-formatters/src/Exception/InvalidFormatException.php
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
namespace Consolidation\OutputFormatters\Exception;
|
||||
|
||||
/**
|
||||
* Represents an incompatibility between the output data and selected formatter.
|
||||
*/
|
||||
class InvalidFormatException extends AbstractDataFormatException
|
||||
{
|
||||
public function __construct($format, $data, $validFormats)
|
||||
{
|
||||
$dataDescription = static::describeDataType($data);
|
||||
$message = "The format $format cannot be used with the data produced by this command, which was $dataDescription. Valid formats are: " . implode(',', $validFormats);
|
||||
parent::__construct($message, 1);
|
||||
}
|
||||
}
|
14
vendor/consolidation/output-formatters/src/Exception/UnknownFieldException.php
vendored
Normal file
14
vendor/consolidation/output-formatters/src/Exception/UnknownFieldException.php
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
namespace Consolidation\OutputFormatters\Exception;
|
||||
|
||||
/**
|
||||
* Indicates that the requested format does not exist.
|
||||
*/
|
||||
class UnknownFieldException extends \Exception
|
||||
{
|
||||
public function __construct($field)
|
||||
{
|
||||
$message = "The requested field, '$field', is not defined.";
|
||||
parent::__construct($message, 1);
|
||||
}
|
||||
}
|
14
vendor/consolidation/output-formatters/src/Exception/UnknownFormatException.php
vendored
Normal file
14
vendor/consolidation/output-formatters/src/Exception/UnknownFormatException.php
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
namespace Consolidation\OutputFormatters\Exception;
|
||||
|
||||
/**
|
||||
* Indicates that the requested format does not exist.
|
||||
*/
|
||||
class UnknownFormatException extends \Exception
|
||||
{
|
||||
public function __construct($format)
|
||||
{
|
||||
$message = "The requested format, '$format', is not available.";
|
||||
parent::__construct($message, 1);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue