GetSettingsCommand.php
7 years ago
GetSettingsCommandHandler.php
1 year ago
UpdateSettingsCommand.php
7 years ago
UpdateSettingsCommandHandler.php
1 year ago
GetSettingsCommandHandler.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Commands\Settings; |
| 4 | |
| 5 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 6 | use AmeliaBooking\Application\Commands\CommandResult; |
| 7 | use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException; |
| 8 | use AmeliaBooking\Domain\Entity\Entities; |
| 9 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 10 | use Interop\Container\Exception\ContainerException; |
| 11 | |
| 12 | /** |
| 13 | * Class GetSettingsCommandHandler |
| 14 | * |
| 15 | * @package AmeliaBooking\Application\Commands\Settings |
| 16 | */ |
| 17 | class GetSettingsCommandHandler extends CommandHandler |
| 18 | { |
| 19 | /** |
| 20 | * @return CommandResult |
| 21 | * @throws ContainerException |
| 22 | * @throws AccessDeniedException |
| 23 | */ |
| 24 | public function handle(GetSettingsCommand $command) |
| 25 | { |
| 26 | $result = new CommandResult(); |
| 27 | |
| 28 | if (!$command->getPermissionService()->currentUserCanRead(Entities::SETTINGS)) { |
| 29 | throw new AccessDeniedException('You are not allowed to read settings.'); |
| 30 | } |
| 31 | |
| 32 | /** @var SettingsService $settingsService */ |
| 33 | $settingsService = $this->getContainer()->get('domain.settings.service'); |
| 34 | |
| 35 | $settings = $settingsService->getAllSettingsCategorized(); |
| 36 | |
| 37 | if ($settings['activation']['purchaseCodeStore'] !== '' && $settings['activation']['active']) { |
| 38 | $settings['activation']['purchaseCodeStore'] = null; |
| 39 | } |
| 40 | |
| 41 | if (!empty($settings['payments']['square'])) { |
| 42 | $settings['payments']['square']['phpVersion'] = phpversion(); |
| 43 | } |
| 44 | |
| 45 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 46 | $result->setMessage('Successfully retrieved settings.'); |
| 47 | |
| 48 | $settings = apply_filters('amelia_get_settings_filter', $settings); |
| 49 | |
| 50 | do_action('amelia_get_settings', $settings); |
| 51 | |
| 52 | $result->setData( |
| 53 | [ |
| 54 | 'settings' => $settings |
| 55 | ] |
| 56 | ); |
| 57 | |
| 58 | return $result; |
| 59 | } |
| 60 | } |
| 61 |