AbstractCommand.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Intervention\Image\Commands;
  3. abstract class AbstractCommand
  4. {
  5. /**
  6. * Arguments of command
  7. *
  8. * @var array
  9. */
  10. public $arguments;
  11. /**
  12. * Output of command
  13. *
  14. * @var mixed
  15. */
  16. protected $output;
  17. /**
  18. * Executes current command on given image
  19. *
  20. * @param \Intervention\Image\Image $image
  21. * @return mixed
  22. */
  23. abstract public function execute($image);
  24. /**
  25. * Creates new command instance
  26. *
  27. * @param array $arguments
  28. */
  29. public function __construct($arguments)
  30. {
  31. $this->arguments = $arguments;
  32. }
  33. /**
  34. * Creates new argument instance from given argument key
  35. *
  36. * @param int $key
  37. * @return \Intervention\Image\Commands\Argument
  38. */
  39. public function argument($key)
  40. {
  41. return new \Intervention\Image\Commands\Argument($this, $key);
  42. }
  43. /**
  44. * Returns output data of current command
  45. *
  46. * @return mixed
  47. */
  48. public function getOutput()
  49. {
  50. return $this->output ? $this->output : null;
  51. }
  52. /**
  53. * Determines if current instance has output data
  54. *
  55. * @return boolean
  56. */
  57. public function hasOutput()
  58. {
  59. return ! is_null($this->output);
  60. }
  61. /**
  62. * Sets output data of current command
  63. *
  64. * @param mixed $value
  65. */
  66. public function setOutput($value)
  67. {
  68. $this->output = $value;
  69. }
  70. }