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
|
6 |
|
public function __construct( string $developing_php_class = null ) |
23
|
|
|
{ |
24
|
6 |
|
$this->developing_php_class = $developing_php_class ?: Developing::class; |
25
|
|
|
|
26
|
6 |
|
if (!is_subclass_of($this->developing_php_class, DevelopingInterface::class )) |
|
|
|
|
27
|
|
|
throw new \InvalidArgumentException("Class name must implement DevelopingInterface."); |
28
|
6 |
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The factory method. |
33
|
|
|
* |
34
|
|
|
* Expects an array with at least elements "time", "densities", and "exposures". |
35
|
|
|
* |
36
|
|
|
* If no "exposures" are given, but "zones" numbers are instead, the zone numbers |
37
|
|
|
* will be converted internally. |
38
|
|
|
* |
39
|
|
|
* @param array $developing |
40
|
|
|
* @return DevelopingInterface |
41
|
|
|
*/ |
42
|
6 |
|
public function __invoke( $developing ) |
43
|
|
|
{ |
44
|
6 |
|
$time = $developing['time'] ?? null; |
45
|
6 |
|
$densities = $developing['densities'] ?? array(); |
46
|
6 |
|
$zones = $developing['zones'] ?? array(); |
47
|
6 |
|
$exposures = $developing['exposures'] ?? array(); |
48
|
|
|
|
49
|
6 |
|
if (empty($exposures) and !empty($zones)): |
|
|
|
|
50
|
3 |
|
$exposures = new Zones( $zones ); |
51
|
|
|
endif; |
52
|
|
|
|
53
|
6 |
|
$developing_php_class = $this->developing_php_class; |
|
|
|
|
54
|
6 |
|
return new $developing_php_class( $exposures, $densities, $time ); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.