From 4af55e14c09df718a44b5c19cf7c982878b0c85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 13 Jun 2016 18:26:23 +0200 Subject: [PATCH 1/2] Use a chain pattern for data providers --- src/Action/ActionUtilTrait.php | 2 +- src/Action/GetCollectionAction.php | 4 +- src/Action/GetItemAction.php | 2 +- src/Action/PutItemAction.php | 2 +- src/Api/ResourceClassResolver.php | 1 + .../Doctrine/Orm/CollectionDataProvider.php | 15 +---- src/Bridge/Doctrine/Orm/ItemDataProvider.php | 15 +---- src/Bridge/Doctrine/Orm/Paginator.php | 2 +- .../Symfony/Bundle/ApiPlatformBundle.php | 2 + .../ApiPlatformExtension.php | 1 + .../Compiler/DataProviderPass.php | 58 +++++++++++++++++++ .../Symfony/Bundle/Resources/config/api.xml | 2 - .../Bundle/Resources/config/data_provider.xml | 15 +++++ .../Bundle/Resources/config/doctrine_orm.xml | 12 ++-- src/Bridge/Symfony/Routing/IriConverter.php | 2 +- .../ChainCollectionDataProvider.php | 46 +++++++++++++++ src/DataProvider/ChainItemDataProvider.php | 46 +++++++++++++++ .../CollectionDataProviderInterface.php | 4 +- .../ItemDataProviderInterface.php | 4 +- .../PaginatorInterface.php | 2 +- src/Hydra/Serializer/CollectionNormalizer.php | 2 +- .../PartialCollectionViewNormalizer.php | 2 +- .../ApiPlatformExtensionTest.php | 4 +- .../Symfony/Routing/IriConverterTest.php | 2 +- .../Controller/ConfigCustomController.php | 2 +- .../PartialCollectionViewNormalizerTest.php | 2 +- 26 files changed, 197 insertions(+), 54 deletions(-) create mode 100644 src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php create mode 100644 src/Bridge/Symfony/Bundle/Resources/config/data_provider.xml create mode 100644 src/DataProvider/ChainCollectionDataProvider.php create mode 100644 src/DataProvider/ChainItemDataProvider.php rename src/{Api => DataProvider}/CollectionDataProviderInterface.php (87%) rename src/{Api => DataProvider}/ItemDataProviderInterface.php (87%) rename src/{Api => DataProvider}/PaginatorInterface.php (95%) diff --git a/src/Action/ActionUtilTrait.php b/src/Action/ActionUtilTrait.php index c515270e2ec..09bcae0a3d6 100644 --- a/src/Action/ActionUtilTrait.php +++ b/src/Action/ActionUtilTrait.php @@ -11,7 +11,7 @@ namespace ApiPlatform\Core\Action; -use ApiPlatform\Core\Api\ItemDataProviderInterface; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Exception\RuntimeException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; diff --git a/src/Action/GetCollectionAction.php b/src/Action/GetCollectionAction.php index 51a531cddd4..142c8aefd80 100644 --- a/src/Action/GetCollectionAction.php +++ b/src/Action/GetCollectionAction.php @@ -11,8 +11,8 @@ namespace ApiPlatform\Core\Action; -use ApiPlatform\Core\Api\CollectionDataProviderInterface; -use ApiPlatform\Core\Api\PaginatorInterface; +use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; +use ApiPlatform\Core\DataProvider\PaginatorInterface; use ApiPlatform\Core\Exception\RuntimeException; use Symfony\Component\HttpFoundation\Request; diff --git a/src/Action/GetItemAction.php b/src/Action/GetItemAction.php index c9616ddde50..a34215348dc 100644 --- a/src/Action/GetItemAction.php +++ b/src/Action/GetItemAction.php @@ -11,7 +11,7 @@ namespace ApiPlatform\Core\Action; -use ApiPlatform\Core\Api\ItemDataProviderInterface; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Exception\RuntimeException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; diff --git a/src/Action/PutItemAction.php b/src/Action/PutItemAction.php index d572ab1f6d2..45e3117c000 100644 --- a/src/Action/PutItemAction.php +++ b/src/Action/PutItemAction.php @@ -11,7 +11,7 @@ namespace ApiPlatform\Core\Action; -use ApiPlatform\Core\Api\ItemDataProviderInterface; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Exception\RuntimeException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; diff --git a/src/Api/ResourceClassResolver.php b/src/Api/ResourceClassResolver.php index 332ede5bf6a..b2c155cb971 100644 --- a/src/Api/ResourceClassResolver.php +++ b/src/Api/ResourceClassResolver.php @@ -11,6 +11,7 @@ namespace ApiPlatform\Core\Api; +use ApiPlatform\Core\DataProvider\PaginatorInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; use ApiPlatform\Core\Util\ClassInfoTrait; diff --git a/src/Bridge/Doctrine/Orm/CollectionDataProvider.php b/src/Bridge/Doctrine/Orm/CollectionDataProvider.php index acabd5fb8bf..28f53f664fe 100644 --- a/src/Bridge/Doctrine/Orm/CollectionDataProvider.php +++ b/src/Bridge/Doctrine/Orm/CollectionDataProvider.php @@ -11,7 +11,7 @@ namespace ApiPlatform\Core\Bridge\Doctrine\Orm; -use ApiPlatform\Core\Api\CollectionDataProviderInterface; +use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryResultExtensionInterface; use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; @@ -27,18 +27,15 @@ class CollectionDataProvider implements CollectionDataProviderInterface { private $managerRegistry; private $collectionExtensions; - private $decorated; /** * @param ManagerRegistry $managerRegistry * @param QueryCollectionExtensionInterface[] $collectionExtensions - * @param CollectionDataProviderInterface|null $decorated */ - public function __construct(ManagerRegistry $managerRegistry, array $collectionExtensions = [], CollectionDataProviderInterface $decorated = null) + public function __construct(ManagerRegistry $managerRegistry, array $collectionExtensions = []) { $this->managerRegistry = $managerRegistry; $this->collectionExtensions = $collectionExtensions; - $this->decorated = $decorated; } /** @@ -46,14 +43,6 @@ public function __construct(ManagerRegistry $managerRegistry, array $collectionE */ public function getCollection(string $resourceClass, string $operationName = null) { - if ($this->decorated) { - try { - return $this->decorated->getCollection($resourceClass, $operationName); - } catch (ResourceClassNotSupportedException $resourceClassNotSupportedException) { - // Ignore it - } - } - $manager = $this->managerRegistry->getManagerForClass($resourceClass); if (null === $manager) { throw new ResourceClassNotSupportedException(); diff --git a/src/Bridge/Doctrine/Orm/ItemDataProvider.php b/src/Bridge/Doctrine/Orm/ItemDataProvider.php index 8b41714da53..b848344c54a 100644 --- a/src/Bridge/Doctrine/Orm/ItemDataProvider.php +++ b/src/Bridge/Doctrine/Orm/ItemDataProvider.php @@ -11,7 +11,7 @@ namespace ApiPlatform\Core\Bridge\Doctrine\Orm; -use ApiPlatform\Core\Api\ItemDataProviderInterface; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; @@ -33,22 +33,19 @@ class ItemDataProvider implements ItemDataProviderInterface private $propertyNameCollectionFactory; private $propertyMetadataFactory; private $itemExtensions; - private $decorated; /** * @param ManagerRegistry $managerRegistry * @param PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory * @param PropertyMetadataFactoryInterface $propertyMetadataFactory * @param QueryItemExtensionInterface[] $itemExtensions - * @param ItemDataProviderInterface|null $decorated */ - public function __construct(ManagerRegistry $managerRegistry, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, array $itemExtensions = [], ItemDataProviderInterface $decorated = null) + public function __construct(ManagerRegistry $managerRegistry, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, array $itemExtensions = []) { $this->managerRegistry = $managerRegistry; $this->propertyNameCollectionFactory = $propertyNameCollectionFactory; $this->propertyMetadataFactory = $propertyMetadataFactory; $this->itemExtensions = $itemExtensions; - $this->decorated = $decorated; } /** @@ -56,14 +53,6 @@ public function __construct(ManagerRegistry $managerRegistry, PropertyNameCollec */ public function getItem(string $resourceClass, $id, string $operationName = null, bool $fetchData = false) { - if ($this->decorated) { - try { - return $this->decorated->getItem($resourceClass, $id, $operationName, $fetchData); - } catch (ResourceClassNotSupportedException $resourceClassNotSupportedException) { - // Ignore it - } - } - $manager = $this->managerRegistry->getManagerForClass($resourceClass); if (null === $manager) { throw new ResourceClassNotSupportedException(); diff --git a/src/Bridge/Doctrine/Orm/Paginator.php b/src/Bridge/Doctrine/Orm/Paginator.php index b8f7903e22c..92d22aff711 100644 --- a/src/Bridge/Doctrine/Orm/Paginator.php +++ b/src/Bridge/Doctrine/Orm/Paginator.php @@ -11,7 +11,7 @@ namespace ApiPlatform\Core\Bridge\Doctrine\Orm; -use ApiPlatform\Core\Api\PaginatorInterface; +use ApiPlatform\Core\DataProvider\PaginatorInterface; use Doctrine\ORM\Query; use Doctrine\ORM\Tools\Pagination\Paginator as DoctrineOrmPaginator; diff --git a/src/Bridge/Symfony/Bundle/ApiPlatformBundle.php b/src/Bridge/Symfony/Bundle/ApiPlatformBundle.php index fc9da0da414..0f3f2330753 100644 --- a/src/Bridge/Symfony/Bundle/ApiPlatformBundle.php +++ b/src/Bridge/Symfony/Bundle/ApiPlatformBundle.php @@ -11,6 +11,7 @@ namespace ApiPlatform\Core\Bridge\Symfony\Bundle; +use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\DataProviderPass; use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\DoctrineQueryExtensionPass; use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\FilterPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -30,6 +31,7 @@ public function build(ContainerBuilder $container) { parent::build($container); + $container->addCompilerPass(new DataProviderPass()); $container->addCompilerPass(new FilterPass()); $container->addCompilerPass(new DoctrineQueryExtensionPass()); } diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 5ac1a68cf78..5e42b8aa6b5 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -81,6 +81,7 @@ public function load(array $configs, ContainerBuilder $container) $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('api.xml'); $loader->load('metadata.xml'); + $loader->load('data_provider.xml'); $this->enableJsonLd($loader); $this->registerAnnotationLoaders($container); diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php b/src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php new file mode 100644 index 00000000000..a3396007511 --- /dev/null +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; + +/** + * Registers data providers. + * + * @internal + * + * @author Kévin Dunglas + */ +final class DataProviderPass implements CompilerPassInterface +{ + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + $this->registerDataProviders($container, 'collection'); + $this->registerDataProviders($container, 'item'); + } + + /** + * The priority sorting algorithm has been backported from Symfony 3.2. + * + * @see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php + * + * @param ContainerBuilder $container + * @param string $type + */ + private function registerDataProviders(ContainerBuilder $container, string $type) { + $services = $container->findTaggedServiceIds('api_platform.'.$type.'_data_provider'); + + $queue = new \SplPriorityQueue(); + + foreach ($services as $serviceId => $tags) { + foreach ($tags as $attributes) { + $priority = isset($attributes['priority']) ? $attributes['priority'] : 0; + $queue->insert(new Reference($serviceId), $priority); + } + } + + $container->getDefinition('api_platform.'.$type.'_data_provider')->addArgument(iterator_to_array($queue, false)); + } +} diff --git a/src/Bridge/Symfony/Bundle/Resources/config/api.xml b/src/Bridge/Symfony/Bundle/Resources/config/api.xml index 00e736eac99..7bb616deb0d 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/api.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/api.xml @@ -11,8 +11,6 @@ - - diff --git a/src/Bridge/Symfony/Bundle/Resources/config/data_provider.xml b/src/Bridge/Symfony/Bundle/Resources/config/data_provider.xml new file mode 100644 index 00000000000..6cec2537ad2 --- /dev/null +++ b/src/Bridge/Symfony/Bundle/Resources/config/data_provider.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml b/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml index ef0e4dc072f..0a322a171c0 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml @@ -5,9 +5,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - @@ -24,8 +21,13 @@ - - + + + + + + + diff --git a/src/Bridge/Symfony/Routing/IriConverter.php b/src/Bridge/Symfony/Routing/IriConverter.php index a3c8fa46539..dbbefebf6cf 100644 --- a/src/Bridge/Symfony/Routing/IriConverter.php +++ b/src/Bridge/Symfony/Routing/IriConverter.php @@ -12,7 +12,7 @@ namespace ApiPlatform\Core\Bridge\Symfony\Routing; use ApiPlatform\Core\Api\IriConverterInterface; -use ApiPlatform\Core\Api\ItemDataProviderInterface; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Api\UrlGeneratorInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; diff --git a/src/DataProvider/ChainCollectionDataProvider.php b/src/DataProvider/ChainCollectionDataProvider.php new file mode 100644 index 00000000000..d5b03870825 --- /dev/null +++ b/src/DataProvider/ChainCollectionDataProvider.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ApiPlatform\Core\DataProvider; + +use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; + +/** + * Tries each configured data provider and returns the result of the first able to handle the resource class. + * + * @author Kévin Dunglas + */ +final class ChainCollectionDataProvider implements CollectionDataProviderInterface +{ + private $dataProviders; + + /** + * @param CollectionDataProviderInterface[] $dataProviders + */ + public function __construct(array $dataProviders) + { + $this->dataProviders = $dataProviders; + } + + /** + * {@inheritdoc} + */ + public function getCollection(string $resourceClass, string $operationName = null) + { + foreach ($this->dataProviders as $dataProvider) { + try { + return $dataProvider->getCollection($resourceClass, $operationName); + } catch (ResourceClassNotSupportedException $e) { + continue; + } + } + } +} diff --git a/src/DataProvider/ChainItemDataProvider.php b/src/DataProvider/ChainItemDataProvider.php new file mode 100644 index 00000000000..7e3a1a25298 --- /dev/null +++ b/src/DataProvider/ChainItemDataProvider.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ApiPlatform\Core\DataProvider; + +use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; + +/** + * Tries each configured data provider and returns the result of the first able to handle the resource class. + * + * @author Kévin Dunglas + */ +final class ChainItemDataProvider implements ItemDataProviderInterface +{ + private $dataProviders; + + /** + * @param ItemDataProviderInterface[] $dataProviders + */ + public function __construct(array $dataProviders) + { + $this->dataProviders = $dataProviders; + } + + /** + * {@inheritdoc} + */ + public function getItem(string $resourceClass, $id, string $operationName = null, bool $fetchData = false) + { + foreach ($this->dataProviders as $dataProviders) { + try { + return $dataProviders->getItem($resourceClass, $id, $operationName, $fetchData); + } catch (ResourceClassNotSupportedException $e) { + continue; + } + } + } +} diff --git a/src/Api/CollectionDataProviderInterface.php b/src/DataProvider/CollectionDataProviderInterface.php similarity index 87% rename from src/Api/CollectionDataProviderInterface.php rename to src/DataProvider/CollectionDataProviderInterface.php index 82a8aa18628..cf576307a19 100644 --- a/src/Api/CollectionDataProviderInterface.php +++ b/src/DataProvider/CollectionDataProviderInterface.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace ApiPlatform\Core\Api; +namespace ApiPlatform\Core\DataProvider; -use ApiPlatform\Core\Exception\ExceptionInterface; use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; /** @@ -28,7 +27,6 @@ interface CollectionDataProviderInterface * @param string|null $operationName * * @throws ResourceClassNotSupportedException - * @throws ExceptionInterface * * @return array|PaginatorInterface|\Traversable */ diff --git a/src/Api/ItemDataProviderInterface.php b/src/DataProvider/ItemDataProviderInterface.php similarity index 87% rename from src/Api/ItemDataProviderInterface.php rename to src/DataProvider/ItemDataProviderInterface.php index d78d65da4d9..b0ff3d543a1 100644 --- a/src/Api/ItemDataProviderInterface.php +++ b/src/DataProvider/ItemDataProviderInterface.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace ApiPlatform\Core\Api; +namespace ApiPlatform\Core\DataProvider; -use ApiPlatform\Core\Exception\ExceptionInterface; use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; /** @@ -30,7 +29,6 @@ interface ItemDataProviderInterface * @param bool $fetchData * * @throws ResourceClassNotSupportedException - * @throws ExceptionInterface * * @return object|null */ diff --git a/src/Api/PaginatorInterface.php b/src/DataProvider/PaginatorInterface.php similarity index 95% rename from src/Api/PaginatorInterface.php rename to src/DataProvider/PaginatorInterface.php index 2887c086f4a..0a395d9505c 100644 --- a/src/Api/PaginatorInterface.php +++ b/src/DataProvider/PaginatorInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ApiPlatform\Core\Api; +namespace ApiPlatform\Core\DataProvider; /** * Paginator Interface. diff --git a/src/Hydra/Serializer/CollectionNormalizer.php b/src/Hydra/Serializer/CollectionNormalizer.php index 0160baa93fb..78214847719 100644 --- a/src/Hydra/Serializer/CollectionNormalizer.php +++ b/src/Hydra/Serializer/CollectionNormalizer.php @@ -12,7 +12,7 @@ namespace ApiPlatform\Core\Hydra\Serializer; use ApiPlatform\Core\Api\IriConverterInterface; -use ApiPlatform\Core\Api\PaginatorInterface; +use ApiPlatform\Core\DataProvider\PaginatorInterface; use ApiPlatform\Core\Api\ResourceClassResolverInterface; use ApiPlatform\Core\Exception\RuntimeException; use ApiPlatform\Core\JsonLd\ContextBuilderInterface; diff --git a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php index 2b1f119a9c3..ab45dfaaf8f 100644 --- a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php +++ b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php @@ -11,7 +11,7 @@ namespace ApiPlatform\Core\Hydra\Serializer; -use ApiPlatform\Core\Api\PaginatorInterface; +use ApiPlatform\Core\DataProvider\PaginatorInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\JsonLd\Serializer\ContextTrait; use ApiPlatform\Core\Util\RequestParser; diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index 7e9cbe70e4f..8af668c0030 100644 --- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -211,8 +211,6 @@ private function getContainerBuilderProphecy() 'api_platform.metadata.resource.metadata_factory', 'api_platform.metadata.property.name_collection_factory', 'api_platform.metadata.property.metadata_factory', - 'api_platform.item_data_provider', - 'api_platform.collection_data_provider', 'api_platform.action.delete_item', ]; foreach ($aliases as $alias) { @@ -245,6 +243,8 @@ private function getContainerBuilderProphecy() $containerBuilderProphecy->getDefinition('api_platform.metadata.resource.metadata_factory.xml')->willReturn($definition); $definitions = [ + 'api_platform.item_data_provider', + 'api_platform.collection_data_provider', 'api_platform.filters', 'api_platform.resource_class_resolver', 'api_platform.operation_method_resolver', diff --git a/tests/Bridge/Symfony/Routing/IriConverterTest.php b/tests/Bridge/Symfony/Routing/IriConverterTest.php index 33e3a422fb4..a1534456b48 100644 --- a/tests/Bridge/Symfony/Routing/IriConverterTest.php +++ b/tests/Bridge/Symfony/Routing/IriConverterTest.php @@ -11,7 +11,7 @@ namespace ApiPlatform\Core\Tests\Symfony\Bridge\Bundle\DependencyInjection; -use ApiPlatform\Core\Api\ItemDataProviderInterface; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Bridge\Symfony\Routing\IriConverter; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; diff --git a/tests/Fixtures/TestBundle/Controller/ConfigCustomController.php b/tests/Fixtures/TestBundle/Controller/ConfigCustomController.php index 69695aef4ef..c621e8e3440 100644 --- a/tests/Fixtures/TestBundle/Controller/ConfigCustomController.php +++ b/tests/Fixtures/TestBundle/Controller/ConfigCustomController.php @@ -12,7 +12,7 @@ namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Controller; use ApiPlatform\Core\Action\ActionUtilTrait; -use ApiPlatform\Core\Api\ItemDataProviderInterface; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use Symfony\Component\HttpFoundation\Request; /** diff --git a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php index 6f34b74e195..36596ecfed3 100644 --- a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php +++ b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php @@ -11,7 +11,7 @@ namespace ApiPlatform\Core\Tests\Hydra\Serializer; -use ApiPlatform\Core\Api\PaginatorInterface; +use ApiPlatform\Core\DataProvider\PaginatorInterface; use ApiPlatform\Core\Hydra\Serializer\PartialCollectionViewNormalizer; use Prophecy\Argument; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; From 07a5481a3ba45a2d99ef548ed7afc5874c57593b Mon Sep 17 00:00:00 2001 From: dunglas Date: Wed, 15 Jun 2016 05:46:43 -0400 Subject: [PATCH 2/2] Applied fixes from StyleCI --- src/Bridge/Doctrine/Orm/CollectionDataProvider.php | 6 +++--- src/Bridge/Doctrine/Orm/ItemDataProvider.php | 2 +- .../DependencyInjection/Compiler/DataProviderPass.php | 3 ++- src/Bridge/Symfony/Routing/IriConverter.php | 2 +- src/Hydra/Serializer/CollectionNormalizer.php | 2 +- tests/Bridge/Symfony/Routing/IriConverterTest.php | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Bridge/Doctrine/Orm/CollectionDataProvider.php b/src/Bridge/Doctrine/Orm/CollectionDataProvider.php index 28f53f664fe..ee73261d9de 100644 --- a/src/Bridge/Doctrine/Orm/CollectionDataProvider.php +++ b/src/Bridge/Doctrine/Orm/CollectionDataProvider.php @@ -11,9 +11,9 @@ namespace ApiPlatform\Core\Bridge\Doctrine\Orm; -use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryResultExtensionInterface; +use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; use Doctrine\Common\Persistence\ManagerRegistry; @@ -29,8 +29,8 @@ class CollectionDataProvider implements CollectionDataProviderInterface private $collectionExtensions; /** - * @param ManagerRegistry $managerRegistry - * @param QueryCollectionExtensionInterface[] $collectionExtensions + * @param ManagerRegistry $managerRegistry + * @param QueryCollectionExtensionInterface[] $collectionExtensions */ public function __construct(ManagerRegistry $managerRegistry, array $collectionExtensions = []) { diff --git a/src/Bridge/Doctrine/Orm/ItemDataProvider.php b/src/Bridge/Doctrine/Orm/ItemDataProvider.php index b848344c54a..b688c4d7506 100644 --- a/src/Bridge/Doctrine/Orm/ItemDataProvider.php +++ b/src/Bridge/Doctrine/Orm/ItemDataProvider.php @@ -11,8 +11,8 @@ namespace ApiPlatform\Core\Bridge\Doctrine\Orm; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php b/src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php index a3396007511..cddae693190 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php @@ -41,7 +41,8 @@ public function process(ContainerBuilder $container) * @param ContainerBuilder $container * @param string $type */ - private function registerDataProviders(ContainerBuilder $container, string $type) { + private function registerDataProviders(ContainerBuilder $container, string $type) + { $services = $container->findTaggedServiceIds('api_platform.'.$type.'_data_provider'); $queue = new \SplPriorityQueue(); diff --git a/src/Bridge/Symfony/Routing/IriConverter.php b/src/Bridge/Symfony/Routing/IriConverter.php index dbbefebf6cf..df84e441b7e 100644 --- a/src/Bridge/Symfony/Routing/IriConverter.php +++ b/src/Bridge/Symfony/Routing/IriConverter.php @@ -12,8 +12,8 @@ namespace ApiPlatform\Core\Bridge\Symfony\Routing; use ApiPlatform\Core\Api\IriConverterInterface; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Api\UrlGeneratorInterface; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; diff --git a/src/Hydra/Serializer/CollectionNormalizer.php b/src/Hydra/Serializer/CollectionNormalizer.php index 78214847719..5104997330d 100644 --- a/src/Hydra/Serializer/CollectionNormalizer.php +++ b/src/Hydra/Serializer/CollectionNormalizer.php @@ -12,8 +12,8 @@ namespace ApiPlatform\Core\Hydra\Serializer; use ApiPlatform\Core\Api\IriConverterInterface; -use ApiPlatform\Core\DataProvider\PaginatorInterface; use ApiPlatform\Core\Api\ResourceClassResolverInterface; +use ApiPlatform\Core\DataProvider\PaginatorInterface; use ApiPlatform\Core\Exception\RuntimeException; use ApiPlatform\Core\JsonLd\ContextBuilderInterface; use ApiPlatform\Core\JsonLd\Serializer\ContextTrait; diff --git a/tests/Bridge/Symfony/Routing/IriConverterTest.php b/tests/Bridge/Symfony/Routing/IriConverterTest.php index a1534456b48..e21b8afcb92 100644 --- a/tests/Bridge/Symfony/Routing/IriConverterTest.php +++ b/tests/Bridge/Symfony/Routing/IriConverterTest.php @@ -11,8 +11,8 @@ namespace ApiPlatform\Core\Tests\Symfony\Bridge\Bundle\DependencyInjection; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Bridge\Symfony\Routing\IriConverter; +use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;