Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ServiceOptions | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| save | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| remove | |
100.00% |
5 / 5 |
|
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 | |
| 29 | /** |
| 30 | * @notice It is NOT RECOMMENDED to use this class. New services on container should rely on ENVIRONMENT VARIABLES, |
| 31 | * but when this is really not possible and OO techniques like, Proxy, Factory, Strategy cannot solve the |
| 32 | * issue than MAYBE this class can be used. |
| 33 | */ |
| 34 | final class ServiceOptions extends ConfigurableService implements ServiceOptionsInterface |
| 35 | { |
| 36 | public const SERVICE_ID = 'generis/ServiceOptions'; |
| 37 | |
| 38 | public function save(string $serviceId, string $option, $value): ServiceOptionsInterface |
| 39 | { |
| 40 | $mainOption = parent::getOption($serviceId, []); |
| 41 | $mainOption[$option] = $value; |
| 42 | |
| 43 | parent::setOption($serviceId, $mainOption); |
| 44 | |
| 45 | return $this; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @inheritDoc |
| 50 | */ |
| 51 | public function get(string $serviceId, string $option, $default = null) |
| 52 | { |
| 53 | return parent::getOption($serviceId, [])[$option] ?? $default; |
| 54 | } |
| 55 | |
| 56 | public function remove(string $serviceId, string $option): ServiceOptionsInterface |
| 57 | { |
| 58 | $allOptions = parent::getOption($serviceId, []); |
| 59 | |
| 60 | if (isset($allOptions[$option])) { |
| 61 | unset($allOptions[$option]); |
| 62 | } |
| 63 | |
| 64 | parent::setOption($serviceId, $allOptions); |
| 65 | |
| 66 | return $this; |
| 67 | } |
| 68 | } |