Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
93.33% |
14 / 15 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ClassMetadataSearcherProxy | |
93.33% |
14 / 15 |
|
50.00% |
1 / 2 |
4.00 | |
0.00% |
0 / 1 |
| findAll | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
3.00 | |||
| getClassMetadataSearcher | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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) 2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\Lists\Business\Service; |
| 24 | |
| 25 | use oat\generis\model\OntologyAwareTrait; |
| 26 | use oat\oatbox\service\ConfigurableService; |
| 27 | use oat\tao\model\Lists\Business\Contract\ClassMetadataSearcherInterface; |
| 28 | use oat\tao\model\Lists\Business\Domain\ClassCollection; |
| 29 | use oat\tao\model\Lists\Business\Input\ClassMetadataSearchInput; |
| 30 | use Throwable; |
| 31 | |
| 32 | class ClassMetadataSearcherProxy extends ConfigurableService implements ClassMetadataSearcherInterface |
| 33 | { |
| 34 | use OntologyAwareTrait; |
| 35 | |
| 36 | public const SERVICE_ID = 'tao/ClassMetadataSearcherProxy'; |
| 37 | public const OPTION_ACTIVE_SEARCHER = 'activeSearcher'; |
| 38 | |
| 39 | public function findAll(ClassMetadataSearchInput $input): ClassCollection |
| 40 | { |
| 41 | $activeSearcherId = $this->getOption(self::OPTION_ACTIVE_SEARCHER, ClassMetadataService::SERVICE_ID); |
| 42 | |
| 43 | try { |
| 44 | /** @var ClassMetadataSearcherInterface $searcher */ |
| 45 | $searcher = $this->getServiceLocator()->get($activeSearcherId); |
| 46 | |
| 47 | return $searcher->findAll($input); |
| 48 | } catch (Throwable $exception) { |
| 49 | $this->logCritical( |
| 50 | sprintf( |
| 51 | 'Impossible to perform class metadata search with %s: %s', |
| 52 | $activeSearcherId, |
| 53 | $exception->getMessage() |
| 54 | ) |
| 55 | ); |
| 56 | |
| 57 | if ($activeSearcherId !== ClassMetadataService::SERVICE_ID) { |
| 58 | return $this->getClassMetadataSearcher()->findAll($input); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return new ClassCollection(...[]); |
| 63 | } |
| 64 | |
| 65 | private function getClassMetadataSearcher(): ClassMetadataSearcherInterface |
| 66 | { |
| 67 | return $this->getServiceLocator()->get(ClassMetadataService::SERVICE_ID); |
| 68 | } |
| 69 | } |