| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 100.00% | 9 / 9 |  | 100.00% | 3 / 3 | CRAP |  | 100.00% | 1 / 1 | 
| EnvironmentVariableConfigProvider |  | 100.00% | 9 / 9 |  | 100.00% | 3 / 3 | 4 |  | 100.00% | 1 / 1 | 
| __construct |  | 100.00% | 2 / 2 |  | 100.00% | 1 / 1 | 1 | |||
| getConfigByName |  | 100.00% | 6 / 6 |  | 100.00% | 1 / 1 | 2 | |||
| hasConfig |  | 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) 2024 (original work) Open Assessment Technologies SA; | 
| 19 | */ | 
| 20 | |
| 21 | declare(strict_types=1); | 
| 22 | |
| 23 | namespace oat\tao\model\DynamicConfig; | 
| 24 | |
| 25 | use Psr\Log\LoggerInterface; | 
| 26 | |
| 27 | class EnvironmentVariableConfigProvider implements DynamicConfigProviderInterface | 
| 28 | { | 
| 29 | public const ENV_REDIRECT_AFTER_LOGOUT_URL = 'REDIRECT_AFTER_LOGOUT_URL'; | 
| 30 | public const ENV_PORTAL_URL = 'PORTAL_URL'; | 
| 31 | public const ENV_TAO_LOGIN_URL = 'TAO_LOGIN_URL'; | 
| 32 | |
| 33 | private array $configs; | 
| 34 | private LoggerInterface $logger; | 
| 35 | |
| 36 | public function __construct(array $configs, LoggerInterface $logger) | 
| 37 | { | 
| 38 | $this->configs = $configs; | 
| 39 | $this->logger = $logger; | 
| 40 | } | 
| 41 | |
| 42 | public function getConfigByName(string $name): ?string | 
| 43 | { | 
| 44 | if (!in_array($name, self::AVAILABLE_CONFIGS)) { | 
| 45 | $this->logger->warning( | 
| 46 | sprintf('The Authoring As Tool config var with the name %s is not available', $name) | 
| 47 | ); | 
| 48 | return null; | 
| 49 | } | 
| 50 | |
| 51 | return $this->configs[$name] ?? null; | 
| 52 | } | 
| 53 | |
| 54 | public function hasConfig(string $name): bool | 
| 55 | { | 
| 56 | return $this->getConfigByName($name) !== null; | 
| 57 | } | 
| 58 | } |