mirror of
https://github.com/Intervention/image.git
synced 2025-08-18 19:51:22 +02:00
@@ -81,59 +81,57 @@ class Argument
|
|||||||
*/
|
*/
|
||||||
public function type($type)
|
public function type($type)
|
||||||
{
|
{
|
||||||
$fail = false;
|
$valid = true;
|
||||||
|
|
||||||
$value = $this->value();
|
$value = $this->value();
|
||||||
|
|
||||||
if (is_null($value)) {
|
if ($value === null) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (strtolower($type)) {
|
switch (strtolower($type)) {
|
||||||
|
|
||||||
case 'bool':
|
case 'bool':
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
$fail = ! is_bool($value);
|
$valid = \is_bool($value);
|
||||||
$message = sprintf('%s accepts only boolean values as argument %d.', $this->getCommandName(), $this->key + 1);
|
$message = '%s accepts only boolean values as argument %d.';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'int':
|
case 'int':
|
||||||
case 'integer':
|
case 'integer':
|
||||||
$fail = ! is_integer($value);
|
$valid = \is_int($value);
|
||||||
$message = sprintf('%s accepts only integer values as argument %d.', $this->getCommandName(), $this->key + 1);
|
$message = '%s accepts only integer values as argument %d.';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'num':
|
case 'num':
|
||||||
case 'numeric':
|
case 'numeric':
|
||||||
$fail = ! is_numeric($value);
|
$valid = is_numeric($value);
|
||||||
$message = sprintf('%s accepts only numeric values as argument %d.', $this->getCommandName(), $this->key + 1);
|
$message = '%s accepts only numeric values as argument %d.';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'str':
|
case 'str':
|
||||||
case 'string':
|
case 'string':
|
||||||
$fail = ! is_string($value);
|
$valid = \is_string($value);
|
||||||
$message = sprintf('%s accepts only string values as argument %d.', $this->getCommandName(), $this->key + 1);
|
$message = '%s accepts only string values as argument %d.';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'array':
|
case 'array':
|
||||||
$fail = ! is_array($value);
|
$valid = \is_array($value);
|
||||||
$message = sprintf('%s accepts only array as argument %d.', $this->getCommandName(), $this->key + 1);
|
$message = '%s accepts only array as argument %d.';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'closure':
|
case 'closure':
|
||||||
$fail = ! is_a($value, '\Closure');
|
$valid = is_a($value, '\Closure');
|
||||||
$message = sprintf('%s accepts only Closure as argument %d.', $this->getCommandName(), $this->key + 1);
|
$message = '%s accepts only Closure as argument %d.';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'digit':
|
case 'digit':
|
||||||
$fail = ! $this->isDigit($value);
|
$valid = $this->isDigit($value);
|
||||||
$message = sprintf('%s accepts only integer values as argument %d.', $this->getCommandName(), $this->key + 1);
|
$message = '%s accepts only integer values as argument %d.';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fail) {
|
if (! $valid) {
|
||||||
|
$commandName = $this->getCommandName();
|
||||||
|
$argument = $this->key + 1;
|
||||||
|
|
||||||
$message = isset($message) ? $message : sprintf("Missing argument for %d.", $this->key);
|
if (isset($message)) {
|
||||||
|
$message = sprintf($message, $commandName, $argument);
|
||||||
|
} else {
|
||||||
|
$message = sprintf('Missing argument for %d.', $argument);
|
||||||
|
}
|
||||||
|
|
||||||
throw new \Intervention\Image\Exception\InvalidArgumentException(
|
throw new \Intervention\Image\Exception\InvalidArgumentException(
|
||||||
$message
|
$message
|
||||||
|
Reference in New Issue
Block a user