Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
66.67% |
10 / 15 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
Configurable | |
66.67% |
10 / 15 |
|
85.71% |
6 / 7 |
15.48 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setOption | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setOptions | |
28.57% |
2 / 7 |
|
0.00% |
0 / 1 |
9.83 | |||
hasOption | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOption | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOptions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__toPhpCode | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2014-2021 (original work) Open Assessment Technologies SA; |
19 | */ |
20 | |
21 | namespace oat\oatbox; |
22 | |
23 | use oat\oatbox\log\LoggerAwareTrait; |
24 | use oat\oatbox\log\TaoLoggerAwareInterface; |
25 | |
26 | /** |
27 | * Configurable base class |
28 | * |
29 | * inspired by Solarium\Core\Configurable by Bas de Nooijer |
30 | * https://github.com/basdenooijer/solarium/blob/master/library/Solarium/Core/Configurable.php |
31 | * |
32 | * @author Joel Bout <joel@taotesting.com> |
33 | * @deprecated New services must be registered using Dependency Injection Container |
34 | */ |
35 | abstract class Configurable implements PhpSerializable, TaoLoggerAwareInterface |
36 | { |
37 | use LoggerAwareTrait; |
38 | |
39 | /** @var array */ |
40 | private $options = []; |
41 | |
42 | /** |
43 | * public constructor to allow the object to be recreated from php code |
44 | * |
45 | * @param array $options |
46 | * @deprecated New services must be registered using Dependency Injection Container |
47 | */ |
48 | public function __construct($options = []) |
49 | { |
50 | $this->setOptions($options); |
51 | } |
52 | |
53 | /** |
54 | * @deprecated Use \oat\generis\model\DependencyInjection\ServiceOptions instead |
55 | */ |
56 | public function setOption($name, $value) |
57 | { |
58 | $this->options[$name] = $value; |
59 | } |
60 | |
61 | /** |
62 | * Set options |
63 | * |
64 | * @param array $options |
65 | * @return void |
66 | * @throws \common_exception_Error |
67 | * @deprecated Use \oat\generis\model\DependencyInjection\ServiceOptions instead |
68 | */ |
69 | public function setOptions(array $options) |
70 | { |
71 | if (!is_array($options)) { |
72 | if (is_object($options) && method_exists($options, 'toArray')) { |
73 | $options = $options->toArray(); |
74 | } else { |
75 | throw new \common_exception_Error( |
76 | 'Options submitted to ' . get_called_class() . ' must be an array or implement toArray' |
77 | ); |
78 | } |
79 | } |
80 | $this->options = $options; |
81 | } |
82 | |
83 | /** |
84 | * Returns whenever or not the option is defined |
85 | * |
86 | * @param string $name |
87 | * @return boolean |
88 | * @deprecated Use \oat\generis\model\DependencyInjection\ServiceOptions instead |
89 | */ |
90 | public function hasOption($name) |
91 | { |
92 | return isset($this->options[$name]); |
93 | } |
94 | |
95 | /** |
96 | * Get an option value by name |
97 | * |
98 | * If the option is not set a default value will be returned. |
99 | * |
100 | * @param string $name |
101 | * @param mixed|null $default Default value to return if option is not set. |
102 | * @return mixed |
103 | * @deprecated Use \oat\generis\model\DependencyInjection\ServiceOptions instead |
104 | */ |
105 | public function getOption($name, $default = null) |
106 | { |
107 | return $this->options[$name] ?? $default; |
108 | } |
109 | |
110 | /** |
111 | * Get all options |
112 | * |
113 | * @return array |
114 | * @deprecated Use \oat\generis\model\DependencyInjection\ServiceOptions instead |
115 | */ |
116 | public function getOptions() |
117 | { |
118 | return $this->options; |
119 | } |
120 | |
121 | /** |
122 | * (non-PHPdoc) |
123 | * @see \oat\oatbox\PhpSerializable::__toPhpCode() |
124 | * @deprecated Use \oat\generis\model\DependencyInjection\ServiceOptions instead |
125 | */ |
126 | public function __toPhpCode() |
127 | { |
128 | $options = $this->getOptions(); |
129 | $params = empty($options) ? '' : \common_Utils::toHumanReadablePhpString($options); |
130 | return 'new ' . get_class($this) . '(' . $params . ')'; |
131 | } |
132 | } |