1 : <?php
2 : namespace phMagick\Core;
3 :
4 : // not needed, just added here for clarity
5 : use phMagick\Core\Command;
6 :
7 : /**
8 : *
9 : * Base class for phMagick Action
10 : * @author nuno
11 : * @package phmagick
12 : * @subpackage core
13 : *
14 : */
15 : Abstract class Action
16 : {
17 : private $source;
18 : private $destination;
19 : /**
20 : *
21 : * holds valid values for imagemagick gravity
22 : * @var array[string]
23 : */
24 : protected $gravityValues = array(
25 : 'northwest',
26 : 'north',
27 : 'northeast',
28 : 'west',
29 : 'center',
30 : 'east',
31 : 'southwest',
32 : 'south',
33 : 'southeast'
34 : );
35 :
36 : /**
37 : *
38 : * checks if gravity is an allowed value
39 : * @param String $gravity
40 : * @return Boolean
41 : */
42 : public function isValidGravity($gravity)
43 : {
44 10 : return in_array(strtolower($gravity), $this->gravityValues);
45 : }
46 : /**
47 : *
48 : * to be overwritten from Action classes
49 : *
50 : * this method should return the phMagick shell command to be executed
51 : *
52 : * @return Command
53 : */
54 : abstract function getShellCommand();
55 :
56 : /**
57 : *
58 : * created the class and set the source and destination file paths
59 : * @param String $source
60 : * @param String $destination
61 : */
62 : public function __construct($source, $destination)
63 : {
64 15 : $this->setSource($source);
65 15 : $this->setDestination($destination);
66 15 : }
67 :
68 : /**
69 : *
70 : * Sets the file path of the file to be transformed
71 : * @param String $file
72 : */
73 : public function setSource($file)
74 : {
75 15 : $this->source = $file;
76 15 : return $this;
77 : }
78 : /**
79 : *
80 : * Gets the file path of the file to be transformed
81 : * return String
82 : */
83 : public function getSource()
84 : {
85 1 : return $this->source;
86 : }
87 :
88 : /**
89 : *
90 : * Sets the file path of the file transformed file (new file)
91 : * @param String $file
92 : */
93 : public function setDestination($file)
94 : {
95 15 : $this->destination = $file;
96 15 : return $this;
97 : }
98 :
99 : /**
100 : *
101 : * Gets the file path of the file transformed file (new file)
102 : * return String
103 : */
104 : public function getDestination()
105 : {
106 1 : return $this->destination;
107 : }
108 :
|