Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| BaseContainer | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| get | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| has | |
0.00% |
0 / 1 |
|
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) 2021-2025 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\generis\model\DependencyInjection; |
| 24 | |
| 25 | use Psr\Container\ContainerInterface; |
| 26 | use Psr\Container\NotFoundExceptionInterface; |
| 27 | use Symfony\Component\DependencyInjection\Container; |
| 28 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
| 29 | |
| 30 | /** |
| 31 | * @note Class used only to help load not supported services from container. |
| 32 | * Please DO NOT use it for other purposes. |
| 33 | * |
| 34 | * @internal |
| 35 | */ |
| 36 | class BaseContainer extends Container |
| 37 | { |
| 38 | /** @var LegacyServiceGateway|null */ |
| 39 | private $legacyContainer; |
| 40 | |
| 41 | public function __construct(ParameterBagInterface $parameterBag = null, ContainerInterface $legacyContainer = null) |
| 42 | { |
| 43 | parent::__construct($parameterBag); |
| 44 | |
| 45 | $this->legacyContainer = $legacyContainer ?? new LegacyServiceGateway(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @inheritDoc |
| 50 | */ |
| 51 | public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) |
| 52 | { |
| 53 | try { |
| 54 | return parent::get($id, self::NULL_ON_INVALID_REFERENCE) ?? $this->legacyContainer->get($id); |
| 55 | } catch (NotFoundExceptionInterface $exception) { |
| 56 | if ($invalidBehavior >= self::NULL_ON_INVALID_REFERENCE) { |
| 57 | return null; |
| 58 | } |
| 59 | |
| 60 | throw $exception; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @inheritDoc |
| 66 | */ |
| 67 | public function has($id) |
| 68 | { |
| 69 | return parent::has($id) || $this->legacyContainer->has($id); |
| 70 | } |
| 71 | } |