Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| AbstractRegistry | |
0.00% |
0 / 15 |
|
0.00% |
0 / 8 |
132 | |
0.00% |
0 / 1 |
| getRegistry | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getExtension | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getConfigId | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| remove | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getMap | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| set | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| isRegistered | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| 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 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\oatbox; |
| 23 | |
| 24 | use oat\oatbox\service\ConfigurableService; |
| 25 | use oat\oatbox\service\ServiceManager; |
| 26 | use common_ext_Extension; |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * Registry allows any extension to store specific arrays of data into extension config file |
| 31 | * |
| 32 | * @author Lionel Lecaque <lionel@taotesting.com> |
| 33 | */ |
| 34 | abstract class AbstractRegistry extends ConfigurableService |
| 35 | { |
| 36 | /** |
| 37 | * |
| 38 | * @author Lionel Lecaque, lionel@taotesting.com |
| 39 | * @return AbstractRegistry |
| 40 | */ |
| 41 | public static function getRegistry() |
| 42 | { |
| 43 | return ServiceManager::getServiceManager()->get(get_called_class()); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Specify in which extensions the config will be stored |
| 48 | * |
| 49 | * @author Lionel Lecaque, lionel@taotesting.com |
| 50 | * @return common_ext_Extension |
| 51 | */ |
| 52 | abstract protected function getExtension(); |
| 53 | |
| 54 | /** |
| 55 | * |
| 56 | * config file in which the data will be stored |
| 57 | * |
| 58 | * @author Lionel Lecaque, lionel@taotesting.com |
| 59 | * @return string |
| 60 | */ |
| 61 | abstract protected function getConfigId(); |
| 62 | |
| 63 | /** |
| 64 | * |
| 65 | * Get the config of dedicated extensions |
| 66 | * |
| 67 | * @author Lionel Lecaque, lionel@taotesting.com |
| 68 | */ |
| 69 | protected function getConfig() |
| 70 | { |
| 71 | return $this->getExtension()->getConfig($this->getConfigId()); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * |
| 76 | * @author Lionel Lecaque, lionel@taotesting.com |
| 77 | * @param array $map |
| 78 | */ |
| 79 | protected function setConfig($map) |
| 80 | { |
| 81 | $this->getExtension()->setConfig($this->getConfigId(), $map); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * |
| 86 | * Remove a element from the array |
| 87 | * |
| 88 | * @author Lionel Lecaque, lionel@taotesting.com |
| 89 | * @param string $id |
| 90 | */ |
| 91 | public function remove($id) |
| 92 | { |
| 93 | $map = $this->getMap(); |
| 94 | if (isset($map[$id])) { |
| 95 | unset($map[$id]); |
| 96 | $this->setConfig($map); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Get the complete array |
| 102 | * |
| 103 | * @author Lionel Lecaque, lionel@taotesting.com |
| 104 | * @return array |
| 105 | */ |
| 106 | public function getMap() |
| 107 | { |
| 108 | $map = $this->getConfig(); |
| 109 | return is_array($map) ? $map : []; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Add a value to the config with given id |
| 114 | * |
| 115 | * @author Lionel Lecaque, lionel@taotesting.com |
| 116 | * @param string $id |
| 117 | * @param string $value |
| 118 | */ |
| 119 | public function set($id, $value) |
| 120 | { |
| 121 | $map = $this->getMap(); |
| 122 | $map[$id] = $value; |
| 123 | $this->setConfig($map); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Check if the config element exist |
| 128 | * |
| 129 | * @author Lionel Lecaque, lionel@taotesting.com |
| 130 | * @param unknown $id |
| 131 | */ |
| 132 | public function isRegistered($id) |
| 133 | { |
| 134 | return array_key_exists($id, $this->getMap()); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | /** |
| 139 | * |
| 140 | * Retrieve the given element from the array in config |
| 141 | * |
| 142 | * @author Lionel Lecaque, lionel@taotesting.com |
| 143 | * @param string $id |
| 144 | * @return string |
| 145 | */ |
| 146 | public function get($id) |
| 147 | { |
| 148 | $map = $this->getMap(); |
| 149 | return isset($map[$id]) ? $map[$id] : ''; |
| 150 | } |
| 151 | } |