Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| PermissionsServiceFactory | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| create | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getDataBaseAccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPermissionsStrategy | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| getEventManager | |
0.00% |
0 / 1 |
|
0.00% |
0 / 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) 2020-2023 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoDacSimple\model; |
| 24 | |
| 25 | use oat\oatbox\event\EventManager; |
| 26 | use oat\oatbox\service\ConfigurableService; |
| 27 | use RuntimeException; |
| 28 | |
| 29 | class PermissionsServiceFactory extends ConfigurableService |
| 30 | { |
| 31 | public const SERVICE_ID = 'taoDacSimple/PermissionsService'; |
| 32 | public const OPTION_SAVE_STRATEGY = 'save_strategy'; |
| 33 | public const OPTION_RECURSIVE_BY_DEFAULT = 'recursive_by_default'; |
| 34 | |
| 35 | public function create(): ChangePermissionsService |
| 36 | { |
| 37 | return new ChangePermissionsService( |
| 38 | $this->getDataBaseAccess(), |
| 39 | $this->getPermissionsStrategy(), |
| 40 | $this->getEventManager() |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | private function getDataBaseAccess(): DataBaseAccess |
| 45 | { |
| 46 | return $this->serviceLocator->get(DataBaseAccess::SERVICE_ID); |
| 47 | } |
| 48 | |
| 49 | private function getPermissionsStrategy(): PermissionsStrategyInterface |
| 50 | { |
| 51 | $strategyClass = $this->getOption(self::OPTION_SAVE_STRATEGY); |
| 52 | |
| 53 | if ($strategyClass === null) { |
| 54 | throw new RuntimeException( |
| 55 | sprintf( |
| 56 | 'Option %s is not configured. Please check %s', |
| 57 | self::OPTION_SAVE_STRATEGY, |
| 58 | self::SERVICE_ID |
| 59 | ) |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | return new $strategyClass(); |
| 64 | } |
| 65 | |
| 66 | private function getEventManager(): EventManager |
| 67 | { |
| 68 | return $this->serviceLocator->get(EventManager::SERVICE_ID); |
| 69 | } |
| 70 | } |