Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 14 |
CRAP | |
0.00% |
0 / 1 |
| MetadataRegistry | |
0.00% |
0 / 52 |
|
0.00% |
0 / 14 |
306 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setExtension | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getExtension | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMapping | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| setMapping | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| registerMetadataInjector | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| unregisterMetadataInjector | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| registerMetadataExtractor | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| unregisterMetadataExtractor | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| registerMetadataGuardian | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| unregisterMetadataGuardian | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| registerMetadataClassLookup | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| unregisterMetadataClassLookup | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getServiceManager | |
0.00% |
0 / 1 |
|
0.00% |
0 / 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 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model\qti\metadata; |
| 23 | |
| 24 | use common_ext_Extension; |
| 25 | use common_ext_ExtensionsManager; |
| 26 | use InvalidArgumentException; |
| 27 | use oat\oatbox\service\ServiceManager; |
| 28 | use oat\taoQtiItem\model\qti\metadata\importer\MetadataImporter; |
| 29 | |
| 30 | /** |
| 31 | * @deprecated MetadataService should be used to handle export & import |
| 32 | * |
| 33 | * MetadataRegistry objects enables you to register/unregister |
| 34 | * MetadataExtractor and MetadataInjector objects to be used |
| 35 | * in various situations accross the platform. |
| 36 | * |
| 37 | * @author Jérôme Bogaerts <jerome@taotesting.com> |
| 38 | * @see oat\taoQtiItem\model\qti\metadata\MetadataExtractor The MetadataExtractor interface. |
| 39 | * @see oat\taoQtiItem\model\qti\metadata\MetadataInjector The MetadataInjector interface. |
| 40 | */ |
| 41 | class MetadataRegistry |
| 42 | { |
| 43 | /** |
| 44 | * The key to be used in configuration to retrieve |
| 45 | * or set the class mapping. |
| 46 | * |
| 47 | * @var string |
| 48 | */ |
| 49 | public const CONFIG_ID = 'metadata_registry'; |
| 50 | |
| 51 | /** |
| 52 | * A pointer to the taoQtiItem extension |
| 53 | * |
| 54 | * @var \common_ext_Extension |
| 55 | */ |
| 56 | protected $extension; |
| 57 | |
| 58 | /** |
| 59 | * Create a new MetadataRegistry object. |
| 60 | * |
| 61 | */ |
| 62 | public function __construct() |
| 63 | { |
| 64 | $this->setExtension(common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Set the extension to be used to store the mapping in configuration. |
| 69 | * |
| 70 | * @param common_ext_Extension $extension |
| 71 | */ |
| 72 | protected function setExtension(common_ext_Extension $extension) |
| 73 | { |
| 74 | $this->extension = $extension; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get the extension to be used to store the mapping configuration. |
| 79 | * |
| 80 | * @return common_ext_Extension |
| 81 | */ |
| 82 | protected function getExtension() |
| 83 | { |
| 84 | return $this->extension; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @deprecated Use MetadataService->getImporter() instead to have access to specific instance of metadataImporter |
| 89 | * |
| 90 | * Get the class mapping of Extractor/Injector classes. |
| 91 | * |
| 92 | * @return array An associative array with two main keys. The 'injectors' and 'extractors' and 'guardians' keys |
| 93 | * refer to sub-arrays containing respectively classnames of MetadataInjector and MetadataExtractor |
| 94 | * implementations. |
| 95 | */ |
| 96 | public function getMapping() |
| 97 | { |
| 98 | $instances = $this->getServiceManager() |
| 99 | ->get(MetadataService::SERVICE_ID) |
| 100 | ->getImporter() |
| 101 | ->getOptions(); |
| 102 | |
| 103 | $mapping = []; |
| 104 | foreach ($instances as $key => $helpers) { |
| 105 | if (! isset($mapping[$key])) { |
| 106 | $mapping[$key] = []; |
| 107 | } |
| 108 | foreach ($helpers as $instance) { |
| 109 | $mapping[$key][] = get_class($instance); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return $mapping; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @deprecated use MetadataService->getImporter()->registerService() instead |
| 118 | * |
| 119 | * Set the class mapping of Extractor/Injector classes. |
| 120 | * |
| 121 | * @param array $mapping An associative array with two main keys. The 'injectors' and 'extractors' keys refer |
| 122 | * to sub-arrays containing respectively classnames of MetadataInjector and MetadataExtractor |
| 123 | * implementations. |
| 124 | */ |
| 125 | protected function setMapping(array $mapping) |
| 126 | { |
| 127 | /** @var MetadataService $metadataService */ |
| 128 | $metadataService = $this->getServiceManager()->get(MetadataService::SERVICE_ID); |
| 129 | |
| 130 | $importer = $metadataService->getImporter(); |
| 131 | $importer->setOptions($mapping); |
| 132 | |
| 133 | $metadataService->setOption(MetadataService::IMPORTER_KEY, $importer); |
| 134 | $this->getServiceManager()->register(MetadataService::SERVICE_ID, $metadataService); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * @deprecated use MetadataService->getImporter()->register(MetadataImport::INJECTOR_KEY, $fqcn) |
| 139 | * |
| 140 | * Register a MetadataInjector implementation by $fqcn (Fully Qualified Class Name). |
| 141 | * |
| 142 | * @param string $fqcn A Fully Qualified Class Name. |
| 143 | * @throws InvalidArgumentException If the given $fqcn does not correspond to an implementation of the |
| 144 | * MetadataInjector interface. |
| 145 | * @see oat\taoQtiItem\model\qti\metadata\MetadataInjector The MetadataInjector interface. |
| 146 | */ |
| 147 | public function registerMetadataInjector($fqcn) |
| 148 | { |
| 149 | $this->getServiceManager() |
| 150 | ->get(MetadataService::SERVICE_ID) |
| 151 | ->getImporter() |
| 152 | ->register(MetadataImporter::INJECTOR_KEY, $fqcn); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @deprecated use MetadataService->getImporter()->unregister(MetadataImport::INJECTOR_KEY, $fqcn) |
| 157 | * |
| 158 | * Unregister a MetadataInjector implementation by $fqcn (Fully Qualified Class Name). |
| 159 | * |
| 160 | * @param string $fqcn A Fully Qualified Class Name. |
| 161 | * @see oat\taoQtiItem\model\qti\metadata\MetadataInjector The MetadataInjector interface. |
| 162 | */ |
| 163 | public function unregisterMetadataInjector($fqcn) |
| 164 | { |
| 165 | $this->getServiceManager() |
| 166 | ->get(MetadataService::SERVICE_ID) |
| 167 | ->getImporter() |
| 168 | ->unregister(MetadataImporter::INJECTOR_KEY, $fqcn); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * @deprecated use MetadataService->getImporter()->register(MetadataImport::EXTRACTOR_KEY, $fqcn) |
| 173 | * |
| 174 | * Register a MetadataExtractor implementation by $fqcn (Fully Qualified Class Name). |
| 175 | * |
| 176 | * @param string $fqcn A Fully Qualified Class Name. |
| 177 | * @throws InvalidArgumentException If the given $fqcn does not correspond to an implementation of the |
| 178 | * MetadataExtractor interface. |
| 179 | * @see oat\taoQtiItem\model\qti\metadata\MetadataExtractor The MetadataExtractor interface. |
| 180 | */ |
| 181 | public function registerMetadataExtractor($fqcn) |
| 182 | { |
| 183 | $this->getServiceManager() |
| 184 | ->get(MetadataService::SERVICE_ID) |
| 185 | ->getImporter() |
| 186 | ->register(MetadataImporter::EXTRACTOR_KEY, $fqcn); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * @deprecated use MetadataService->getImporter()->unregister(MetadataImport::EXTRACTOR_KEY, $fqcn) |
| 191 | * |
| 192 | * Unregister a MetadataExtractor implementation by $fqcn (Fully Qualified Class Name). |
| 193 | * |
| 194 | * @param string $fqcn A Fully Qualified Class Name. |
| 195 | * @see oat\taoQtiItem\model\qti\metadata\MetadataExtractor The MetadataExtractor interface. |
| 196 | */ |
| 197 | public function unregisterMetadataExtractor($fqcn) |
| 198 | { |
| 199 | $this->getServiceManager() |
| 200 | ->get(MetadataService::SERVICE_ID) |
| 201 | ->getImporter() |
| 202 | ->unregister(MetadataImporter::EXTRACTOR_KEY, $fqcn); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * @deprecated use MetadataService->getImporter()->register(MetadataImport::GUARDIAN_KEY, $fqcn) |
| 207 | * |
| 208 | * Register a MetadataGuardian implementation by $fqcn (Fully Qualified Class Name). |
| 209 | * |
| 210 | * @param string $fqcn A Fully Qualified Class Name. |
| 211 | * @throws InvalidArgumentException If the given $fqcn does not correspond to an implementation of the |
| 212 | * MetadataGuardian interface. |
| 213 | * @see oat\taoQtiItem\model\qti\metadata\MetadataGuardian The MetadataExtractor interface. |
| 214 | */ |
| 215 | public function registerMetadataGuardian($fqcn) |
| 216 | { |
| 217 | $this->getServiceManager() |
| 218 | ->get(MetadataService::SERVICE_ID) |
| 219 | ->getImporter() |
| 220 | ->register(MetadataImporter::GUARDIAN_KEY, $fqcn); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * @deprecated use MetadataService->getImporter()->unregister(MetadataImport::GUARDIAN_KEY, $fqcn) |
| 225 | * |
| 226 | * Unregister a MetadataGuardian implementation by $fqcn (Fully Qualified Class Name). |
| 227 | * |
| 228 | * @param string $fqcn A Fully Qualified Class Name. |
| 229 | * @see oat\taoQtiItem\model\qti\metadata\MetadataGuardian The MetadataGuardian interface. |
| 230 | */ |
| 231 | public function unregisterMetadataGuardian($fqcn) |
| 232 | { |
| 233 | $this->getServiceManager() |
| 234 | ->get(MetadataService::SERVICE_ID) |
| 235 | ->getImporter() |
| 236 | ->unregister(MetadataImporter::GUARDIAN_KEY, $fqcn); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @deprecated use MetadataService->getImporter()->register(MetadataImport::CLASS_LOOKUP_KEY, $fqcn) |
| 241 | * |
| 242 | * Register a MetadataClassLookup implementation by $fqcn (Fully Qualified Class Name). |
| 243 | * |
| 244 | * @param string $fqcn A Fully Qualified Class Name. |
| 245 | * @throws InvalidArgumentException If the given $fqcn does not correspond to an implementation of the |
| 246 | * MetadataClassLookup interface. |
| 247 | * @see oat\taoQtiItem\model\qti\metadata\MetadataClassLookup The MetadataClassLookup interface. |
| 248 | */ |
| 249 | public function registerMetadataClassLookup($fqcn) |
| 250 | { |
| 251 | $this->getServiceManager() |
| 252 | ->get(MetadataService::SERVICE_ID) |
| 253 | ->getImporter() |
| 254 | ->register(MetadataImporter::CLASS_LOOKUP_KEY, $fqcn); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * @deprecated use MetadataService->getImporter()->unregister(MetadataImport::CLASS_LOOKUP_KEY, $fqcn) |
| 259 | * |
| 260 | * Unregister a MetadataClassLookup implementation by $fqcn (Fully Qualified Class Name). |
| 261 | * |
| 262 | * @param string $fqcn A Fully Qualified Class Name. |
| 263 | * @see oat\taoQtiItem\model\qti\metadata\MetadataClassLookup The MetadataClassLookup interface. |
| 264 | */ |
| 265 | public function unregisterMetadataClassLookup($fqcn) |
| 266 | { |
| 267 | $this->getServiceManager() |
| 268 | ->get(MetadataService::SERVICE_ID) |
| 269 | ->getImporter() |
| 270 | ->unregister(MetadataImporter::CLASS_LOOKUP_KEY, $fqcn); |
| 271 | } |
| 272 | |
| 273 | protected function getServiceManager() |
| 274 | { |
| 275 | return ServiceManager::getServiceManager(); |
| 276 | } |
| 277 | } |