|
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 Conversion |
|
60
|
|
|
*/ |
|
61
|
6 |
|
public static function create(string $name) |
|
62
|
|
|
{ |
|
63
|
6 |
|
return new static($name); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Set the collection names on which this conversion must be performed. |
|
68
|
|
|
* |
|
69
|
|
|
* @param array ...$collectionNames |
|
70
|
|
|
* |
|
71
|
|
|
* @return $this |
|
72
|
|
|
*/ |
|
73
|
|
|
public function performOnCollections(...$collectionNames) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->performOnCollections = $collectionNames; |
|
76
|
|
|
|
|
77
|
|
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Determine if this conversion should be performed on the given |
|
82
|
|
|
* collection. |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $collectionName |
|
85
|
|
|
* |
|
86
|
|
|
* @return bool |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function shouldBePerformedOn(string $collectionName): bool |
|
89
|
|
|
{ |
|
90
|
|
|
//if no collections were specified, perform conversion on all collections |
|
91
|
1 |
|
if (!count($this->performOnCollections)) { |
|
92
|
1 |
|
return true; |
|
93
|
|
|
} |
|
94
|
|
|
if (in_array('*', $this->performOnCollections)) { |
|
95
|
|
|
return true; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return in_array($collectionName, $this->performOnCollections); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return ManipulationSequence |
|
103
|
|
|
*/ |
|
104
|
3 |
|
public function getManipulations(): ManipulationSequence |
|
105
|
|
|
{ |
|
106
|
3 |
|
return $this->manipulations; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|