Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
LegacyServiceGateway | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__invoke | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
has | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
isConfigurableService | |
100.00% |
1 / 1 |
|
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) 2021 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
19 | * |
20 | * @author Gabriel Felipe Soares <gabriel.felipe.soares@taotesting.com> |
21 | */ |
22 | |
23 | declare(strict_types=1); |
24 | |
25 | namespace oat\generis\model\DependencyInjection; |
26 | |
27 | use oat\oatbox\service\ConfigurableService; |
28 | use oat\oatbox\service\ServiceManager; |
29 | use Psr\Container\ContainerInterface; |
30 | |
31 | class LegacyServiceGateway implements ContainerInterface |
32 | { |
33 | /** @var ServiceManager|null */ |
34 | private $serviceManager; |
35 | |
36 | public function __construct(ServiceManager $serviceManager = null) |
37 | { |
38 | $this->serviceManager = $serviceManager ?? ServiceManager::getServiceManager(); |
39 | } |
40 | |
41 | public function __invoke($id = null) |
42 | { |
43 | return $id ? $this->serviceManager->get($id) : $this->serviceManager; |
44 | } |
45 | |
46 | /** |
47 | * @inheritDoc |
48 | */ |
49 | public function get($id) |
50 | { |
51 | return $this->serviceManager->get($id); |
52 | } |
53 | |
54 | /** |
55 | * @inheritDoc |
56 | */ |
57 | public function has($id) |
58 | { |
59 | return $this->serviceManager->has($id) || $this->isConfigurableService($id); |
60 | } |
61 | |
62 | private function isConfigurableService($id): bool |
63 | { |
64 | return class_exists($id) && is_subclass_of($id, ConfigurableService::class); |
65 | } |
66 | } |