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