1
|
|
|
<?php |
2
|
|
|
namespace FilmTools\Developing; |
3
|
|
|
|
4
|
|
|
use FilmTools\Commons\Zones; |
5
|
|
|
|
6
|
|
|
class DevelopingFactory |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* PHP class name (FQDN) of the DevelopingInterface instance this factory produces. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
public $developing_php_class; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param string|null $developing_php_class DevelopingInterface instance FQDN |
19
|
|
|
* |
20
|
|
|
* @throws InvalidArgumentException If FQDN does not implement DevelopingInterface |
21
|
|
|
*/ |
22
|
18 |
|
public function __construct( string $developing_php_class = null ) |
23
|
|
|
{ |
24
|
18 |
|
$this->developing_php_class = $developing_php_class ?: Developing::class; |
25
|
|
|
|
26
|
18 |
|
if (!is_subclass_of($this->developing_php_class, DevelopingInterface::class )): |
|
|
|
|
27
|
3 |
|
$msg = sprintf("Class name must implement '%s'.", DevelopingInterface::class); |
28
|
3 |
|
throw new DevelopingInvalidArgumentException( $msg ); |
29
|
|
|
endif; |
30
|
15 |
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The factory method. |
35
|
|
|
* |
36
|
|
|
* Expects an array with at least elements "time", "densities", and "exposures". |
37
|
|
|
* |
38
|
|
|
* If no "exposures" are given, but "zones" numbers are instead, the zone numbers |
39
|
|
|
* will be converted internally. |
40
|
|
|
* |
41
|
|
|
* @param array $developing |
42
|
|
|
* @return DevelopingInterface |
43
|
|
|
*/ |
44
|
15 |
|
public function __invoke( $developing ) |
45
|
|
|
{ |
46
|
15 |
|
$densities = $developing['densities'] ?? array(); |
47
|
15 |
|
$zones = $developing['zones'] ?? array(); |
48
|
15 |
|
$exposures = $developing['exposures'] ?? array(); |
49
|
|
|
|
50
|
15 |
|
if (!array_key_exists("time", $developing)) |
51
|
3 |
|
throw new NoTimeGivenException("The data array must contain a 'time' element."); |
52
|
|
|
|
53
|
12 |
|
$time = $developing['time'] ?? false; |
54
|
12 |
|
if (empty($time)) |
55
|
6 |
|
throw new NoTimeGivenException("The developing time must not be empty."); |
56
|
|
|
|
57
|
6 |
|
if (empty($exposures) and !empty($zones)): |
58
|
3 |
|
$exposures = new Zones( $zones ); |
59
|
|
|
endif; |
60
|
|
|
|
61
|
6 |
|
$developing_php_class = $this->developing_php_class; |
62
|
6 |
|
return new $developing_php_class( $exposures, $densities, $time ); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|