From e6ef65c6421c52ac870501c7f5f402102e4ec336 Mon Sep 17 00:00:00 2001 From: mattamon Date: Thu, 16 May 2024 08:46:38 +0200 Subject: [PATCH 1/4] Add system settings controller --- config/settings.yaml | 12 ++++ .../PimcoreStudioBackendExtension.php | 1 + src/OpenApi/Config/Tags.php | 5 ++ src/Setting/Controller/GetController.php | 66 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 config/settings.yaml create mode 100644 src/Setting/Controller/GetController.php diff --git a/config/settings.yaml b/config/settings.yaml new file mode 100644 index 000000000..c646a2074 --- /dev/null +++ b/config/settings.yaml @@ -0,0 +1,12 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + # controllers are imported separately to make sure they're public + # and have a tag that allows actions to type-hint services + Pimcore\Bundle\StudioBackendBundle\Setting\Controller\: + resource: '../src/Setting/Controller' + public: true + tags: [ 'controller.service_arguments' ] \ No newline at end of file diff --git a/src/DependencyInjection/PimcoreStudioBackendExtension.php b/src/DependencyInjection/PimcoreStudioBackendExtension.php index 4dc56ec00..a7b931793 100644 --- a/src/DependencyInjection/PimcoreStudioBackendExtension.php +++ b/src/DependencyInjection/PimcoreStudioBackendExtension.php @@ -61,6 +61,7 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('open_api.yaml'); $loader->load('security.yaml'); $loader->load('services.yaml'); + $loader->load('settings.yaml'); $loader->load('translation.yaml'); $loader->load('versions.yaml'); diff --git a/src/OpenApi/Config/Tags.php b/src/OpenApi/Config/Tags.php index 7955ec957..c69486f3d 100644 --- a/src/OpenApi/Config/Tags.php +++ b/src/OpenApi/Config/Tags.php @@ -37,6 +37,10 @@ name: Tags::Translation->name, description: 'Get translations either for a single key or multiple keys' )] +#[Tag( + name: Tags::Settings->name, + description: 'Get Settings' +)] #[Tag( name: Tags::Versions->name, description: 'Versions operations to get/list/publish/delete and cleanup versions' @@ -46,6 +50,7 @@ enum Tags case Assets; case Authorization; case DataObjects; + case Settings; case Translation; case Versions; } diff --git a/src/Setting/Controller/GetController.php b/src/Setting/Controller/GetController.php new file mode 100644 index 000000000..e4fe498f7 --- /dev/null +++ b/src/Setting/Controller/GetController.php @@ -0,0 +1,66 @@ +name] + )] + #[SuccessResponse( + description: 'System settings', + content: new JsonContent(type: 'object', additionalProperties: true) + )] + #[MethodNotAllowedResponse] + #[UnsupportedMediaTypeResponse] + #[UnprocessableContentResponse] + public function getSystemSettings(): JsonResponse + { + return $this->jsonResponse($this->systemSettingsConfig->getSystemSettingsConfig()); + } +} \ No newline at end of file From 34988e0dc54149c149e02b0e9b8362c2751aea70 Mon Sep 17 00:00:00 2001 From: mattamon Date: Thu, 16 May 2024 15:32:48 +0200 Subject: [PATCH 2/4] Add settings provider concept --- config/settings.yaml | 15 +++++- .../CompilerPass/SettingsProviderPass.php | 47 ++++++++++++++++++ src/PimcoreStudioBackendBundle.php | 2 + src/Setting/Controller/GetController.php | 9 ++-- .../Provider/ConfigSettingsProvider.php | 43 +++++++++++++++++ .../Provider/SettingsProviderInterface.php | 25 ++++++++++ .../Provider/SystemSettingsProvider.php | 48 +++++++++++++++++++ .../Service/Loader/TaggedIteratorAdapter.php | 39 +++++++++++++++ .../SettingProviderLoaderInterface.php | 25 ++++++++++ src/Setting/Service/SettingsService.php | 41 ++++++++++++++++ .../Service/SettingsServiceInterface.php | 25 ++++++++++ 11 files changed, 315 insertions(+), 4 deletions(-) create mode 100644 src/DependencyInjection/CompilerPass/SettingsProviderPass.php create mode 100644 src/Setting/Provider/ConfigSettingsProvider.php create mode 100644 src/Setting/Provider/SettingsProviderInterface.php create mode 100644 src/Setting/Provider/SystemSettingsProvider.php create mode 100644 src/Setting/Service/Loader/TaggedIteratorAdapter.php create mode 100644 src/Setting/Service/SettingProviderLoaderInterface.php create mode 100644 src/Setting/Service/SettingsService.php create mode 100644 src/Setting/Service/SettingsServiceInterface.php diff --git a/config/settings.yaml b/config/settings.yaml index c646a2074..a59d6ee5a 100644 --- a/config/settings.yaml +++ b/config/settings.yaml @@ -9,4 +9,17 @@ services: Pimcore\Bundle\StudioBackendBundle\Setting\Controller\: resource: '../src/Setting/Controller' public: true - tags: [ 'controller.service_arguments' ] \ No newline at end of file + tags: [ 'controller.service_arguments' ] + + + Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingProviderLoaderInterface: + class: Pimcore\Bundle\StudioBackendBundle\Setting\Service\Loader\TaggedIteratorAdapter + + Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingsServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingsService + + Pimcore\Bundle\StudioBackendBundle\Setting\Provider\ConfigSettingsProvider: + tags: [ 'pimcore.studio_api.settings_provider' ] + + Pimcore\Bundle\StudioBackendBundle\Setting\Provider\SystemSettingsProvider: + tags: [ 'pimcore.studio_api.settings_provider' ] \ No newline at end of file diff --git a/src/DependencyInjection/CompilerPass/SettingsProviderPass.php b/src/DependencyInjection/CompilerPass/SettingsProviderPass.php new file mode 100644 index 000000000..5dce53e38 --- /dev/null +++ b/src/DependencyInjection/CompilerPass/SettingsProviderPass.php @@ -0,0 +1,47 @@ +findTaggedServiceIds(TaggedIteratorAdapter::SETTINGS_PROVIDER_TAG), + ); + + foreach ($taggedServices as $environmentType) { + $this->checkInterface($environmentType, SettingsProviderInterface::class); + } + } +} diff --git a/src/PimcoreStudioBackendBundle.php b/src/PimcoreStudioBackendBundle.php index ebdb5435a..c27464c83 100644 --- a/src/PimcoreStudioBackendBundle.php +++ b/src/PimcoreStudioBackendBundle.php @@ -19,6 +19,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\PimcoreGenericDataIndexBundle; use Pimcore\Bundle\StaticResolverBundle\PimcoreStaticResolverBundle; use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\FilterPass; +use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\SettingsProviderPass; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; use Pimcore\Extension\Bundle\Installer\InstallerInterface; use Pimcore\HttpKernel\Bundle\DependentBundleInterface; @@ -63,6 +64,7 @@ public function getInstaller(): ?InstallerInterface public function build(ContainerBuilder $container): void { $container->addCompilerPass(new FilterPass()); + $container->addCompilerPass(new SettingsProviderPass()); } public static function registerDependentBundles(BundleCollection $collection): void diff --git a/src/Setting/Controller/GetController.php b/src/Setting/Controller/GetController.php index e4fe498f7..4b67b2426 100644 --- a/src/Setting/Controller/GetController.php +++ b/src/Setting/Controller/GetController.php @@ -18,12 +18,15 @@ use OpenApi\Attributes\Get; use OpenApi\Attributes\JsonContent; +use Pimcore\Bundle\AdminBundle\System\AdminConfig; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnsupportedMediaTypeResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; +use Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingsServiceInterface; +use Pimcore\Config; use Pimcore\SystemSettingsConfig; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Routing\Attribute\Route; @@ -34,11 +37,11 @@ */ final class GetController extends AbstractApiController { - private const ROUTE = '/system-settings'; + private const ROUTE = '/settings'; public function __construct( SerializerInterface $serializer, - private readonly SystemSettingsConfig $systemSettingsConfig + private readonly SettingsServiceInterface $settingsService, ) { parent::__construct($serializer); } @@ -61,6 +64,6 @@ public function __construct( #[UnprocessableContentResponse] public function getSystemSettings(): JsonResponse { - return $this->jsonResponse($this->systemSettingsConfig->getSystemSettingsConfig()); + return $this->jsonResponse($this->settingsService->getSettings()); } } \ No newline at end of file diff --git a/src/Setting/Provider/ConfigSettingsProvider.php b/src/Setting/Provider/ConfigSettingsProvider.php new file mode 100644 index 000000000..94fde67ab --- /dev/null +++ b/src/Setting/Provider/ConfigSettingsProvider.php @@ -0,0 +1,43 @@ + $this->config['assets']['tree_paging_limit'], + 'document_tree_paging_limit' => $this->config['documents']['tree_paging_limit'], + 'object_tree_paging_limit' => $this->config['objects']['tree_paging_limit'], + 'timezone' => $this->config['general']['timezone'], + ]; + + } +} \ No newline at end of file diff --git a/src/Setting/Provider/SettingsProviderInterface.php b/src/Setting/Provider/SettingsProviderInterface.php new file mode 100644 index 000000000..a8562d4f9 --- /dev/null +++ b/src/Setting/Provider/SettingsProviderInterface.php @@ -0,0 +1,25 @@ +systemSettings = $systemSettingsConfig->getSystemSettingsConfig(); + } + + public function getSettings(): array + { + $requiredLanguages = + $this->systemSettings['general']['required_languages'] ?? + $this->systemSettings['general']['valid_languages']; + + + return [ + 'requiredLanguages' => $requiredLanguages, + 'debug_admin_translations' => (bool)$this->systemSettings['general']['debug_admin_translations'], + 'main_domain' => $this->systemSettings['general']['domain'], + ]; + } +} \ No newline at end of file diff --git a/src/Setting/Service/Loader/TaggedIteratorAdapter.php b/src/Setting/Service/Loader/TaggedIteratorAdapter.php new file mode 100644 index 000000000..0786c56cb --- /dev/null +++ b/src/Setting/Service/Loader/TaggedIteratorAdapter.php @@ -0,0 +1,39 @@ +taggedSettingProviders]; + } +} diff --git a/src/Setting/Service/SettingProviderLoaderInterface.php b/src/Setting/Service/SettingProviderLoaderInterface.php new file mode 100644 index 000000000..368b0fa98 --- /dev/null +++ b/src/Setting/Service/SettingProviderLoaderInterface.php @@ -0,0 +1,25 @@ +settingProviderLoader->loadSettingProviders() as $settingProvider) { + $settings = [ + ... $settings, + ... $settingProvider->getSettings() + ]; + } + return $settings; + } +} \ No newline at end of file diff --git a/src/Setting/Service/SettingsServiceInterface.php b/src/Setting/Service/SettingsServiceInterface.php new file mode 100644 index 000000000..c6159301b --- /dev/null +++ b/src/Setting/Service/SettingsServiceInterface.php @@ -0,0 +1,25 @@ + Date: Thu, 16 May 2024 13:35:05 +0000 Subject: [PATCH 3/4] Apply php-cs-fixer changes --- src/DependencyInjection/CompilerPass/SettingsProviderPass.php | 1 - src/Setting/Provider/SettingsProviderInterface.php | 2 +- src/Setting/Service/SettingsServiceInterface.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/DependencyInjection/CompilerPass/SettingsProviderPass.php b/src/DependencyInjection/CompilerPass/SettingsProviderPass.php index 5dce53e38..805c34572 100644 --- a/src/DependencyInjection/CompilerPass/SettingsProviderPass.php +++ b/src/DependencyInjection/CompilerPass/SettingsProviderPass.php @@ -16,7 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass; - use Pimcore\Bundle\StudioBackendBundle\Exception\MustImplementInterfaceException; use Pimcore\Bundle\StudioBackendBundle\Setting\Provider\SettingsProviderInterface; use Pimcore\Bundle\StudioBackendBundle\Setting\Service\Loader\TaggedIteratorAdapter; diff --git a/src/Setting/Provider/SettingsProviderInterface.php b/src/Setting/Provider/SettingsProviderInterface.php index a8562d4f9..2f2824bda 100644 --- a/src/Setting/Provider/SettingsProviderInterface.php +++ b/src/Setting/Provider/SettingsProviderInterface.php @@ -22,4 +22,4 @@ interface SettingsProviderInterface { public function getSettings(): array; -} \ No newline at end of file +} diff --git a/src/Setting/Service/SettingsServiceInterface.php b/src/Setting/Service/SettingsServiceInterface.php index c6159301b..434a6f3a9 100644 --- a/src/Setting/Service/SettingsServiceInterface.php +++ b/src/Setting/Service/SettingsServiceInterface.php @@ -22,4 +22,4 @@ interface SettingsServiceInterface { public function getSettings(): array; -} \ No newline at end of file +} From 75fedfd864a69db10ceab42535f75012b93ab6bf Mon Sep 17 00:00:00 2001 From: mattamon Date: Thu, 23 May 2024 11:51:59 +0200 Subject: [PATCH 4/4] Consistency check --- config/settings.yaml | 4 ++-- src/Setting/Controller/GetController.php | 5 +---- src/Setting/Provider/ConfigSettingsProvider.php | 8 +++++--- src/Setting/Provider/SystemSettingsProvider.php | 8 +++++--- src/Setting/Service/Loader/TaggedIteratorAdapter.php | 2 +- src/Setting/Service/SettingsService.php | 8 ++++---- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/config/settings.yaml b/config/settings.yaml index a59d6ee5a..8c9bb36aa 100644 --- a/config/settings.yaml +++ b/config/settings.yaml @@ -19,7 +19,7 @@ services: class: Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingsService Pimcore\Bundle\StudioBackendBundle\Setting\Provider\ConfigSettingsProvider: - tags: [ 'pimcore.studio_api.settings_provider' ] + tags: [ 'pimcore.studio_backend.settings_provider' ] Pimcore\Bundle\StudioBackendBundle\Setting\Provider\SystemSettingsProvider: - tags: [ 'pimcore.studio_api.settings_provider' ] \ No newline at end of file + tags: [ 'pimcore.studio_backend.settings_provider' ] \ No newline at end of file diff --git a/src/Setting/Controller/GetController.php b/src/Setting/Controller/GetController.php index 4b67b2426..0a5d215e7 100644 --- a/src/Setting/Controller/GetController.php +++ b/src/Setting/Controller/GetController.php @@ -18,7 +18,6 @@ use OpenApi\Attributes\Get; use OpenApi\Attributes\JsonContent; -use Pimcore\Bundle\AdminBundle\System\AdminConfig; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse; @@ -26,8 +25,6 @@ use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; use Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingsServiceInterface; -use Pimcore\Config; -use Pimcore\SystemSettingsConfig; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Serializer\SerializerInterface; @@ -66,4 +63,4 @@ public function getSystemSettings(): JsonResponse { return $this->jsonResponse($this->settingsService->getSettings()); } -} \ No newline at end of file +} diff --git a/src/Setting/Provider/ConfigSettingsProvider.php b/src/Setting/Provider/ConfigSettingsProvider.php index 94fde67ab..5f9e21444 100644 --- a/src/Setting/Provider/ConfigSettingsProvider.php +++ b/src/Setting/Provider/ConfigSettingsProvider.php @@ -17,14 +17,16 @@ namespace Pimcore\Bundle\StudioBackendBundle\Setting\Provider; use Pimcore\Config; +use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; /** * @internal */ -final class ConfigSettingsProvider implements SettingsProviderInterface +#[AsTaggedItem('pimcore.studio_backend.settings_provider')] +final readonly class ConfigSettingsProvider implements SettingsProviderInterface { public function __construct( - private readonly Config $config + private Config $config ) { @@ -40,4 +42,4 @@ public function getSettings(): array ]; } -} \ No newline at end of file +} diff --git a/src/Setting/Provider/SystemSettingsProvider.php b/src/Setting/Provider/SystemSettingsProvider.php index b63831ec0..803f34c2d 100644 --- a/src/Setting/Provider/SystemSettingsProvider.php +++ b/src/Setting/Provider/SystemSettingsProvider.php @@ -17,13 +17,15 @@ namespace Pimcore\Bundle\StudioBackendBundle\Setting\Provider; use Pimcore\SystemSettingsConfig; +use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; /** * @internal */ -final class SystemSettingsProvider implements SettingsProviderInterface +#[AsTaggedItem('pimcore.studio_backend.settings_provider')] +final readonly class SystemSettingsProvider implements SettingsProviderInterface { - private readonly array $systemSettings; + private array $systemSettings; public function __construct( SystemSettingsConfig $systemSettingsConfig, @@ -45,4 +47,4 @@ public function getSettings(): array 'main_domain' => $this->systemSettings['general']['domain'], ]; } -} \ No newline at end of file +} diff --git a/src/Setting/Service/Loader/TaggedIteratorAdapter.php b/src/Setting/Service/Loader/TaggedIteratorAdapter.php index 0786c56cb..0955f9292 100644 --- a/src/Setting/Service/Loader/TaggedIteratorAdapter.php +++ b/src/Setting/Service/Loader/TaggedIteratorAdapter.php @@ -24,7 +24,7 @@ */ final class TaggedIteratorAdapter implements SettingProviderLoaderInterface { - public const SETTINGS_PROVIDER_TAG = 'pimcore.studio_api.settings_provider'; + public const SETTINGS_PROVIDER_TAG = 'pimcore.studio_backend.settings_provider'; public function __construct( #[TaggedIterator(self::SETTINGS_PROVIDER_TAG)] diff --git a/src/Setting/Service/SettingsService.php b/src/Setting/Service/SettingsService.php index 06452a6d8..dbbd15bc5 100644 --- a/src/Setting/Service/SettingsService.php +++ b/src/Setting/Service/SettingsService.php @@ -19,10 +19,10 @@ /** * @internal */ -final class SettingsService implements SettingsServiceInterface +final readonly class SettingsService implements SettingsServiceInterface { public function __construct( - private readonly SettingProviderLoaderInterface $settingProviderLoader + private SettingProviderLoaderInterface $settingProviderLoader ) { } @@ -30,7 +30,7 @@ public function __construct( public function getSettings(): array { $settings = []; - foreach($this->settingProviderLoader->loadSettingProviders() as $settingProvider) { + foreach ($this->settingProviderLoader->loadSettingProviders() as $settingProvider) { $settings = [ ... $settings, ... $settingProvider->getSettings() @@ -38,4 +38,4 @@ public function getSettings(): array } return $settings; } -} \ No newline at end of file +}