1 | <?php |
||
8 | class ManipulationSequence implements IteratorAggregate |
||
9 | { |
||
10 | /** @var array */ |
||
11 | protected $groups = []; |
||
12 | |||
13 | public function __construct(array $sequenceArray = []) |
||
14 | { |
||
15 | $this->startNewGroup(); |
||
16 | $this->mergeArray($sequenceArray); |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * @param string $operation |
||
21 | * @param string $argument |
||
22 | * |
||
23 | * @return $this |
||
24 | */ |
||
25 | public function addManipulation(string $operation, string $argument) |
||
26 | { |
||
27 | $lastIndex = count($this->groups) - 1; |
||
28 | |||
29 | $this->groups[$lastIndex][$operation] = $argument; |
||
30 | |||
31 | return $this; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param \Spatie\Image\ManipulationSequence $sequence |
||
36 | * |
||
37 | * @return $this |
||
38 | */ |
||
39 | public function merge(ManipulationSequence $sequence) |
||
40 | { |
||
41 | $sequenceArray = $sequence->toArray(); |
||
42 | |||
43 | $this->mergeArray($sequenceArray); |
||
44 | |||
45 | return $this; |
||
46 | } |
||
47 | |||
48 | public function mergeArray(array $sequenceArray) |
||
49 | { |
||
50 | foreach ($sequenceArray as $group) { |
||
51 | foreach ($group as $name => $argument) { |
||
52 | $this->addManipulation($name, $argument); |
||
53 | } |
||
54 | |||
55 | if (next($sequenceArray)) { |
||
56 | $this->startNewGroup(); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return $this |
||
63 | */ |
||
64 | public function startNewGroup() |
||
70 | |||
71 | public function toArray(): array |
||
75 | |||
76 | public function getGroups(): array |
||
80 | |||
81 | public function getIterator(): ArrayIterator |
||
85 | |||
86 | /** |
||
87 | * @param string $manipulationName |
||
88 | * |
||
89 | * @return $this |
||
90 | */ |
||
91 | public function removeManipulation(string $manipulationName) |
||
101 | |||
102 | public function isEmpty(): bool |
||
103 | { |
||
104 | if (count($this->groups) > 1) { |
||
105 | return false; |
||
114 | |||
115 | protected function sanitizeManipulationSets(array $groups): array |
||
121 | } |
||
122 |