1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PamiModule\Service; |
4
|
|
|
|
5
|
|
|
use Interop\Container\ContainerInterface; |
6
|
|
|
use RuntimeException; |
7
|
|
|
use Zend\ServiceManager\FactoryInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class AbstractFactory. |
11
|
|
|
*/ |
12
|
|
|
abstract class AbstractFactory implements FactoryInterface |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Service name. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $name; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Constructor. |
23
|
|
|
* |
24
|
|
|
* @param string $name Service name |
25
|
|
|
*/ |
26
|
3 |
|
public function __construct($name) |
27
|
|
|
{ |
28
|
3 |
|
$this->name = $name; |
29
|
3 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Gets options from configuration based on name. |
33
|
|
|
* |
34
|
|
|
* @param ContainerInterface $container Service locator |
35
|
|
|
* @param string $key Service type |
36
|
|
|
* @param null|string $name Service name |
37
|
|
|
* |
38
|
|
|
* @throws \RuntimeException |
39
|
|
|
* |
40
|
|
|
* @return \Zend\Stdlib\AbstractOptions |
41
|
|
|
*/ |
42
|
3 |
|
public function getOptions(ContainerInterface $container, $key, $name = null) |
43
|
|
|
{ |
44
|
3 |
|
if ($name === null) { |
45
|
3 |
|
$name = $this->getName(); |
46
|
3 |
|
} |
47
|
|
|
|
48
|
3 |
|
if (!$this->hasOptions($container, $key, $name)) { |
49
|
|
|
// @codeCoverageIgnoreStart |
50
|
|
|
throw new RuntimeException( |
51
|
|
|
sprintf( |
52
|
|
|
'Options with name "%s" could not be found in "pami_module.%s".', |
53
|
|
|
$name, |
54
|
|
|
$key |
55
|
|
|
) |
56
|
|
|
); |
57
|
|
|
// @codeCoverageIgnoreEnd |
58
|
|
|
} |
59
|
|
|
|
60
|
3 |
|
$options = $container->get('config'); |
61
|
3 |
|
$options = $options['pami_module']; |
62
|
3 |
|
$options = isset($options[$key][$name]) ? $options[$key][$name] : null; |
63
|
|
|
|
64
|
3 |
|
$optionsClass = $this->getOptionsClass(); |
65
|
|
|
|
66
|
3 |
|
return new $optionsClass($options); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Return if options exists in configuration. |
71
|
|
|
* |
72
|
|
|
* @param ContainerInterface $container Service locator |
73
|
|
|
* @param string $key Service type |
74
|
|
|
* @param string $name Service name |
75
|
|
|
* |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
3 |
|
public function hasOptions(ContainerInterface $container, $key, $name) |
79
|
|
|
{ |
80
|
3 |
|
$options = $container->get('config'); |
81
|
3 |
|
$options = $options['pami_module']; |
82
|
|
|
|
83
|
3 |
|
return isset($options[$key][$name]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Service name. |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
3 |
|
public function getName() |
92
|
|
|
{ |
93
|
3 |
|
return $this->name; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get the class name of the options associated with this factory. |
98
|
|
|
* |
99
|
|
|
* @abstract |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
abstract public function getOptionsClass(); |
104
|
|
|
} |
105
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.