1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\MediaLibrary\Conversions; |
4
|
|
|
|
5
|
|
|
use ByTIC\MediaLibrary\Conversions\Manipulations\Manipulation; |
6
|
|
|
use ByTIC\MediaLibrary\Conversions\Manipulations\ManipulationSequence; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Conversion. |
10
|
|
|
*/ |
11
|
|
|
class Conversion |
12
|
|
|
{ |
13
|
|
|
/** @var string */ |
14
|
|
|
protected $name = ''; |
15
|
|
|
|
16
|
|
|
protected $manipulations; |
17
|
|
|
|
18
|
|
|
/** @var array */ |
19
|
|
|
protected $performOnCollections = []; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Conversion constructor. |
23
|
|
|
* |
24
|
|
|
* @param string $name |
25
|
|
|
*/ |
26
|
6 |
|
public function __construct(string $name) |
27
|
|
|
{ |
28
|
6 |
|
$this->name = $name; |
29
|
6 |
|
$this->manipulations = (new ManipulationSequence()); |
30
|
6 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param $name |
34
|
|
|
* @param $arguments |
35
|
|
|
* |
36
|
|
|
* @return $this |
37
|
|
|
*/ |
38
|
3 |
|
public function __call($name, $arguments) |
39
|
|
|
{ |
40
|
|
|
// if (!method_exists($this->manipulations, $name)) { |
41
|
|
|
// throw new BadMethodCallException("Manipulation `{$name}` does not exist"); |
42
|
|
|
// } |
43
|
3 |
|
$this->manipulations[] = Manipulation::create($name, ...$arguments); |
44
|
|
|
|
45
|
3 |
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
2 |
|
public function getName(): string |
52
|
|
|
{ |
53
|
2 |
|
return $this->name; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $name |
58
|
|
|
* |
59
|
|
|
* @return $this |
60
|
|
|
*/ |
61
|
|
|
public function setName(string $name): Conversion |
62
|
|
|
{ |
63
|
|
|
$this->name = $name; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $name |
70
|
|
|
* |
71
|
|
|
* @return Conversion |
72
|
|
|
*/ |
73
|
6 |
|
public static function create(string $name) |
74
|
|
|
{ |
75
|
6 |
|
return new static($name); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Set the collection names on which this conversion must be performed. |
80
|
|
|
* |
81
|
|
|
* @param array ...$collectionNames |
82
|
|
|
* |
83
|
|
|
* @return $this |
84
|
|
|
*/ |
85
|
|
|
public function performOnCollections(...$collectionNames) |
86
|
|
|
{ |
87
|
|
|
$this->performOnCollections = $collectionNames; |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Determine if this conversion should be performed on the given |
94
|
|
|
* collection. |
95
|
|
|
* |
96
|
|
|
* @param string $collectionName |
97
|
|
|
* |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
1 |
|
public function shouldBePerformedOn(string $collectionName): bool |
101
|
|
|
{ |
102
|
|
|
//if no collections were specified, perform conversion on all collections |
103
|
1 |
|
if (!count($this->performOnCollections)) { |
104
|
1 |
|
return true; |
105
|
|
|
} |
106
|
|
|
if (in_array('*', $this->performOnCollections)) { |
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return in_array($collectionName, $this->performOnCollections); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return ManipulationSequence |
115
|
|
|
*/ |
116
|
3 |
|
public function getManipulations(): ManipulationSequence |
117
|
|
|
{ |
118
|
3 |
|
return $this->manipulations; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|