40 preg_match(
"/\\\\([\w]+)Command$/", get_class($this->command), $matches);
41 return isset($matches[1]) ? lcfirst($matches[1]).
'()' :
'Method';
50 public function value($default =
null)
52 $arguments = $this->command->arguments;
54 if (is_array($arguments)) {
55 return isset($arguments[$this->key]) ? $arguments[
$this->key] : $default;
68 if ( ! array_key_exists($this->key, $this->command->arguments)) {
69 throw new \Intervention\Image\Exception\InvalidArgumentException(
70 sprintf(
"Missing argument %d for %s", $this->key + 1, $this->
getCommandName())
82 public function type($type)
86 $value = $this->
value();
88 if (is_null($value)) {
92 switch (strtolower($type)) {
96 $fail = ! is_bool($value);
97 $message = sprintf(
'%s accepts only boolean values as argument %d.', $this->
getCommandName(), $this->key + 1);
102 $fail = ! is_integer($value);
103 $message = sprintf(
'%s accepts only integer values as argument %d.', $this->
getCommandName(), $this->key + 1);
108 $fail = ! is_numeric($value);
109 $message = sprintf(
'%s accepts only numeric values as argument %d.', $this->
getCommandName(), $this->key + 1);
114 $fail = ! is_string($value);
115 $message = sprintf(
'%s accepts only string values as argument %d.', $this->
getCommandName(), $this->key + 1);
119 $fail = ! is_array($value);
120 $message = sprintf(
'%s accepts only array as argument %d.', $this->
getCommandName(), $this->key + 1);
124 $fail = ! is_a($value,
'\Closure');
125 $message = sprintf(
'%s accepts only Closure as argument %d.', $this->
getCommandName(), $this->key + 1);
129 $fail = ! $this->isDigit($value);
130 $message = sprintf(
'%s accepts only integer values as argument %d.', $this->
getCommandName(), $this->key + 1);
136 $message = isset($message) ? $message : sprintf(
"Missing argument for %d.", $this->key);
138 throw new \Intervention\Image\Exception\InvalidArgumentException(
153 $value = $this->
type(
'numeric')->value();
155 if (is_null($value)) {
159 $alpha =
min($x, $y);
160 $omega =
max($x, $y);
162 if ($value < $alpha || $value > $omega) {
163 throw new \Intervention\Image\Exception\InvalidArgumentException(
164 sprintf(
'Argument %d must be between %s and %s.', $this->key, $x, $y)
176 public function min($value)
178 $v = $this->
type(
'numeric')->value();
185 throw new \Intervention\Image\Exception\InvalidArgumentException(
186 sprintf(
'Argument %d must be at least %s.', $this->key, $value)
198 public function max($value)
200 $v = $this->
type(
'numeric')->value();
207 throw new \Intervention\Image\Exception\InvalidArgumentException(
208 sprintf(
'Argument %d may not be greater than %s.', $this->key, $value)
221 private function isDigit($value)
223 return is_numeric($value) ? intval($value) == $value :
false;