PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.8
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.8
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / spatie / image / src / ManipulationSequence.php

ManipulationSequence.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.8, at vendor/spatie/image/src/ManipulationSequence.php

134 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Spatie\Image;
4
5 use ArrayIterator;
6 use IteratorAggregate;
7
8 class ManipulationSequence implements IteratorAggregate
9 {
10 protected array $groups = [];
11
12 public function __construct(array $sequenceArray = [])
13 {
14 $this->startNewGroup();
15 $this->mergeArray($sequenceArray);
16 }
17
18 public function addManipulation(string $operation, string $argument): static
19 {
20 $lastIndex = count($this->groups) - 1;
21
22 $this->groups[$lastIndex][$operation] = $argument;
23
24 return $this;
25 }
26
27 public function merge(self $sequence): static
28 {
29 $sequenceArray = $sequence->toArray();
30
31 $this->mergeArray($sequenceArray);
32
33 return $this;
34 }
35
36 public function mergeArray(array $sequenceArray): void
37 {
38 foreach ($sequenceArray as $group) {
39 foreach ($group as $name => $argument) {
40 $this->addManipulation($name, $argument);
41 }
42
43 if (next($sequenceArray)) {
44 $this->startNewGroup();
45 }
46 }
47 }
48
49 public function startNewGroup(): static
50 {
51 $this->groups[] = [];
52
53 return $this;
54 }
55
56 public function toArray(): array
57 {
58 return $this->getGroups();
59 }
60
61 public function getGroups(): array
62 {
63 return $this->sanitizeManipulationSets($this->groups);
64 }
65
66 public function getIterator(): ArrayIterator
67 {
68 return new ArrayIterator($this->toArray());
69 }
70
71 public function removeManipulation(string $manipulationName): static
72 {
73 foreach ($this->groups as &$group) {
74 if (array_key_exists($manipulationName, $group)) {
75 unset($group[$manipulationName]);
76 }
77 }
78
79 return $this;
80 }
81
82 public function isEmpty(): bool
83 {
84 if (count($this->groups) > 1) {
85 return false;
86 }
87
88 if (count($this->groups[0]) > 0) {
89 return false;
90 }
91
92 return true;
93 }
94
95 protected function sanitizeManipulationSets(array $groups): array
96 {
97 return array_values(array_filter($groups, function (array $manipulationSet) {
98 return count($manipulationSet);
99 }));
100 }
101
102 /*
103 * Determine if the sequences contain a manipulation with the given name.
104 */
105 public function getFirstManipulationArgument($searchManipulationName)
106 {
107 foreach ($this->groups as $group) {
108 foreach ($group as $name => $argument) {
109 if ($name === $searchManipulationName) {
110 return $argument;
111 }
112 }
113 }
114 }
115
116 /*
117 * Determine if the sequences contain a manipulation with the given name.
118 */
119 public function contains($searchManipulationName): bool
120 {
121 foreach ($this->groups as $group) {
122 foreach ($group as $name => $argument) {
123 if ($name === $searchManipulationName) {
124 return true;
125 }
126 }
127
128 return false;
129 }
130
131 return false;
132 }
133 }
134