@@ 5-57 (lines=53) @@ | ||
2 | namespace FilmTools\Commons; |
|
3 | ||
4 | ||
5 | class ExposuresFactory |
|
6 | { |
|
7 | ||
8 | /** |
|
9 | * @var string |
|
10 | */ |
|
11 | public $php_exposures_class; |
|
12 | ||
13 | ||
14 | /** |
|
15 | * @param string|null $php_exposures_class |
|
16 | */ |
|
17 | public function __construct( string $php_exposures_class = null ) |
|
18 | { |
|
19 | $this->php_exposures_class = $php_exposures_class ?: Exposures::class; |
|
20 | ||
21 | if (!is_subclass_of($this->php_exposures_class, ExposuresInterface::class )) |
|
22 | throw new FilmToolsInvalidArgumentException("Class name must implement ExposuresInterface."); |
|
23 | ||
24 | } |
|
25 | ||
26 | ||
27 | /** |
|
28 | * @param array $data |
|
29 | * @return ExposuresInterface |
|
30 | */ |
|
31 | public function fromValues( $data ) : ExposuresInterface |
|
32 | { |
|
33 | if ($data instanceOf \Traversable ) |
|
34 | $data = iterator_to_array( $data ); |
|
35 | else if (!is_array($data)) |
|
36 | throw new FilmToolsInvalidArgumentException("Array or Traversable expected"); |
|
37 | ||
38 | $php_class = $this->php_exposures_class; |
|
39 | return new $php_class( array_values( $data )); |
|
40 | } |
|
41 | ||
42 | ||
43 | /** |
|
44 | * @param array $data |
|
45 | * @return ExposuresInterface |
|
46 | */ |
|
47 | public function fromKeys( $data ) : ExposuresInterface |
|
48 | { |
|
49 | if ($data instanceOf \Traversable ) |
|
50 | $data = iterator_to_array( $data ); |
|
51 | else if (!is_array($data)) |
|
52 | throw new FilmToolsInvalidArgumentException("Array or Traversable expected"); |
|
53 | ||
54 | $php_class = $this->php_exposures_class; |
|
55 | return new $php_class( array_keys( $data )); |
|
56 | } |
|
57 | } |
|
58 |
@@ 5-57 (lines=53) @@ | ||
2 | namespace FilmTools\Commons; |
|
3 | ||
4 | ||
5 | class ZonesFactory |
|
6 | { |
|
7 | ||
8 | /** |
|
9 | * @var string |
|
10 | */ |
|
11 | public $php_zones_class; |
|
12 | ||
13 | ||
14 | /** |
|
15 | * @param string|null $php_zones_class |
|
16 | */ |
|
17 | public function __construct( string $php_zones_class = null ) |
|
18 | { |
|
19 | $this->php_zones_class = $php_zones_class ?: Zones::class; |
|
20 | ||
21 | if (!is_subclass_of($this->php_zones_class, ZonesInterface::class )) |
|
22 | throw new FilmToolsInvalidArgumentException("Class name must implement ZonesInterface."); |
|
23 | ||
24 | } |
|
25 | ||
26 | ||
27 | /** |
|
28 | * @param array $data |
|
29 | * @return ZonesInterface |
|
30 | */ |
|
31 | public function fromValues( $data ) : ZonesInterface |
|
32 | { |
|
33 | if ($data instanceOf \Traversable ) |
|
34 | $data = iterator_to_array( $data ); |
|
35 | else if (!is_array($data)) |
|
36 | throw new FilmToolsInvalidArgumentException("Array or Traversable expected"); |
|
37 | ||
38 | $php_class = $this->php_zones_class; |
|
39 | return new $php_class( array_values( $data )); |
|
40 | } |
|
41 | ||
42 | ||
43 | /** |
|
44 | * @param array $data |
|
45 | * @return ZonesInterface |
|
46 | */ |
|
47 | public function fromKeys( $data ) : ZonesInterface |
|
48 | { |
|
49 | if ($data instanceOf \Traversable ) |
|
50 | $data = iterator_to_array( $data ); |
|
51 | else if (!is_array($data)) |
|
52 | throw new FilmToolsInvalidArgumentException("Array or Traversable expected"); |
|
53 | ||
54 | $php_class = $this->php_zones_class; |
|
55 | return new $php_class( array_keys( $data )); |
|
56 | } |
|
57 | } |
|
58 |