Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
66.67% |
10 / 15 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ContainerStarter | |
66.67% |
10 / 15 |
|
33.33% |
1 / 3 |
10.37 | |
0.00% |
0 / 1 |
| __construct | |
66.67% |
4 / 6 |
|
0.00% |
0 / 1 |
4.59 | |||
| getContainer | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getContainerBuilder | |
100.00% |
6 / 6 |
|
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 LogicException; |
| 28 | use Psr\Container\ContainerInterface; |
| 29 | |
| 30 | final class ContainerStarter |
| 31 | { |
| 32 | /** @var ContainerInterface */ |
| 33 | private $container; |
| 34 | |
| 35 | /** @var ContainerBuilder */ |
| 36 | private $containerBuilder; |
| 37 | |
| 38 | /** @var ContainerInterface */ |
| 39 | private $legacyContainer; |
| 40 | |
| 41 | /** @var string|null */ |
| 42 | private $cachePath; |
| 43 | |
| 44 | public function __construct( |
| 45 | ContainerInterface $legacyContainer, |
| 46 | string $cachePath = null |
| 47 | ) { |
| 48 | if (!$cachePath) { |
| 49 | $cachePath = defined('GENERIS_CACHE_PATH') ? GENERIS_CACHE_PATH : null; |
| 50 | } |
| 51 | |
| 52 | if (!$cachePath) { |
| 53 | throw new LogicException('Required application constants were not initialized!'); |
| 54 | } |
| 55 | |
| 56 | $this->legacyContainer = $legacyContainer; |
| 57 | $this->cachePath = $cachePath; |
| 58 | } |
| 59 | |
| 60 | public function getContainer(): ContainerInterface |
| 61 | { |
| 62 | if (!$this->container) { |
| 63 | $this->container = $this->getContainerBuilder()->build(); |
| 64 | } |
| 65 | |
| 66 | return $this->container; |
| 67 | } |
| 68 | |
| 69 | public function getContainerBuilder(): ContainerBuilder |
| 70 | { |
| 71 | if (!$this->containerBuilder) { |
| 72 | $this->containerBuilder = new ContainerBuilder( |
| 73 | $this->cachePath, |
| 74 | $this->legacyContainer |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | return $this->containerBuilder; |
| 79 | } |
| 80 | } |