From 322c625ffe9736cd05a63c5b9c0aa0e4613f5d41 Mon Sep 17 00:00:00 2001 From: mattamon Date: Wed, 24 Apr 2024 08:28:15 +0200 Subject: [PATCH] Change to provider instead of factory, move trait --- config/factories.yaml | 7 ------- config/providers.yaml | 13 +++++++++++++ src/Controller/Api/Assets/CollectionController.php | 6 +++--- .../Api/DataObjects/CollectionController.php | 6 +++--- .../PimcoreStudioApiExtension.php | 1 + .../FilterServiceLoaderInterface.php | 2 +- .../FilterServiceProvider.php} | 4 ++-- .../FilterServiceProviderInterface.php} | 4 ++-- .../Loader/TaggedIteratorAdapter.php | 5 ++--- .../Traits}/PaginatedResponseTrait.php | 2 +- 10 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 config/providers.yaml rename src/{Factory => Provider}/FilterServiceLoaderInterface.php (91%) rename src/{Factory/FilterServiceFactory.php => Provider/FilterServiceProvider.php} (89%) rename src/{Factory/FilterServiceFactoryInterface.php => Provider/FilterServiceProviderInterface.php} (84%) rename src/{Factory => Provider}/Loader/TaggedIteratorAdapter.php (88%) rename src/{Controller/Trait => Util/Traits}/PaginatedResponseTrait.php (94%) diff --git a/config/factories.yaml b/config/factories.yaml index b9592e251..2193d0bd1 100644 --- a/config/factories.yaml +++ b/config/factories.yaml @@ -5,12 +5,5 @@ services: public: false #Factory - - Pimcore\Bundle\StudioApiBundle\Factory\FilterServiceFactoryInterface: - class: Pimcore\Bundle\StudioApiBundle\Factory\FilterServiceFactory - - Pimcore\Bundle\StudioApiBundle\Factory\FilterServiceLoaderInterface: - class: Pimcore\Bundle\StudioApiBundle\Factory\Loader\TaggedIteratorAdapter - Pimcore\Bundle\StudioApiBundle\Factory\QueryFactoryInterface: class: Pimcore\Bundle\StudioApiBundle\Factory\QueryFactory diff --git a/config/providers.yaml b/config/providers.yaml new file mode 100644 index 000000000..8107c0a1f --- /dev/null +++ b/config/providers.yaml @@ -0,0 +1,13 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + #Factory + + Pimcore\Bundle\StudioApiBundle\Provider\FilterServiceProviderInterface: + class: Pimcore\Bundle\StudioApiBundle\Provider\FilterServiceProvider + + Pimcore\Bundle\StudioApiBundle\Provider\FilterServiceLoaderInterface: + class: Pimcore\Bundle\StudioApiBundle\Provider\Loader\TaggedIteratorAdapter diff --git a/src/Controller/Api/Assets/CollectionController.php b/src/Controller/Api/Assets/CollectionController.php index 2c16975e9..680a5f733 100644 --- a/src/Controller/Api/Assets/CollectionController.php +++ b/src/Controller/Api/Assets/CollectionController.php @@ -35,12 +35,12 @@ use Pimcore\Bundle\StudioApiBundle\Attributes\Response\SuccessResponse; use Pimcore\Bundle\StudioApiBundle\Config\Tags; use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController; -use Pimcore\Bundle\StudioApiBundle\Controller\Trait\PaginatedResponseTrait; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException; -use Pimcore\Bundle\StudioApiBundle\Factory\FilterServiceFactoryInterface; +use Pimcore\Bundle\StudioApiBundle\Provider\FilterServiceProviderInterface; use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParameters; use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Filter\OpenSearchFilterInterface; +use Pimcore\Bundle\StudioApiBundle\Util\Traits\PaginatedResponseTrait; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapQueryString; use Symfony\Component\Routing\Attribute\Route; @@ -56,7 +56,7 @@ final class CollectionController extends AbstractApiController public function __construct( SerializerInterface $serializer, private readonly AssetSearchServiceInterface $assetSearchService, - private readonly FilterServiceFactoryInterface $filterServiceFactory + private readonly FilterServiceProviderInterface $filterServiceFactory ) { parent::__construct($serializer); } diff --git a/src/Controller/Api/DataObjects/CollectionController.php b/src/Controller/Api/DataObjects/CollectionController.php index f16b14c6c..d4198babf 100644 --- a/src/Controller/Api/DataObjects/CollectionController.php +++ b/src/Controller/Api/DataObjects/CollectionController.php @@ -36,12 +36,12 @@ use Pimcore\Bundle\StudioApiBundle\Attributes\Response\SuccessResponse; use Pimcore\Bundle\StudioApiBundle\Config\Tags; use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController; -use Pimcore\Bundle\StudioApiBundle\Controller\Trait\PaginatedResponseTrait; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException; -use Pimcore\Bundle\StudioApiBundle\Factory\FilterServiceFactoryInterface; +use Pimcore\Bundle\StudioApiBundle\Provider\FilterServiceProviderInterface; use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\DataObjectParameters; use Pimcore\Bundle\StudioApiBundle\Service\DataObjectSearchServiceInterface; use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Filter\OpenSearchFilterInterface; +use Pimcore\Bundle\StudioApiBundle\Util\Traits\PaginatedResponseTrait; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapQueryString; use Symfony\Component\Routing\Attribute\Route; @@ -54,7 +54,7 @@ final class CollectionController extends AbstractApiController public function __construct( SerializerInterface $serializer, private readonly DataObjectSearchServiceInterface $dataObjectSearchService, - private readonly FilterServiceFactoryInterface $filterServiceFactory + private readonly FilterServiceProviderInterface $filterServiceFactory ) { parent::__construct($serializer); } diff --git a/src/DependencyInjection/PimcoreStudioApiExtension.php b/src/DependencyInjection/PimcoreStudioApiExtension.php index dd8acaab8..ef499d418 100644 --- a/src/DependencyInjection/PimcoreStudioApiExtension.php +++ b/src/DependencyInjection/PimcoreStudioApiExtension.php @@ -52,6 +52,7 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('event_subscribers.yaml'); $loader->load('factories.yaml'); $loader->load('filters.yaml'); + $loader->load('providers.yaml'); $loader->load('services.yaml'); $definition = $container->getDefinition(TokenServiceInterface::class); diff --git a/src/Factory/FilterServiceLoaderInterface.php b/src/Provider/FilterServiceLoaderInterface.php similarity index 91% rename from src/Factory/FilterServiceLoaderInterface.php rename to src/Provider/FilterServiceLoaderInterface.php index 800bd5373..e29f92e09 100644 --- a/src/Factory/FilterServiceLoaderInterface.php +++ b/src/Provider/FilterServiceLoaderInterface.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioApiBundle\Factory; +namespace Pimcore\Bundle\StudioApiBundle\Provider; /** * @internal diff --git a/src/Factory/FilterServiceFactory.php b/src/Provider/FilterServiceProvider.php similarity index 89% rename from src/Factory/FilterServiceFactory.php rename to src/Provider/FilterServiceProvider.php index 1e1607dc8..56086dccc 100644 --- a/src/Factory/FilterServiceFactory.php +++ b/src/Provider/FilterServiceProvider.php @@ -14,11 +14,11 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioApiBundle\Factory; +namespace Pimcore\Bundle\StudioApiBundle\Provider; use Pimcore\Bundle\StudioApiBundle\Exception\InvalidFilterServiceTypeException; -final class FilterServiceFactory implements FilterServiceFactoryInterface +final class FilterServiceProvider implements FilterServiceProviderInterface { private array $filterServices = []; diff --git a/src/Factory/FilterServiceFactoryInterface.php b/src/Provider/FilterServiceProviderInterface.php similarity index 84% rename from src/Factory/FilterServiceFactoryInterface.php rename to src/Provider/FilterServiceProviderInterface.php index d4911d198..471b1011b 100644 --- a/src/Factory/FilterServiceFactoryInterface.php +++ b/src/Provider/FilterServiceProviderInterface.php @@ -14,9 +14,9 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioApiBundle\Factory; +namespace Pimcore\Bundle\StudioApiBundle\Provider; -interface FilterServiceFactoryInterface +interface FilterServiceProviderInterface { public function create(string $type): mixed; } diff --git a/src/Factory/Loader/TaggedIteratorAdapter.php b/src/Provider/Loader/TaggedIteratorAdapter.php similarity index 88% rename from src/Factory/Loader/TaggedIteratorAdapter.php rename to src/Provider/Loader/TaggedIteratorAdapter.php index 0f3a2cf38..1f9ada4c3 100644 --- a/src/Factory/Loader/TaggedIteratorAdapter.php +++ b/src/Provider/Loader/TaggedIteratorAdapter.php @@ -14,10 +14,9 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioApiBundle\Factory\Loader; - -use Pimcore\Bundle\StudioApiBundle\Factory\FilterServiceLoaderInterface; +namespace Pimcore\Bundle\StudioApiBundle\Provider\Loader; +use Pimcore\Bundle\StudioApiBundle\Provider\FilterServiceLoaderInterface; use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; /** diff --git a/src/Controller/Trait/PaginatedResponseTrait.php b/src/Util/Traits/PaginatedResponseTrait.php similarity index 94% rename from src/Controller/Trait/PaginatedResponseTrait.php rename to src/Util/Traits/PaginatedResponseTrait.php index dd05a5758..0d660e2b9 100644 --- a/src/Controller/Trait/PaginatedResponseTrait.php +++ b/src/Util/Traits/PaginatedResponseTrait.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioApiBundle\Controller\Trait; +namespace Pimcore\Bundle\StudioApiBundle\Util\Traits; use Pimcore\Bundle\StudioApiBundle\Response\Collection; use Symfony\Component\HttpFoundation\JsonResponse;