diff --git a/src/Intervention/Image/Commands/AbstractCommand.php b/src/Intervention/Image/Commands/AbstractCommand.php index 4e9a00fd..c0d754ea 100644 --- a/src/Intervention/Image/Commands/AbstractCommand.php +++ b/src/Intervention/Image/Commands/AbstractCommand.php @@ -14,15 +14,9 @@ abstract class AbstractCommand $this->arguments = $arguments; } - public function getArgument($key, $default = null) + public function argument($key) { - // return new \Intervention\Image\Argument($this->arguments, $key); - - if (is_array($this->arguments)) { - return array_key_exists($key, $this->arguments) ? $this->arguments[$key] : $default; - } - - return $default; + return new \Intervention\Image\Commands\Argument($this, $key); } public function getOutput() diff --git a/src/Intervention/Image/Commands/Argument.php b/src/Intervention/Image/Commands/Argument.php index d1654de4..6ca144cf 100644 --- a/src/Intervention/Image/Commands/Argument.php +++ b/src/Intervention/Image/Commands/Argument.php @@ -51,6 +51,12 @@ class Argument switch (strtolower($type)) { + case 'bool': + case 'boolean': + $fail = ! is_bool($value); + $message = sprintf('%s accepts only boolean values as argument %d.', $this->getCommandName(), $this->key + 1); + break; + case 'int': case 'integer': $fail = ! is_integer($value); diff --git a/src/Intervention/Image/Commands/CircleCommand.php b/src/Intervention/Image/Commands/CircleCommand.php index 363dc824..9ae085b8 100644 --- a/src/Intervention/Image/Commands/CircleCommand.php +++ b/src/Intervention/Image/Commands/CircleCommand.php @@ -8,10 +8,10 @@ class CircleCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $x = $this->getArgument(0); - $y = $this->getArgument(1); - $radius = $this->getArgument(2); - $callback = $this->getArgument(3); + $x = $this->argument(0)->type('numeric')->required()->value(); + $y = $this->argument(1)->type('numeric')->required()->value(); + $radius = $this->argument(2)->type('numeric')->required()->value(); + $callback = $this->argument(3)->type('closure')->value(); $circle_classname = sprintf('\Intervention\Image\%s\Shapes\CircleShape', $image->getDriver()->getDriverName()); diff --git a/src/Intervention/Image/Commands/EllipseCommand.php b/src/Intervention/Image/Commands/EllipseCommand.php index 837968e0..85ef0eb5 100644 --- a/src/Intervention/Image/Commands/EllipseCommand.php +++ b/src/Intervention/Image/Commands/EllipseCommand.php @@ -8,11 +8,11 @@ class EllipseCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $x = $this->getArgument(0); - $y = $this->getArgument(1); - $width = $this->getArgument(2); - $height = $this->getArgument(3); - $callback = $this->getArgument(4); + $x = $this->argument(0)->type('numeric')->required()->value(); + $y = $this->argument(1)->type('numeric')->required()->value(); + $width = $this->argument(2)->type('numeric')->value(10); + $height = $this->argument(3)->type('numeric')->value(10); + $callback = $this->argument(4)->type('closure')->value(); $ellipse_classname = sprintf('\Intervention\Image\%s\Shapes\EllipseShape', $image->getDriver()->getDriverName()); diff --git a/src/Intervention/Image/Commands/ExifCommand.php b/src/Intervention/Image/Commands/ExifCommand.php index 9ce8e518..89e69b84 100644 --- a/src/Intervention/Image/Commands/ExifCommand.php +++ b/src/Intervention/Image/Commands/ExifCommand.php @@ -12,7 +12,7 @@ class ExifCommand extends AbstractCommand ); } - $key = $this->getArgument(0); + $key = $this->argument(0)->value(); $data = exif_read_data($image->dirname .'/'. $image->basename, 'EXIF', false); if (! is_null($key) && is_array($data)) { diff --git a/src/Intervention/Image/Commands/LineCommand.php b/src/Intervention/Image/Commands/LineCommand.php index 90eec2e3..2c427fdc 100644 --- a/src/Intervention/Image/Commands/LineCommand.php +++ b/src/Intervention/Image/Commands/LineCommand.php @@ -8,11 +8,11 @@ class LineCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $x1 = $this->getArgument(0); - $y1 = $this->getArgument(1); - $x2 = $this->getArgument(2); - $y2 = $this->getArgument(3); - $callback = $this->getArgument(4); + $x1 = $this->argument(0)->type('numeric')->required()->value(); + $y1 = $this->argument(1)->type('numeric')->required()->value(); + $x2 = $this->argument(2)->type('numeric')->required()->value(); + $y2 = $this->argument(3)->type('numeric')->required()->value(); + $callback = $this->argument(4)->type('closure')->value(); $line_classname = sprintf('\Intervention\Image\%s\Shapes\LineShape', $image->getDriver()->getDriverName()); diff --git a/src/Intervention/Image/Commands/RectangleCommand.php b/src/Intervention/Image/Commands/RectangleCommand.php index 19230a41..3d0a10d2 100644 --- a/src/Intervention/Image/Commands/RectangleCommand.php +++ b/src/Intervention/Image/Commands/RectangleCommand.php @@ -8,11 +8,11 @@ class RectangleCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $x1 = $this->getArgument(0); - $y1 = $this->getArgument(1); - $x2 = $this->getArgument(2); - $y2 = $this->getArgument(3); - $callback = $this->getArgument(4); + $x1 = $this->argument(0)->type('numeric')->required()->value(); + $y1 = $this->argument(1)->type('numeric')->required()->value(); + $x2 = $this->argument(2)->type('numeric')->required()->value(); + $y2 = $this->argument(3)->type('numeric')->required()->value(); + $callback = $this->argument(4)->type('closure')->value(); $rectangle_classname = sprintf('\Intervention\Image\%s\Shapes\RectangleShape', $image->getDriver()->getDriverName()); diff --git a/src/Intervention/Image/Commands/ResponseCommand.php b/src/Intervention/Image/Commands/ResponseCommand.php index ed457d0f..3c459f98 100644 --- a/src/Intervention/Image/Commands/ResponseCommand.php +++ b/src/Intervention/Image/Commands/ResponseCommand.php @@ -8,8 +8,8 @@ class ResponseCommand extends AbstractCommand { public function execute($image) { - $format = $this->getArgument(0); - $quality = $this->getArgument(1); + $format = $this->argument(0)->value(); + $quality = $this->argument(1)->between(0, 100)->value(); $response = new Response($image, $format, $quality); diff --git a/src/Intervention/Image/Commands/TextCommand.php b/src/Intervention/Image/Commands/TextCommand.php index 58070842..0980e793 100644 --- a/src/Intervention/Image/Commands/TextCommand.php +++ b/src/Intervention/Image/Commands/TextCommand.php @@ -8,10 +8,10 @@ class TextCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $text = $this->getArgument(0); - $x = $this->getArgument(1, 0); - $y = $this->getArgument(2, 0); - $callback = $this->getArgument(3); + $text = $this->argument(0)->required()->value(); + $x = $this->argument(1, 0)->type('numeric')->value(); + $y = $this->argument(2, 0)->type('numeric')->value(); + $callback = $this->argument(3)->type('closure')->value(); $fontclassname = sprintf('\Intervention\Image\%s\Font', $image->getDriver()->getDriverName()); diff --git a/src/Intervention/Image/Gd/Commands/BlurCommand.php b/src/Intervention/Image/Gd/Commands/BlurCommand.php index 83ed6338..c75a0b7b 100644 --- a/src/Intervention/Image/Gd/Commands/BlurCommand.php +++ b/src/Intervention/Image/Gd/Commands/BlurCommand.php @@ -6,7 +6,7 @@ class BlurCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $amount = $this->getArgument(0, 1); + $amount = $this->argument(0)->between(0, 100)->value(1); for ($i=0; $i < intval($amount); $i++) { imagefilter($image->getCore(), IMG_FILTER_GAUSSIAN_BLUR); diff --git a/src/Intervention/Image/Gd/Commands/BrightnessCommand.php b/src/Intervention/Image/Gd/Commands/BrightnessCommand.php index d41b4d05..2bb7abc2 100644 --- a/src/Intervention/Image/Gd/Commands/BrightnessCommand.php +++ b/src/Intervention/Image/Gd/Commands/BrightnessCommand.php @@ -6,7 +6,7 @@ class BrightnessCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $level = $this->getArgument(0); + $level = $this->argument(0)->between(-100, 100)->required()->value(); return imagefilter($image->getCore(), IMG_FILTER_BRIGHTNESS, ($level * 2.55)); } diff --git a/src/Intervention/Image/Gd/Commands/ColorizeCommand.php b/src/Intervention/Image/Gd/Commands/ColorizeCommand.php index 6beaaaee..233b21e5 100644 --- a/src/Intervention/Image/Gd/Commands/ColorizeCommand.php +++ b/src/Intervention/Image/Gd/Commands/ColorizeCommand.php @@ -6,9 +6,9 @@ class ColorizeCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $red = $this->getArgument(0); - $green = $this->getArgument(1); - $blue = $this->getArgument(2); + $red = $this->argument(0)->between(-100, 100)->required()->value(); + $green = $this->argument(1)->between(-100, 100)->required()->value(); + $blue = $this->argument(2)->between(-100, 100)->required()->value(); // normalize colorize levels $red = round($red * 2.55); diff --git a/src/Intervention/Image/Gd/Commands/ContrastCommand.php b/src/Intervention/Image/Gd/Commands/ContrastCommand.php index bcc4b41c..81083550 100644 --- a/src/Intervention/Image/Gd/Commands/ContrastCommand.php +++ b/src/Intervention/Image/Gd/Commands/ContrastCommand.php @@ -6,7 +6,7 @@ class ContrastCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $level = $this->getArgument(0); + $level = $this->argument(0)->between(-100, 100)->required()->value(); return imagefilter($image->getCore(), IMG_FILTER_CONTRAST, ($level * -1)); } diff --git a/src/Intervention/Image/Gd/Commands/CropCommand.php b/src/Intervention/Image/Gd/Commands/CropCommand.php index 0c2a87b9..8d03cb2e 100644 --- a/src/Intervention/Image/Gd/Commands/CropCommand.php +++ b/src/Intervention/Image/Gd/Commands/CropCommand.php @@ -9,10 +9,10 @@ class CropCommand extends ResizeCommand { public function execute($image) { - $width = $this->getArgument(0); - $height = $this->getArgument(1); - $x = $this->getArgument(2); - $y = $this->getArgument(3); + $width = $this->argument(0)->type('integer')->required()->value(); + $height = $this->argument(1)->type('integer')->required()->value(); + $x = $this->argument(2)->type('integer')->value(); + $y = $this->argument(3)->type('integer')->value(); if (is_null($width) || is_null($height)) { throw new \Intervention\Image\Exception\InvalidArgumentException( diff --git a/src/Intervention/Image/Gd/Commands/FillCommand.php b/src/Intervention/Image/Gd/Commands/FillCommand.php index b5d931a7..c02239c3 100644 --- a/src/Intervention/Image/Gd/Commands/FillCommand.php +++ b/src/Intervention/Image/Gd/Commands/FillCommand.php @@ -9,9 +9,9 @@ class FillCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $filling = $this->getArgument(0); - $x = $this->getArgument(1); - $y = $this->getArgument(2); + $filling = $this->argument(0)->value(); + $x = $this->argument(1)->type('integer')->value(); + $y = $this->argument(2)->type('integer')->value(); $width = $image->getWidth(); $height = $image->getHeight(); diff --git a/src/Intervention/Image/Gd/Commands/FitCommand.php b/src/Intervention/Image/Gd/Commands/FitCommand.php index b01fd073..fd4d4993 100644 --- a/src/Intervention/Image/Gd/Commands/FitCommand.php +++ b/src/Intervention/Image/Gd/Commands/FitCommand.php @@ -9,8 +9,8 @@ class FitCommand extends ResizeCommand { public function execute($image) { - $width = $this->getArgument(0); - $height = $this->getArgument(1, $width); + $width = $this->argument(0)->type('integer')->value(); + $height = $this->argument(1)->type('integer')->value($width); // calculate size $fitted = $image->getSize()->fit(new Size($width, $height)); diff --git a/src/Intervention/Image/Gd/Commands/FlipCommand.php b/src/Intervention/Image/Gd/Commands/FlipCommand.php index b7bec6b0..a1e1da84 100644 --- a/src/Intervention/Image/Gd/Commands/FlipCommand.php +++ b/src/Intervention/Image/Gd/Commands/FlipCommand.php @@ -6,7 +6,7 @@ class FlipCommand extends ResizeCommand { public function execute($image) { - $mode = strtolower($this->getArgument(0, 'h')); + $mode = $this->argument(0)->value('h'); $size = $image->getSize(); $dst = clone $size; diff --git a/src/Intervention/Image/Gd/Commands/GammaCommand.php b/src/Intervention/Image/Gd/Commands/GammaCommand.php index f4ab7230..d77ce4b2 100644 --- a/src/Intervention/Image/Gd/Commands/GammaCommand.php +++ b/src/Intervention/Image/Gd/Commands/GammaCommand.php @@ -6,7 +6,7 @@ class GammaCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $gamma = $this->getArgument(0); + $gamma = $this->argument(0)->type('numeric')->required()->value(); return imagegammacorrect($image->getCore(), 1, $gamma); } diff --git a/src/Intervention/Image/Gd/Commands/HeightenCommand.php b/src/Intervention/Image/Gd/Commands/HeightenCommand.php index f8ea9df5..4f3900ac 100644 --- a/src/Intervention/Image/Gd/Commands/HeightenCommand.php +++ b/src/Intervention/Image/Gd/Commands/HeightenCommand.php @@ -6,7 +6,7 @@ class HeightenCommand extends ResizeCommand { public function execute($image) { - $height = $this->getArgument(0); + $height = $this->argument(0)->type('integer')->required()->value(); $this->arguments[0] = null; $this->arguments[1] = $height; diff --git a/src/Intervention/Image/Gd/Commands/InsertCommand.php b/src/Intervention/Image/Gd/Commands/InsertCommand.php index e60b74db..7cbe1c08 100644 --- a/src/Intervention/Image/Gd/Commands/InsertCommand.php +++ b/src/Intervention/Image/Gd/Commands/InsertCommand.php @@ -6,10 +6,10 @@ class InsertCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $source = $this->getArgument(0); - $position = $this->getArgument(1); - $x = intval($this->getArgument(2)); - $y = intval($this->getArgument(3)); + $source = $this->argument(0)->value(); + $position = $this->argument(1)->type('string')->value(); + $x = $this->argument(2)->type('integer')->value(0); + $y = $this->argument(3)->type('integer')->value(0); // build watermark $watermark = $image->getDriver()->init($source); diff --git a/src/Intervention/Image/Gd/Commands/InterlaceCommand.php b/src/Intervention/Image/Gd/Commands/InterlaceCommand.php index fa90dc7b..e23bbeb1 100644 --- a/src/Intervention/Image/Gd/Commands/InterlaceCommand.php +++ b/src/Intervention/Image/Gd/Commands/InterlaceCommand.php @@ -6,7 +6,7 @@ class InterlaceCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $mode = $this->getArgument(0, true); + $mode = $this->argument(0)->type('bool')->value(true); imageinterlace($image->getCore(), $mode); diff --git a/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php b/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php index ed5d6eee..d4efb2e5 100644 --- a/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php +++ b/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php @@ -8,8 +8,8 @@ class LimitColorsCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $count = $this->getArgument(0); - $matte = $this->getArgument(1); + $count = $this->argument(0)->value(); + $matte = $this->argument(1)->value(); // get current image size $size = $image->getSize(); diff --git a/src/Intervention/Image/Gd/Commands/MaskCommand.php b/src/Intervention/Image/Gd/Commands/MaskCommand.php index fb184b98..eff46885 100644 --- a/src/Intervention/Image/Gd/Commands/MaskCommand.php +++ b/src/Intervention/Image/Gd/Commands/MaskCommand.php @@ -6,8 +6,8 @@ class MaskCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $mask_source = $this->getArgument(0); - $mask_w_alpha = (bool) $this->getArgument(1); + $mask_source = $this->argument(0)->value(); + $mask_w_alpha = $this->argument(1)->type('bool')->value(false); $image_size = $image->getSize(); diff --git a/src/Intervention/Image/Gd/Commands/OpacityCommand.php b/src/Intervention/Image/Gd/Commands/OpacityCommand.php index 828905f8..bdd271a6 100644 --- a/src/Intervention/Image/Gd/Commands/OpacityCommand.php +++ b/src/Intervention/Image/Gd/Commands/OpacityCommand.php @@ -6,7 +6,7 @@ class OpacityCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $transparency = $this->getArgument(0); + $transparency = $this->argument(0)->between(0, 100)->required()->value(); // get size of image $size = $image->getSize(); diff --git a/src/Intervention/Image/Gd/Commands/PickColorCommand.php b/src/Intervention/Image/Gd/Commands/PickColorCommand.php index c49c8210..b18a4a21 100644 --- a/src/Intervention/Image/Gd/Commands/PickColorCommand.php +++ b/src/Intervention/Image/Gd/Commands/PickColorCommand.php @@ -8,9 +8,9 @@ class PickColorCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $x = $this->getArgument(0); - $y = $this->getArgument(1); - $format = $this->getArgument(2, 'array'); + $x = $this->argument(0)->type('integer')->required()->value(); + $y = $this->argument(1)->type('integer')->required()->value(); + $format = $this->argument(2)->type('string')->value('array'); // pick color $color = imagecolorat($image->getCore(), $x, $y); diff --git a/src/Intervention/Image/Gd/Commands/PixelCommand.php b/src/Intervention/Image/Gd/Commands/PixelCommand.php index 7b200533..b83c5023 100644 --- a/src/Intervention/Image/Gd/Commands/PixelCommand.php +++ b/src/Intervention/Image/Gd/Commands/PixelCommand.php @@ -8,9 +8,10 @@ class PixelCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $color = new Color($this->getArgument(0)); - $x = $this->getArgument(1); - $y = $this->getArgument(2); + $color = $this->argument(0)->required()->value(); + $color = new Color($color); + $x = $this->argument(1)->type('integer')->required()->value(); + $y = $this->argument(2)->type('integer')->required()->value(); return imagesetpixel($image->getCore(), $x, $y, $color->getInt()); } diff --git a/src/Intervention/Image/Gd/Commands/PixelateCommand.php b/src/Intervention/Image/Gd/Commands/PixelateCommand.php index 79bf2150..9f634bac 100644 --- a/src/Intervention/Image/Gd/Commands/PixelateCommand.php +++ b/src/Intervention/Image/Gd/Commands/PixelateCommand.php @@ -6,7 +6,7 @@ class PixelateCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $size = $this->getArgument(0, 10); + $size = $this->argument(0)->type('integer')->value(10); return imagefilter($image->getCore(), IMG_FILTER_PIXELATE, $size, true); } diff --git a/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php b/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php index 2d562494..a5792931 100644 --- a/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php +++ b/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php @@ -9,11 +9,11 @@ class ResizeCanvasCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $width = $this->getArgument(0); - $height = $this->getArgument(1); - $anchor = $this->getArgument(2) ? $this->getArgument(2) : 'center'; - $relative = $this->getArgument(3); - $bgcolor = $this->getArgument(4); + $width = $this->argument(0)->type('integer')->required()->value(); + $height = $this->argument(1)->type('integer')->required()->value(); + $anchor = $this->argument(2)->value('center'); + $relative = $this->argument(3)->type('boolean')->value(); + $bgcolor = $this->argument(4)->value(); $original_width = $image->getWidth(); $original_height = $image->getHeight(); diff --git a/src/Intervention/Image/Gd/Commands/ResizeCommand.php b/src/Intervention/Image/Gd/Commands/ResizeCommand.php index c235d506..5903f78e 100644 --- a/src/Intervention/Image/Gd/Commands/ResizeCommand.php +++ b/src/Intervention/Image/Gd/Commands/ResizeCommand.php @@ -6,9 +6,9 @@ class ResizeCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $width = $this->getArgument(0); - $height = $this->getArgument(1); - $constraints = $this->getArgument(2); + $width = $this->argument(0)->value(); + $height = $this->argument(1)->value(); + $constraints = $this->argument(2)->type('closure')->value(); // resize box $resized = $image->getSize()->resize($width, $height, $constraints); diff --git a/src/Intervention/Image/Gd/Commands/RotateCommand.php b/src/Intervention/Image/Gd/Commands/RotateCommand.php index c528edb3..06c66fdc 100644 --- a/src/Intervention/Image/Gd/Commands/RotateCommand.php +++ b/src/Intervention/Image/Gd/Commands/RotateCommand.php @@ -8,8 +8,9 @@ class RotateCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $angle = $this->getArgument(0); - $color = new Color($this->getArgument(1)); + $angle = $this->argument(0)->type('numeric')->required()->value(); + $color = $this->argument(1)->value(); + $color = new Color($color); // rotate image $image->setCore(imagerotate($image->getCore(), $angle, $color->getInt())); diff --git a/src/Intervention/Image/Gd/Commands/TrimCommand.php b/src/Intervention/Image/Gd/Commands/TrimCommand.php index 0f30177d..b6b70304 100644 --- a/src/Intervention/Image/Gd/Commands/TrimCommand.php +++ b/src/Intervention/Image/Gd/Commands/TrimCommand.php @@ -8,10 +8,10 @@ class TrimCommand extends ResizeCommand { public function execute($image) { - $base = $this->getArgument(0); - $away = $this->getArgument(1); - $tolerance = intval($this->getArgument(2, 0)); - $feather = intval($this->getArgument(3, 0)); + $base = $this->argument(0)->type('string')->value(); + $away = $this->argument(1)->value(); + $tolerance = $this->argument(2)->type('numeric')->value(0); + $feather = $this->argument(3)->type('numeric')->value(0); $width = $image->getWidth(); $height = $image->getHeight(); diff --git a/src/Intervention/Image/Gd/Commands/WidenCommand.php b/src/Intervention/Image/Gd/Commands/WidenCommand.php index 3afc4377..e30eca31 100644 --- a/src/Intervention/Image/Gd/Commands/WidenCommand.php +++ b/src/Intervention/Image/Gd/Commands/WidenCommand.php @@ -6,7 +6,7 @@ class WidenCommand extends ResizeCommand { public function execute($image) { - $width = $this->getArgument(0); + $width = $this->argument(0)->type('integer')->required()->value(); $this->arguments[0] = $width; $this->arguments[1] = null; diff --git a/src/Intervention/Image/Imagick/Commands/BlurCommand.php b/src/Intervention/Image/Imagick/Commands/BlurCommand.php index 5159372f..2ccfc6ab 100644 --- a/src/Intervention/Image/Imagick/Commands/BlurCommand.php +++ b/src/Intervention/Image/Imagick/Commands/BlurCommand.php @@ -6,7 +6,7 @@ class BlurCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $amount = intval($this->getArgument(0, 1)); + $amount = $this->argument(0)->between(0, 100)->value(1); return $image->getCore()->blurImage(1 * $amount, 0.5 * $amount); } diff --git a/src/Intervention/Image/Imagick/Commands/BrightnessCommand.php b/src/Intervention/Image/Imagick/Commands/BrightnessCommand.php index 8a5269ab..6b39098e 100644 --- a/src/Intervention/Image/Imagick/Commands/BrightnessCommand.php +++ b/src/Intervention/Image/Imagick/Commands/BrightnessCommand.php @@ -6,7 +6,7 @@ class BrightnessCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $level = $this->getArgument(0); + $level = $this->argument(0)->between(-100, 100)->required()->value(); return $image->getCore()->modulateImage(100 + $level, 100, 100); } diff --git a/src/Intervention/Image/Imagick/Commands/ColorizeCommand.php b/src/Intervention/Image/Imagick/Commands/ColorizeCommand.php index 04e30f5d..06da30b3 100644 --- a/src/Intervention/Image/Imagick/Commands/ColorizeCommand.php +++ b/src/Intervention/Image/Imagick/Commands/ColorizeCommand.php @@ -6,9 +6,9 @@ class ColorizeCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $red = $this->getArgument(0); - $green = $this->getArgument(1); - $blue = $this->getArgument(2); + $red = $this->argument(0)->between(-100, 100)->required()->value(); + $green = $this->argument(1)->between(-100, 100)->required()->value(); + $blue = $this->argument(2)->between(-100, 100)->required()->value(); // normalize colorize levels $red = $this->normalizeLevel($red); diff --git a/src/Intervention/Image/Imagick/Commands/ContrastCommand.php b/src/Intervention/Image/Imagick/Commands/ContrastCommand.php index 4e45027a..2c281b72 100644 --- a/src/Intervention/Image/Imagick/Commands/ContrastCommand.php +++ b/src/Intervention/Image/Imagick/Commands/ContrastCommand.php @@ -6,7 +6,7 @@ class ContrastCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $level = $this->getArgument(0); + $level = $this->argument(0)->between(-100, 100)->required()->value(); return $image->getCore()->sigmoidalContrastImage($level > 0, $level / 4, 0); } diff --git a/src/Intervention/Image/Imagick/Commands/CropCommand.php b/src/Intervention/Image/Imagick/Commands/CropCommand.php index 0ac38e73..22583e4a 100644 --- a/src/Intervention/Image/Imagick/Commands/CropCommand.php +++ b/src/Intervention/Image/Imagick/Commands/CropCommand.php @@ -9,10 +9,10 @@ class CropCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $width = $this->getArgument(0); - $height = $this->getArgument(1); - $x = $this->getArgument(2); - $y = $this->getArgument(3); + $width = $this->argument(0)->type('integer')->required()->value(); + $height = $this->argument(1)->type('integer')->required()->value(); + $x = $this->argument(2)->type('integer')->value(); + $y = $this->argument(3)->type('integer')->value(); if (is_null($width) || is_null($height)) { throw new \Intervention\Image\Exception\InvalidArgumentException( diff --git a/src/Intervention/Image/Imagick/Commands/FillCommand.php b/src/Intervention/Image/Imagick/Commands/FillCommand.php index 2ea205c8..ccc16f20 100644 --- a/src/Intervention/Image/Imagick/Commands/FillCommand.php +++ b/src/Intervention/Image/Imagick/Commands/FillCommand.php @@ -10,9 +10,9 @@ class FillCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $filling = $this->getArgument(0); - $x = $this->getArgument(1); - $y = $this->getArgument(2); + $filling = $this->argument(0)->value(); + $x = $this->argument(1)->type('integer')->value(); + $y = $this->argument(2)->type('integer')->value(); $imagick = $image->getCore(); diff --git a/src/Intervention/Image/Imagick/Commands/FitCommand.php b/src/Intervention/Image/Imagick/Commands/FitCommand.php index 539777bd..ae0208e6 100644 --- a/src/Intervention/Image/Imagick/Commands/FitCommand.php +++ b/src/Intervention/Image/Imagick/Commands/FitCommand.php @@ -8,8 +8,8 @@ class FitCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $width = $this->getArgument(0); - $height = $this->getArgument(1, $width); + $width = $this->argument(0)->type('integer')->value(); + $height = $this->argument(1)->type('integer')->value($width); // calculate size $fitted = $image->getSize()->fit(new Size($width, $height)); diff --git a/src/Intervention/Image/Imagick/Commands/FlipCommand.php b/src/Intervention/Image/Imagick/Commands/FlipCommand.php index 02caa9c5..107d12bd 100644 --- a/src/Intervention/Image/Imagick/Commands/FlipCommand.php +++ b/src/Intervention/Image/Imagick/Commands/FlipCommand.php @@ -6,7 +6,7 @@ class FlipCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $mode = strtolower($this->getArgument(0, 'h')); + $mode = $this->argument(0)->value('h'); if (in_array(strtolower($mode), array(2, 'v', 'vert', 'vertical'))) { // flip vertical diff --git a/src/Intervention/Image/Imagick/Commands/GammaCommand.php b/src/Intervention/Image/Imagick/Commands/GammaCommand.php index 5854c2b5..5065ffe7 100644 --- a/src/Intervention/Image/Imagick/Commands/GammaCommand.php +++ b/src/Intervention/Image/Imagick/Commands/GammaCommand.php @@ -6,7 +6,7 @@ class GammaCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $gamma = $this->getArgument(0); + $gamma = $this->argument(0)->type('numeric')->required()->value(); return $image->getCore()->gammaImage($gamma); } diff --git a/src/Intervention/Image/Imagick/Commands/HeightenCommand.php b/src/Intervention/Image/Imagick/Commands/HeightenCommand.php index 314f894c..98646d71 100644 --- a/src/Intervention/Image/Imagick/Commands/HeightenCommand.php +++ b/src/Intervention/Image/Imagick/Commands/HeightenCommand.php @@ -6,7 +6,7 @@ class HeightenCommand extends ResizeCommand { public function execute($image) { - $height = $this->getArgument(0); + $height = $this->argument(0)->type('integer')->required()->value(); $this->arguments[0] = null; $this->arguments[1] = $height; diff --git a/src/Intervention/Image/Imagick/Commands/InsertCommand.php b/src/Intervention/Image/Imagick/Commands/InsertCommand.php index 7c6e3906..4ea21c8e 100644 --- a/src/Intervention/Image/Imagick/Commands/InsertCommand.php +++ b/src/Intervention/Image/Imagick/Commands/InsertCommand.php @@ -8,10 +8,10 @@ class InsertCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $source = $this->getArgument(0); - $position = $this->getArgument(1); - $x = intval($this->getArgument(2)); - $y = intval($this->getArgument(3)); + $source = $this->argument(0)->value(); + $position = $this->argument(1)->type('string')->value(); + $x = $this->argument(2)->type('integer')->value(0); + $y = $this->argument(3)->type('integer')->value(0); // build watermark $watermark = $image->getDriver()->init($source); diff --git a/src/Intervention/Image/Imagick/Commands/InterlaceCommand.php b/src/Intervention/Image/Imagick/Commands/InterlaceCommand.php index b30ee90b..3af269d7 100644 --- a/src/Intervention/Image/Imagick/Commands/InterlaceCommand.php +++ b/src/Intervention/Image/Imagick/Commands/InterlaceCommand.php @@ -6,7 +6,7 @@ class InterlaceCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $mode = $this->getArgument(0, true); + $mode = $this->argument(0)->type('bool')->value(true); if ($mode) { $mode = \Imagick::INTERLACE_LINE; diff --git a/src/Intervention/Image/Imagick/Commands/LimitColorsCommand.php b/src/Intervention/Image/Imagick/Commands/LimitColorsCommand.php index 5befd4fe..05f4457e 100644 --- a/src/Intervention/Image/Imagick/Commands/LimitColorsCommand.php +++ b/src/Intervention/Image/Imagick/Commands/LimitColorsCommand.php @@ -6,8 +6,8 @@ class LimitColorsCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $count = $this->getArgument(0); - $matte = $this->getArgument(1); + $count = $this->argument(0)->value(); + $matte = $this->argument(1)->value(); // get current image size $size = $image->getSize(); diff --git a/src/Intervention/Image/Imagick/Commands/MaskCommand.php b/src/Intervention/Image/Imagick/Commands/MaskCommand.php index 2ba7092a..f4f6b667 100644 --- a/src/Intervention/Image/Imagick/Commands/MaskCommand.php +++ b/src/Intervention/Image/Imagick/Commands/MaskCommand.php @@ -6,8 +6,8 @@ class MaskCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $mask_source = $this->getArgument(0); - $mask_w_alpha = (bool) $this->getArgument(1); + $mask_source = $this->argument(0)->value(); + $mask_w_alpha = $this->argument(1)->type('bool')->value(false); // get imagick $imagick = $image->getCore(); diff --git a/src/Intervention/Image/Imagick/Commands/OpacityCommand.php b/src/Intervention/Image/Imagick/Commands/OpacityCommand.php index a428468c..7d5b029b 100644 --- a/src/Intervention/Image/Imagick/Commands/OpacityCommand.php +++ b/src/Intervention/Image/Imagick/Commands/OpacityCommand.php @@ -6,7 +6,7 @@ class OpacityCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $transparency = $this->getArgument(0); + $transparency = $this->argument(0)->between(0, 100)->required()->value(); return $image->getCore()->setImageOpacity($transparency / 100); } diff --git a/src/Intervention/Image/Imagick/Commands/PickColorCommand.php b/src/Intervention/Image/Imagick/Commands/PickColorCommand.php index 8f42d586..9b157b4a 100644 --- a/src/Intervention/Image/Imagick/Commands/PickColorCommand.php +++ b/src/Intervention/Image/Imagick/Commands/PickColorCommand.php @@ -8,9 +8,9 @@ class PickColorCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $x = $this->getArgument(0, 0); - $y = $this->getArgument(1, 0); - $format = $this->getArgument(2, 'array'); + $x = $this->argument(0)->type('integer')->required()->value(); + $y = $this->argument(1)->type('integer')->required()->value(); + $format = $this->argument(2)->type('string')->value('array'); // pick color $color = new Color($image->getCore()->getImagePixelColor($x, $y)); diff --git a/src/Intervention/Image/Imagick/Commands/PixelCommand.php b/src/Intervention/Image/Imagick/Commands/PixelCommand.php index 14d31645..c4e942b4 100644 --- a/src/Intervention/Image/Imagick/Commands/PixelCommand.php +++ b/src/Intervention/Image/Imagick/Commands/PixelCommand.php @@ -8,9 +8,10 @@ class PixelCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $color = new Color($this->getArgument(0)); - $x = $this->getArgument(1); - $y = $this->getArgument(2); + $color = $this->argument(0)->required()->value(); + $color = new Color($color); + $x = $this->argument(1)->type('integer')->required()->value(); + $y = $this->argument(2)->type('integer')->required()->value(); // prepare pixel $draw = new \ImagickDraw; diff --git a/src/Intervention/Image/Imagick/Commands/PixelateCommand.php b/src/Intervention/Image/Imagick/Commands/PixelateCommand.php index f7d1cb77..85f86f81 100644 --- a/src/Intervention/Image/Imagick/Commands/PixelateCommand.php +++ b/src/Intervention/Image/Imagick/Commands/PixelateCommand.php @@ -6,7 +6,7 @@ class PixelateCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $size = intval($this->getArgument(0, 10)); + $size = $this->argument(0)->type('integer')->value(10); $width = $image->getWidth(); $height = $image->getHeight(); diff --git a/src/Intervention/Image/Imagick/Commands/ResizeCanvasCommand.php b/src/Intervention/Image/Imagick/Commands/ResizeCanvasCommand.php index 23055ba2..26f0a0ee 100644 --- a/src/Intervention/Image/Imagick/Commands/ResizeCanvasCommand.php +++ b/src/Intervention/Image/Imagick/Commands/ResizeCanvasCommand.php @@ -6,11 +6,11 @@ class ResizeCanvasCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $width = $this->getArgument(0); - $height = $this->getArgument(1); - $anchor = $this->getArgument(2) ? $this->getArgument(2) : 'center'; - $relative = $this->getArgument(3); - $bgcolor = $this->getArgument(4); + $width = $this->argument(0)->type('integer')->required()->value(); + $height = $this->argument(1)->type('integer')->required()->value(); + $anchor = $this->argument(2)->value('center'); + $relative = $this->argument(3)->type('boolean')->value(); + $bgcolor = $this->argument(4)->value(); $original_width = $image->getWidth(); $original_height = $image->getHeight(); diff --git a/src/Intervention/Image/Imagick/Commands/ResizeCommand.php b/src/Intervention/Image/Imagick/Commands/ResizeCommand.php index b3e2b889..6357c6ed 100644 --- a/src/Intervention/Image/Imagick/Commands/ResizeCommand.php +++ b/src/Intervention/Image/Imagick/Commands/ResizeCommand.php @@ -6,9 +6,9 @@ class ResizeCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $width = $this->getArgument(0); - $height = $this->getArgument(1); - $constraints = $this->getArgument(2); + $width = $this->argument(0)->value(); + $height = $this->argument(1)->value(); + $constraints = $this->argument(2)->type('closure')->value(); // resize box $resized = $image->getSize()->resize($width, $height, $constraints); diff --git a/src/Intervention/Image/Imagick/Commands/RotateCommand.php b/src/Intervention/Image/Imagick/Commands/RotateCommand.php index 2bbb4826..6b1c7856 100644 --- a/src/Intervention/Image/Imagick/Commands/RotateCommand.php +++ b/src/Intervention/Image/Imagick/Commands/RotateCommand.php @@ -8,8 +8,9 @@ class RotateCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $angle = $this->getArgument(0); - $color = new Color($this->getArgument(1)); + $angle = $this->argument(0)->type('numeric')->required()->value(); + $color = $this->argument(1)->value(); + $color = new Color($color); // rotate image $image->getCore()->rotateImage($color->getPixel(), ($angle * -1)); diff --git a/src/Intervention/Image/Imagick/Commands/TrimCommand.php b/src/Intervention/Image/Imagick/Commands/TrimCommand.php index 59601d77..3f6229f9 100644 --- a/src/Intervention/Image/Imagick/Commands/TrimCommand.php +++ b/src/Intervention/Image/Imagick/Commands/TrimCommand.php @@ -8,10 +8,10 @@ class TrimCommand extends \Intervention\Image\Commands\AbstractCommand { public function execute($image) { - $base = $this->getArgument(0); - $away = $this->getArgument(1); - $tolerance = intval($this->getArgument(2, 0)); - $feather = intval($this->getArgument(3, 0)); + $base = $this->argument(0)->type('string')->value(); + $away = $this->argument(1)->value(); + $tolerance = $this->argument(2)->type('numeric')->value(0); + $feather = $this->argument(3)->type('numeric')->value(0); $width = $image->getWidth(); $height = $image->getHeight(); diff --git a/src/Intervention/Image/Imagick/Commands/WidenCommand.php b/src/Intervention/Image/Imagick/Commands/WidenCommand.php index fe6838d2..c26134e4 100644 --- a/src/Intervention/Image/Imagick/Commands/WidenCommand.php +++ b/src/Intervention/Image/Imagick/Commands/WidenCommand.php @@ -6,7 +6,7 @@ class WidenCommand extends ResizeCommand { public function execute($image) { - $width = $this->getArgument(0); + $width = $this->argument(0)->type('integer')->required()->value(); $this->arguments[0] = $width; $this->arguments[1] = null; diff --git a/tests/AbstractCommandTest.php b/tests/AbstractCommandTest.php index 073cdcf7..cd619600 100644 --- a/tests/AbstractCommandTest.php +++ b/tests/AbstractCommandTest.php @@ -7,11 +7,11 @@ class AbstractCommandTest extends PHPUnit_Framework_TestCase Mockery::close(); } - public function testGetArgument() + public function testArgument() { $command = $this->getTestCommand(); - $this->assertEquals('foo', $command->getArgument(0)); - $this->assertEquals('bar', $command->getArgument(1)); + $this->assertEquals('foo', $command->argument(0)->value()); + $this->assertEquals('bar', $command->argument(1)->value()); } public function testGetOutput() diff --git a/tests/ArgumentTest.php b/tests/ArgumentTest.php index 44b32c6b..e77ec47e 100644 --- a/tests/ArgumentTest.php +++ b/tests/ArgumentTest.php @@ -25,6 +25,10 @@ class ArgumentTest extends PHPUnit_Framework_TestCase $arg = new Argument($this->getMockedCommand(array(null))); $arg->required(); $this->validateArgument($arg, null); + + $arg = new Argument($this->getMockedCommand(array(0))); + $arg->required(); + $this->validateArgument($arg, 0); } /** @@ -85,6 +89,30 @@ class ArgumentTest extends PHPUnit_Framework_TestCase $arg->type('numeric'); } + public function testTypeBooleanPass() + { + $arg = new Argument($this->getMockedCommand(array())); + $arg->type('boolean'); + $this->validateArgument($arg, null); + + $arg = new Argument($this->getMockedCommand(array(true))); + $arg->type('boolean'); + $this->validateArgument($arg, true); + + $arg = new Argument($this->getMockedCommand(array(false))); + $arg->type('boolean'); + $this->validateArgument($arg, false); + } + + /** + * @expectedException \Intervention\Image\Exception\InvalidArgumentException + */ + public function testTypeBooleanFail() + { + $arg = new Argument($this->getMockedCommand(array('foo'))); + $arg->type('boolean'); + } + public function testTypeStringPass() { $arg = new Argument($this->getMockedCommand(array())); diff --git a/tests/CircleCommandTest.php b/tests/CircleCommandTest.php index dffcab10..7d816a15 100644 --- a/tests/CircleCommandTest.php +++ b/tests/CircleCommandTest.php @@ -17,7 +17,7 @@ class CircleCommandTest extends PHPUnit_Framework_TestCase $image = Mockery::mock('\Intervention\Image\Image'); $image->shouldReceive('getDriver')->once()->andReturn($driver); $image->shouldReceive('getCore')->once()->andReturn($resource); - $command = new CircleCommand(10, 20, 250); + $command = new CircleCommand(array(10, 20, 250)); $result = $command->execute($image); $this->assertTrue($result); $this->assertFalse($command->hasOutput()); @@ -33,7 +33,7 @@ class CircleCommandTest extends PHPUnit_Framework_TestCase $image->shouldReceive('getDriver')->once()->andReturn($driver); $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new CircleCommand(10, 20, 250); + $command = new CircleCommand(array(10, 20, 250)); $result = $command->execute($image); $this->assertTrue($result); $this->assertFalse($command->hasOutput()); diff --git a/tests/EllipseCommandTest.php b/tests/EllipseCommandTest.php index 60577e76..68de6f57 100644 --- a/tests/EllipseCommandTest.php +++ b/tests/EllipseCommandTest.php @@ -17,7 +17,7 @@ class EllipseCommandTest extends PHPUnit_Framework_TestCase $image = Mockery::mock('\Intervention\Image\Image'); $image->shouldReceive('getDriver')->once()->andReturn($driver); $image->shouldReceive('getCore')->once()->andReturn($resource); - $command = new EllipseCommand(10, 20, 250, 150); + $command = new EllipseCommand(array(10, 20, 250, 150)); $result = $command->execute($image); $this->assertTrue($result); $this->assertFalse($command->hasOutput()); @@ -33,7 +33,7 @@ class EllipseCommandTest extends PHPUnit_Framework_TestCase $image->shouldReceive('getDriver')->once()->andReturn($driver); $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new EllipseCommand(10, 20, 250, 150); + $command = new EllipseCommand(array(10, 20, 250, 150)); $result = $command->execute($image); $this->assertTrue($result); $this->assertFalse($command->hasOutput()); diff --git a/tests/PickColorCommandTest.php b/tests/PickColorCommandTest.php index 458ac880..731de04e 100644 --- a/tests/PickColorCommandTest.php +++ b/tests/PickColorCommandTest.php @@ -10,19 +10,6 @@ class PickColorCommandTest extends PHPUnit_Framework_TestCase Mockery::close(); } - public function testGd() - { - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->times(2)->andReturn($resource); - $command = new PickColorGd(array()); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInternalType('array', $command->getOutput()); - $this->assertEquals(4, count($command->getOutput())); - } - public function testGdWithCoordinates() { $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); @@ -49,20 +36,6 @@ class PickColorCommandTest extends PHPUnit_Framework_TestCase $this->assertEquals('#ffffff', $command->getOutput()); } - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('getimagepixelcolor')->with(0, 0)->andReturn(new ImagickPixel); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new PickColorImagick(array()); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInternalType('array', $command->getOutput()); - $this->assertEquals(4, count($command->getOutput())); - } - public function testImagickWithCoordinates() { $imagick = Mockery::mock('Imagick'); diff --git a/tests/TextCommandTest.php b/tests/TextCommandTest.php index 4b9694c9..53df1650 100644 --- a/tests/TextCommandTest.php +++ b/tests/TextCommandTest.php @@ -17,7 +17,7 @@ class TextCommandTest extends PHPUnit_Framework_TestCase $image = Mockery::mock('\Intervention\Image\Image'); $image->shouldReceive('getDriver')->once()->andReturn($driver); $image->shouldReceive('getCore')->once()->andReturn($resource); - $command = new TextCommand('test', 10, 20); + $command = new TextCommand(array('test', 10, 20)); $result = $command->execute($image); $this->assertTrue($result); $this->assertFalse($command->hasOutput());