Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FeatureFlagChecker | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
4.05 | |
0.00% |
0 / 1 |
| isEnabled | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getFeatureFlagValue | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| 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) 2020-2022 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\featureFlag; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\tao\model\featureFlag\Repository\FeatureFlagRepositoryInterface; |
| 27 | |
| 28 | class FeatureFlagChecker extends ConfigurableService implements FeatureFlagCheckerInterface |
| 29 | { |
| 30 | public function isEnabled(string $feature): bool |
| 31 | { |
| 32 | if (array_key_exists($feature, $_ENV)) { |
| 33 | return filter_var($_ENV[$feature], FILTER_VALIDATE_BOOLEAN) ?? false; |
| 34 | } |
| 35 | |
| 36 | return $this->getFeatureFlagValue($feature); |
| 37 | } |
| 38 | |
| 39 | private function getFeatureFlagValue(string $feature): bool |
| 40 | { |
| 41 | $container = $this->getServiceManager()->getContainer(); |
| 42 | |
| 43 | if ($container->has(FeatureFlagRepositoryInterface::class)) { |
| 44 | return $container->get(FeatureFlagRepositoryInterface::class)->get($feature); |
| 45 | } |
| 46 | |
| 47 | return false; |
| 48 | } |
| 49 | } |