| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 0.00% | 0 / 35 |  | 0.00% | 0 / 2 | CRAP |  | 0.00% | 0 / 1 | 
| AbstractPortableElementRegistry |  | 0.00% | 0 / 35 |  | 0.00% | 0 / 2 | 132 |  | 0.00% | 0 / 1 | 
| getClientModule | n/a | 0 / 0 | n/a | 0 / 0 | 0 | |||||
| registerProvider |  | 0.00% | 0 / 19 |  | 0.00% | 0 / 1 | 56 | |||
| removeProvider |  | 0.00% | 0 / 16 |  | 0.00% | 0 / 1 | 20 | |||
| 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) 2016 (original work) Open Assessment Technologies SA ; | 
| 19 | * | 
| 20 | */ | 
| 21 | |
| 22 | namespace oat\taoQtiItem\model\portableElement\clientConfigRegistry; | 
| 23 | |
| 24 | use oat\tao\model\ClientLibConfigRegistry; | 
| 25 | |
| 26 | /** | 
| 27 | * Class AbstractPortableElementRegistry | 
| 28 | * @package oat\taoQtiItem\model\portableElement\clientConfigRegistry | 
| 29 | * @author Sam <sam@taotesting.com> | 
| 30 | */ | 
| 31 | abstract class AbstractPortableElementRegistry extends ClientLibConfigRegistry | 
| 32 | { | 
| 33 | public const CI_REGISTRY = "taoQtiItem/portableElementRegistry/ciRegistry"; | 
| 34 | |
| 35 | abstract protected function getClientModule(); | 
| 36 | |
| 37 | /** | 
| 38 | * @param $name | 
| 39 | * @param $module | 
| 40 | * @throws \common_exception_InvalidArgumentType | 
| 41 | */ | 
| 42 | public function registerProvider($name, $module) | 
| 43 | { | 
| 44 | if (!is_string($name)) { | 
| 45 | throw new \common_exception_InvalidArgumentType('The registry name must be a string!'); | 
| 46 | } | 
| 47 | if (!is_string($module)) { | 
| 48 | throw new \common_exception_InvalidArgumentType('The registry module must be a string!'); | 
| 49 | } | 
| 50 | |
| 51 | $config = []; | 
| 52 | $registry = self::getRegistry(); | 
| 53 | if ($registry->isRegistered($this->getClientModule())) { | 
| 54 | $config = $registry->get($this->getClientModule()); | 
| 55 | } | 
| 56 | |
| 57 | $entries = []; | 
| 58 | if (isset($config['providers'])) { | 
| 59 | foreach ($config['providers'] as $entry) { | 
| 60 | if ($entry['module'] != $module) { | 
| 61 | $entries[] = $entry; | 
| 62 | } | 
| 63 | } | 
| 64 | } | 
| 65 | |
| 66 | $entries[] = [ | 
| 67 | 'name' => $name, | 
| 68 | 'module' => $module | 
| 69 | ]; | 
| 70 | |
| 71 | $config['providers'] = $entries; | 
| 72 | $registry->set($this->getClientModule(), $config); | 
| 73 | } | 
| 74 | |
| 75 | /** | 
| 76 | * @param $name | 
| 77 | * @param $module | 
| 78 | */ | 
| 79 | public function removeProvider($name, $module) | 
| 80 | { | 
| 81 | $config = []; | 
| 82 | $registry = self::getRegistry(); | 
| 83 | |
| 84 | if ($registry->isRegistered($this->getClientModule())) { | 
| 85 | $config = $registry->get($this->getClientModule()); | 
| 86 | } | 
| 87 | |
| 88 | if (!isset($config['providers'])) { | 
| 89 | return; | 
| 90 | } | 
| 91 | |
| 92 | $entries = $config['providers']; | 
| 93 | |
| 94 | $entry = [ | 
| 95 | 'name' => $name, | 
| 96 | 'module' => $module | 
| 97 | ]; | 
| 98 | |
| 99 | $key = array_search($entry, $entries); | 
| 100 | if (is_numeric($key)) { | 
| 101 | unset($entries[$key]); | 
| 102 | } | 
| 103 | |
| 104 | $config['providers'] = $entries; | 
| 105 | $registry->set($this->getClientModule(), $config); | 
| 106 | } | 
| 107 | } |