-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add system settings controller * Add settings provider concept * Apply php-cs-fixer changes * Consistency check --------- Co-authored-by: mattamon <[email protected]>
- Loading branch information
Showing
13 changed files
with
395 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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' ] | ||
|
||
|
||
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_backend.settings_provider' ] | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Setting\Provider\SystemSettingsProvider: | ||
tags: [ 'pimcore.studio_backend.settings_provider' ] |
46 changes: 46 additions & 0 deletions
46
src/DependencyInjection/CompilerPass/SettingsProviderPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
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; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\MustImplementInterfaceTrait; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class SettingsProviderPass implements CompilerPassInterface | ||
{ | ||
use MustImplementInterfaceTrait; | ||
|
||
/** | ||
* @throws MustImplementInterfaceException | ||
*/ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
$taggedServices = array_keys( | ||
$container->findTaggedServiceIds(TaggedIteratorAdapter::SETTINGS_PROVIDER_TAG), | ||
); | ||
|
||
foreach ($taggedServices as $environmentType) { | ||
$this->checkInterface($environmentType, SettingsProviderInterface::class); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Setting\Controller; | ||
|
||
use OpenApi\Attributes\Get; | ||
use OpenApi\Attributes\JsonContent; | ||
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 Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class GetController extends AbstractApiController | ||
{ | ||
private const ROUTE = '/settings'; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly SettingsServiceInterface $settingsService, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
#[Route(path: self::ROUTE, name: 'pimcore_studio_api_settings', methods: ['GET'])] | ||
#[Get( | ||
path: self::API_PATH . self::ROUTE, | ||
operationId: 'getSystemSettings', | ||
description: 'Get system settings', | ||
summary: 'Get system settings', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Settings->name] | ||
)] | ||
#[SuccessResponse( | ||
description: 'System settings', | ||
content: new JsonContent(type: 'object', additionalProperties: true) | ||
)] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function getSystemSettings(): JsonResponse | ||
{ | ||
return $this->jsonResponse($this->settingsService->getSettings()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Setting\Provider; | ||
|
||
use Pimcore\Config; | ||
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[AsTaggedItem('pimcore.studio_backend.settings_provider')] | ||
final readonly class ConfigSettingsProvider implements SettingsProviderInterface | ||
{ | ||
public function __construct( | ||
private Config $config | ||
) | ||
{ | ||
|
||
} | ||
|
||
public function getSettings(): array | ||
{ | ||
return [ | ||
'asset_tree_paging_limit' => $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'], | ||
]; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Setting\Provider; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface SettingsProviderInterface | ||
{ | ||
public function getSettings(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Setting\Provider; | ||
|
||
use Pimcore\SystemSettingsConfig; | ||
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[AsTaggedItem('pimcore.studio_backend.settings_provider')] | ||
final readonly class SystemSettingsProvider implements SettingsProviderInterface | ||
{ | ||
private array $systemSettings; | ||
|
||
public function __construct( | ||
SystemSettingsConfig $systemSettingsConfig, | ||
) | ||
{ | ||
$this->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'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Setting\Service\Loader; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingProviderLoaderInterface; | ||
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class TaggedIteratorAdapter implements SettingProviderLoaderInterface | ||
{ | ||
public const SETTINGS_PROVIDER_TAG = 'pimcore.studio_backend.settings_provider'; | ||
|
||
public function __construct( | ||
#[TaggedIterator(self::SETTINGS_PROVIDER_TAG)] | ||
private readonly iterable $taggedSettingProviders, | ||
) { | ||
} | ||
|
||
public function loadSettingProviders(): array | ||
{ | ||
return [...$this->taggedSettingProviders]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Setting\Service; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface SettingProviderLoaderInterface | ||
{ | ||
public function loadSettingProviders(): array; | ||
} |
Oops, something went wrong.