diff --git a/src/Api/FilterInterface.php b/src/Api/FilterInterface.php index 01b9ec589d9..967147ce336 100644 --- a/src/Api/FilterInterface.php +++ b/src/Api/FilterInterface.php @@ -13,6 +13,44 @@ namespace ApiPlatform\Api; -interface FilterInterface extends \ApiPlatform\Metadata\FilterInterface +/** + * Filters applicable on a resource. + * + * @author Kévin Dunglas + */ +interface FilterInterface { + /** + * Gets the description of this filter for the given resource. + * + * Returns an array with the filter parameter names as keys and array with the following data as values: + * - property: the property where the filter is applied + * - type: the type of the filter + * - required: if this filter is required + * - strategy (optional): the used strategy + * - is_collection (optional): if this filter is for collection + * - swagger (optional): additional parameters for the path operation, + * e.g. 'swagger' => [ + * 'description' => 'My Description', + * 'name' => 'My Name', + * 'type' => 'integer', + * ] + * - openapi (optional): additional parameters for the path operation in the version 3 spec, + * e.g. 'openapi' => [ + * 'description' => 'My Description', + * 'name' => 'My Name', + * 'schema' => [ + * 'type' => 'integer', + * ] + * ] + * - schema (optional): schema definition, + * e.g. 'schema' => [ + * 'type' => 'string', + * 'enum' => ['value_1', 'value_2'], + * ] + * The description can contain additional data specific to a filter. + * + * @see \ApiPlatform\OpenApi\Factory\OpenApiFactory::getFiltersParameters + */ + public function getDescription(string $resourceClass): array; } diff --git a/src/Api/FilterLocatorTrait.php b/src/Api/FilterLocatorTrait.php index 5119390bf3c..cb9f5edbb0e 100644 --- a/src/Api/FilterLocatorTrait.php +++ b/src/Api/FilterLocatorTrait.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Api; use ApiPlatform\Exception\InvalidArgumentException; -use ApiPlatform\Metadata\FilterInterface; +use ApiPlatform\Metadata\FilterInterface as MetadataFilterInterface; use Psr\Container\ContainerInterface; /** @@ -45,7 +45,7 @@ private function setFilterLocator(?ContainerInterface $filterLocator, bool $allo /** * Gets a filter with a backward compatibility. */ - private function getFilter(string $filterId): ?FilterInterface + private function getFilter(string $filterId): null|FilterInterface|MetadataFilterInterface { if ($this->filterLocator && $this->filterLocator->has($filterId)) { return $this->filterLocator->get($filterId); diff --git a/src/Api/IdentifiersExtractorInterface.php b/src/Api/IdentifiersExtractorInterface.php index ff0f428c0a3..d0e7566dc45 100644 --- a/src/Api/IdentifiersExtractorInterface.php +++ b/src/Api/IdentifiersExtractorInterface.php @@ -13,15 +13,20 @@ namespace ApiPlatform\Api; -class_exists(\ApiPlatform\Metadata\IdentifiersExtractorInterface::class); +use ApiPlatform\Metadata\Exception\RuntimeException; +use ApiPlatform\Metadata\Operation; -class_alias( - \ApiPlatform\Metadata\IdentifiersExtractorInterface::class, - __NAMESPACE__.'\IdentifiersExtractorInterface' -); - -if (false) { // @phpstan-ignore-line - interface IdentifiersExtractorInterface extends \ApiPlatform\Metadata\IdentifiersExtractorInterface - { - } +/** + * Extracts identifiers for a given Resource according to the retrieved Metadata. + * + * @author Antoine Bluchet + */ +interface IdentifiersExtractorInterface +{ + /** + * Finds identifiers from an Item (object). + * + * @throws RuntimeException + */ + public function getIdentifiersFromItem(object $item, Operation $operation = null, array $context = []): array; } diff --git a/src/Api/IriConverterInterface.php b/src/Api/IriConverterInterface.php index e1f39780324..8a319f370cb 100644 --- a/src/Api/IriConverterInterface.php +++ b/src/Api/IriConverterInterface.php @@ -13,15 +13,33 @@ namespace ApiPlatform\Api; -class_exists(\ApiPlatform\Metadata\IriConverterInterface::class); +use ApiPlatform\Metadata\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\Exception\ItemNotFoundException; +use ApiPlatform\Metadata\Exception\RuntimeException; +use ApiPlatform\Metadata\Operation; -class_alias( - \ApiPlatform\Metadata\IriConverterInterface::class, - __NAMESPACE__.'\IriConverterInterface' -); +/** + * Converts item and resources to IRI and vice versa. + * + * @author Kévin Dunglas + */ +interface IriConverterInterface +{ + /** + * Retrieves an item from its IRI. + * + * @throws InvalidArgumentException + * @throws ItemNotFoundException + */ + public function getResourceFromIri(string $iri, array $context = [], Operation $operation = null): object; -if (false) { // @phpstan-ignore-line - interface IriConverterInterface extends \ApiPlatform\Metadata\IriConverterInterface - { - } + /** + * Gets the IRI associated with the given item. + * + * @param object|class-string $resource + * + * @throws InvalidArgumentException + * @throws RuntimeException + */ + public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, Operation $operation = null, array $context = []): ?string; } diff --git a/src/Api/ResourceClassResolverInterface.php b/src/Api/ResourceClassResolverInterface.php index 0dd636478b9..683b6618368 100644 --- a/src/Api/ResourceClassResolverInterface.php +++ b/src/Api/ResourceClassResolverInterface.php @@ -13,10 +13,27 @@ namespace ApiPlatform\Api; -class_exists(\ApiPlatform\Metadata\ResourceClassResolverInterface::class); +use ApiPlatform\Metadata\Exception\InvalidArgumentException; -if (false) { // @phpstan-ignore-line - interface ResourceClassResolverInterface extends \ApiPlatform\Metadata\ResourceClassResolverInterface - { - } +/** + * Guesses which resource is associated with a given object. + * + * @author Kévin Dunglas + */ +interface ResourceClassResolverInterface +{ + /** + * Guesses the associated resource. + * + * @param string $resourceClass The expected resource class + * @param bool $strict If true, value must match the expected resource class + * + * @throws InvalidArgumentException + */ + public function getResourceClass(mixed $value, string $resourceClass = null, bool $strict = false): string; + + /** + * Is the given class a resource class? + */ + public function isResourceClass(string $type): bool; } diff --git a/src/Api/UriVariableTransformerInterface.php b/src/Api/UriVariableTransformerInterface.php index 544e5c1c989..c3a0013244e 100644 --- a/src/Api/UriVariableTransformerInterface.php +++ b/src/Api/UriVariableTransformerInterface.php @@ -13,6 +13,27 @@ namespace ApiPlatform\Api; -interface UriVariableTransformerInterface extends \ApiPlatform\Metadata\UriVariableTransformerInterface +use ApiPlatform\Exception\InvalidUriVariableException; + +interface UriVariableTransformerInterface { + /** + * Transforms the value of a URI variable (identifier) to its type. + * + * @param mixed $value The URI variable value to transform + * @param array $types The guessed type behind the URI variable + * @param array $context Options available to the transformer + * + * @throws InvalidUriVariableException Occurs when the URI variable could not be transformed + */ + public function transform(mixed $value, array $types, array $context = []); + + /** + * Checks whether the value of a URI variable can be transformed to its type by this transformer. + * + * @param mixed $value The URI variable value to transform + * @param array $types The types to which the URI variable value should be transformed + * @param array $context Options available to the transformer + */ + public function supportsTransformation(mixed $value, array $types, array $context = []): bool; } diff --git a/src/Api/UriVariablesConverterInterface.php b/src/Api/UriVariablesConverterInterface.php index 45dd27a07ed..67c49092221 100644 --- a/src/Api/UriVariablesConverterInterface.php +++ b/src/Api/UriVariablesConverterInterface.php @@ -13,15 +13,24 @@ namespace ApiPlatform\Api; -class_exists(\ApiPlatform\Metadata\UriVariablesConverterInterface::class); +use ApiPlatform\Metadata\Exception\InvalidIdentifierException; -class_alias( - \ApiPlatform\Metadata\UriVariablesConverterInterface::class, - __NAMESPACE__.'\UriVariablesConverterInterface' -); - -if (false) { // @phpstan-ignore-line - interface UriVariablesConverterInterface extends \ApiPlatform\Metadata\UriVariablesConverterInterface - { - } +/** + * Identifier converter. + * + * @author Antoine Bluchet + */ +interface UriVariablesConverterInterface +{ + /** + * Takes an array of strings representing URI variables (identifiers) and transform their values to the expected type. + * + * @param array $data URI variables to convert to PHP values + * @param string $class The class to which the URI variables belong to + * + * @throws InvalidIdentifierException + * + * @return array Array indexed by identifiers properties with their values denormalized + */ + public function convert(array $data, string $class, array $context = []): array; } diff --git a/src/Api/UrlGeneratorInterface.php b/src/Api/UrlGeneratorInterface.php index 5b199a684c1..b6ee97cf0cd 100644 --- a/src/Api/UrlGeneratorInterface.php +++ b/src/Api/UrlGeneratorInterface.php @@ -13,13 +13,72 @@ namespace ApiPlatform\Api; -class_alias( - \ApiPlatform\Metadata\UrlGeneratorInterface::class, - __NAMESPACE__.'\UrlGeneratorInterface' -); - -if (false) { // @phpstan-ignore-line - interface UrlGeneratorInterface extends \ApiPlatform\Metadata\UrlGeneratorInterface - { - } +use Symfony\Component\Routing\Exception\InvalidParameterException; +use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; +use Symfony\Component\Routing\Exception\RouteNotFoundException; + +/** + * UrlGeneratorInterface is the interface that all URL generator classes must implement. + * + * This interface has been imported and adapted from the Symfony project. + * + * The constants in this interface define the different types of resource references that + * are declared in RFC 3986: http://tools.ietf.org/html/rfc3986 + * We are using the term "URL" instead of "URI" as this is more common in web applications + * and we do not need to distinguish them as the difference is mostly semantical and + * less technical. Generating URIs, i.e. representation-independent resource identifiers, + * is also possible. + * + * @author Fabien Potencier + * @author Tobias Schultze + * @copyright Fabien Potencier + */ +interface UrlGeneratorInterface +{ + /** + * Generates an absolute URL, e.g. "http://example.com/dir/file". + */ + public const ABS_URL = 0; + + /** + * Generates an absolute path, e.g. "/dir/file". + */ + public const ABS_PATH = 1; + + /** + * Generates a relative path based on the current request path, e.g. "../parent-file". + * + * @see UrlGenerator::getRelativePath() + */ + public const REL_PATH = 2; + + /** + * Generates a network path, e.g. "//example.com/dir/file". + * Such reference reuses the current scheme but specifies the host. + */ + public const NET_PATH = 3; + + /** + * Generates a URL or path for a specific route based on the given parameters. + * + * Parameters that reference placeholders in the route pattern will substitute them in the + * path or host. Extra params are added as query string to the URL. + * + * When the passed reference type cannot be generated for the route because it requires a different + * host or scheme than the current one, the method will return a more comprehensive reference + * that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH + * but the route requires the https scheme whereas the current scheme is http, it will instead return an + * ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches + * the route in any case. + * + * If there is no route with the given name, the generator must throw the RouteNotFoundException. + * + * The special parameter _fragment will be used as the document fragment suffixed to the final URL. + * + * @throws RouteNotFoundException If the named route doesn't exist + * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route + * @throws InvalidParameterException When a parameter value for a placeholder is not correct because + * it does not match the requirement + */ + public function generate(string $name, array $parameters = [], int $referenceType = self::ABS_PATH): string; } diff --git a/src/Doctrine/Odm/Filter/SearchFilter.php b/src/Doctrine/Odm/Filter/SearchFilter.php index 6193d776d9c..7b0a680307f 100644 --- a/src/Doctrine/Odm/Filter/SearchFilter.php +++ b/src/Doctrine/Odm/Filter/SearchFilter.php @@ -149,7 +149,7 @@ public function __construct(ManagerRegistry $managerRegistry, IriConverterInterf $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } - protected function getIriConverter(): IriConverterInterface + protected function getIriConverter(): LegacyIriConverterInterface|IriConverterInterface { return $this->iriConverter; } diff --git a/src/Doctrine/Orm/Filter/SearchFilter.php b/src/Doctrine/Orm/Filter/SearchFilter.php index 7094a823f12..3f7480e9fb2 100644 --- a/src/Doctrine/Orm/Filter/SearchFilter.php +++ b/src/Doctrine/Orm/Filter/SearchFilter.php @@ -148,7 +148,7 @@ public function __construct(ManagerRegistry $managerRegistry, IriConverterInterf $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } - protected function getIriConverter(): IriConverterInterface + protected function getIriConverter(): IriConverterInterface|LegacyIriConverterInterface { return $this->iriConverter; } diff --git a/src/Hydra/Serializer/CollectionFiltersNormalizer.php b/src/Hydra/Serializer/CollectionFiltersNormalizer.php index 1552e1cb167..2b58890249d 100644 --- a/src/Hydra/Serializer/CollectionFiltersNormalizer.php +++ b/src/Hydra/Serializer/CollectionFiltersNormalizer.php @@ -13,7 +13,9 @@ namespace ApiPlatform\Hydra\Serializer; +use ApiPlatform\Api\FilterInterface as LegacyFilterInterface; use ApiPlatform\Api\FilterLocatorTrait; +use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface; use ApiPlatform\Doctrine\Odm\State\Options as ODMOptions; use ApiPlatform\Doctrine\Orm\State\Options; use ApiPlatform\Metadata\FilterInterface; @@ -40,7 +42,7 @@ final class CollectionFiltersNormalizer implements NormalizerInterface, Normaliz /** * @param ContainerInterface $filterLocator The new filter locator or the deprecated filter collection */ - public function __construct(private readonly NormalizerInterface $collectionNormalizer, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly ResourceClassResolverInterface $resourceClassResolver, ContainerInterface $filterLocator) + public function __construct(private readonly NormalizerInterface $collectionNormalizer, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly LegacyResourceClassResolverInterface|ResourceClassResolverInterface $resourceClassResolver, ContainerInterface $filterLocator) { $this->setFilterLocator($filterLocator); } @@ -142,7 +144,7 @@ public function setNormalizer(NormalizerInterface $normalizer): void /** * Returns the content of the Hydra search property. * - * @param FilterInterface[] $filters + * @param LegacyFilterInterface[]|FilterInterface[] $filters */ private function getSearch(string $resourceClass, array $parts, array $filters): array { diff --git a/src/Metadata/FilterInterface.php b/src/Metadata/FilterInterface.php index 3a8b8036513..51ccea3521f 100644 --- a/src/Metadata/FilterInterface.php +++ b/src/Metadata/FilterInterface.php @@ -13,44 +13,57 @@ namespace ApiPlatform\Metadata; -/** - * Filters applicable on a resource. - * - * @author Kévin Dunglas - */ -interface FilterInterface -{ +if (interface_exists(\ApiPlatform\Api\FilterInterface::class)) { + class_alias( + \ApiPlatform\Api\FilterInterface::class, + __NAMESPACE__.'\FilterInterface' + ); + + if (false) { // @phpstan-ignore-line + interface FilterInterface extends \ApiPlatform\Api\FilterInterface + { + } + } +} else { /** - * Gets the description of this filter for the given resource. - * - * Returns an array with the filter parameter names as keys and array with the following data as values: - * - property: the property where the filter is applied - * - type: the type of the filter - * - required: if this filter is required - * - strategy (optional): the used strategy - * - is_collection (optional): if this filter is for collection - * - swagger (optional): additional parameters for the path operation, - * e.g. 'swagger' => [ - * 'description' => 'My Description', - * 'name' => 'My Name', - * 'type' => 'integer', - * ] - * - openapi (optional): additional parameters for the path operation in the version 3 spec, - * e.g. 'openapi' => [ - * 'description' => 'My Description', - * 'name' => 'My Name', - * 'schema' => [ - * 'type' => 'integer', - * ] - * ] - * - schema (optional): schema definition, - * e.g. 'schema' => [ - * 'type' => 'string', - * 'enum' => ['value_1', 'value_2'], - * ] - * The description can contain additional data specific to a filter. + * Filters applicable on a resource. * - * @see \ApiPlatform\OpenApi\Factory\OpenApiFactory::getFiltersParameters + * @author Kévin Dunglas */ - public function getDescription(string $resourceClass): array; + interface FilterInterface + { + /** + * Gets the description of this filter for the given resource. + * + * Returns an array with the filter parameter names as keys and array with the following data as values: + * - property: the property where the filter is applied + * - type: the type of the filter + * - required: if this filter is required + * - strategy (optional): the used strategy + * - is_collection (optional): if this filter is for collection + * - swagger (optional): additional parameters for the path operation, + * e.g. 'swagger' => [ + * 'description' => 'My Description', + * 'name' => 'My Name', + * 'type' => 'integer', + * ] + * - openapi (optional): additional parameters for the path operation in the version 3 spec, + * e.g. 'openapi' => [ + * 'description' => 'My Description', + * 'name' => 'My Name', + * 'schema' => [ + * 'type' => 'integer', + * ] + * ] + * - schema (optional): schema definition, + * e.g. 'schema' => [ + * 'type' => 'string', + * 'enum' => ['value_1', 'value_2'], + * ] + * The description can contain additional data specific to a filter. + * + * @see \ApiPlatform\OpenApi\Factory\OpenApiFactory::getFiltersParameters + */ + public function getDescription(string $resourceClass): array; + } } diff --git a/src/Metadata/IdentifiersExtractorInterface.php b/src/Metadata/IdentifiersExtractorInterface.php index 5ef91fde783..c8ac46d9929 100644 --- a/src/Metadata/IdentifiersExtractorInterface.php +++ b/src/Metadata/IdentifiersExtractorInterface.php @@ -15,17 +15,30 @@ use ApiPlatform\Exception\RuntimeException; -/** - * Extracts identifiers for a given Resource according to the retrieved Metadata. - * - * @author Antoine Bluchet - */ -interface IdentifiersExtractorInterface -{ +if (interface_exists(\ApiPlatform\Api\IdentifiersExtractorInterface::class)) { + class_alias( + \ApiPlatform\Api\IdentifiersExtractorInterface::class, + __NAMESPACE__.'\IdentifiersExtractorInterface' + ); + + if (false) { // @phpstan-ignore-line + interface IdentifiersExtractorInterface extends \ApiPlatform\Api\IdentifiersExtractorInterface + { + } + } +} else { /** - * Finds identifiers from an Item (object). + * Extracts identifiers for a given Resource according to the retrieved Metadata. * - * @throws RuntimeException + * @author Antoine Bluchet */ - public function getIdentifiersFromItem(object $item, Operation $operation = null, array $context = []): array; + interface IdentifiersExtractorInterface + { + /** + * Finds identifiers from an Item (object). + * + * @throws RuntimeException + */ + public function getIdentifiersFromItem(object $item, Operation $operation = null, array $context = []): array; + } } diff --git a/src/Metadata/IriConverterInterface.php b/src/Metadata/IriConverterInterface.php index b55bb75b984..56fd9618fba 100644 --- a/src/Metadata/IriConverterInterface.php +++ b/src/Metadata/IriConverterInterface.php @@ -17,28 +17,41 @@ use ApiPlatform\Metadata\Exception\ItemNotFoundException; use ApiPlatform\Metadata\Exception\RuntimeException; -/** - * Converts item and resources to IRI and vice versa. - * - * @author Kévin Dunglas - */ -interface IriConverterInterface -{ - /** - * Retrieves an item from its IRI. - * - * @throws InvalidArgumentException - * @throws ItemNotFoundException - */ - public function getResourceFromIri(string $iri, array $context = [], Operation $operation = null): object; +if (interface_exists(\ApiPlatform\Api\IriConverterInterface::class)) { + class_alias( + \ApiPlatform\Api\IriConverterInterface::class, + __NAMESPACE__.'\IriConverterInterface' + ); + if (false) { // @phpstan-ignore-line + interface IriConverterInterface extends \ApiPlatform\Api\IriConverterInterface + { + } + } +} else { /** - * Gets the IRI associated with the given item. - * - * @param object|class-string $resource + * Converts item and resources to IRI and vice versa. * - * @throws InvalidArgumentException - * @throws RuntimeException + * @author Kévin Dunglas */ - public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, Operation $operation = null, array $context = []): ?string; + interface IriConverterInterface + { + /** + * Retrieves an item from its IRI. + * + * @throws InvalidArgumentException + * @throws ItemNotFoundException + */ + public function getResourceFromIri(string $iri, array $context = [], Operation $operation = null): object; + + /** + * Gets the IRI associated with the given item. + * + * @param object|class-string $resource + * + * @throws InvalidArgumentException + * @throws RuntimeException + */ + public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, Operation $operation = null, array $context = []): ?string; + } } diff --git a/src/Metadata/ResourceClassResolverInterface.php b/src/Metadata/ResourceClassResolverInterface.php index 8dabc533502..afb460bb252 100644 --- a/src/Metadata/ResourceClassResolverInterface.php +++ b/src/Metadata/ResourceClassResolverInterface.php @@ -15,27 +15,40 @@ use ApiPlatform\Metadata\Exception\InvalidArgumentException; -/** - * Guesses which resource is associated with a given object. - * - * @author Kévin Dunglas - */ -interface ResourceClassResolverInterface -{ +if (interface_exists(\ApiPlatform\Api\ResourceClassResolverInterface::class)) { + class_alias( + \ApiPlatform\Api\ResourceClassResolverInterface::class, + __NAMESPACE__.'\ResourceClassResolverInterface' + ); + + if (false) { // @phpstan-ignore-line + interface ResourceClassResolverInterface extends \ApiPlatform\Api\ResourceClassResolverInterface + { + } + } +} else { /** - * Guesses the associated resource. - * - * @param string $resourceClass The expected resource class - * @param bool $strict If true, value must match the expected resource class + * Guesses which resource is associated with a given object. * - * @throws InvalidArgumentException + * @author Kévin Dunglas */ - public function getResourceClass(mixed $value, string $resourceClass = null, bool $strict = false): string; + interface ResourceClassResolverInterface + { + /** + * Guesses the associated resource. + * + * @param string $resourceClass The expected resource class + * @param bool $strict If true, value must match the expected resource class + * + * @throws InvalidArgumentException + */ + public function getResourceClass(mixed $value, string $resourceClass = null, bool $strict = false): string; - /** - * Is the given class a resource class? - */ - public function isResourceClass(string $type): bool; -} + /** + * Is the given class a resource class? + */ + public function isResourceClass(string $type): bool; + } -class_alias(ResourceClassResolverInterface::class, \ApiPlatform\Api\ResourceClassResolverInterface::class); + class_alias(ResourceClassResolverInterface::class, \ApiPlatform\Api\ResourceClassResolverInterface::class); +} diff --git a/src/Metadata/UriVariableTransformerInterface.php b/src/Metadata/UriVariableTransformerInterface.php index e91bfc6d7f6..8411cb4e8ee 100644 --- a/src/Metadata/UriVariableTransformerInterface.php +++ b/src/Metadata/UriVariableTransformerInterface.php @@ -15,25 +15,38 @@ use ApiPlatform\Exception\InvalidUriVariableException; -interface UriVariableTransformerInterface -{ - /** - * Transforms the value of a URI variable (identifier) to its type. - * - * @param mixed $value The URI variable value to transform - * @param array $types The guessed type behind the URI variable - * @param array $context Options available to the transformer - * - * @throws InvalidUriVariableException Occurs when the URI variable could not be transformed - */ - public function transform(mixed $value, array $types, array $context = []); +if (class_exists(\ApiPlatform\Api\UriVariableTransformerInterface::class)) { + class_alias( + \ApiPlatform\Api\UriVariableTransformerInterface::class, + __NAMESPACE__.'\UriVariableTransformerInterface' + ); - /** - * Checks whether the value of a URI variable can be transformed to its type by this transformer. - * - * @param mixed $value The URI variable value to transform - * @param array $types The types to which the URI variable value should be transformed - * @param array $context Options available to the transformer - */ - public function supportsTransformation(mixed $value, array $types, array $context = []): bool; + if (false) { // @phpstan-ignore-line + interface UriVariableTransformerInterface extends \ApiPlatform\Api\UriVariableTransformerInterface + { + } + } +} else { + interface UriVariableTransformerInterface + { + /** + * Transforms the value of a URI variable (identifier) to its type. + * + * @param mixed $value The URI variable value to transform + * @param array $types The guessed type behind the URI variable + * @param array $context Options available to the transformer + * + * @throws InvalidUriVariableException Occurs when the URI variable could not be transformed + */ + public function transform(mixed $value, array $types, array $context = []); + + /** + * Checks whether the value of a URI variable can be transformed to its type by this transformer. + * + * @param mixed $value The URI variable value to transform + * @param array $types The types to which the URI variable value should be transformed + * @param array $context Options available to the transformer + */ + public function supportsTransformation(mixed $value, array $types, array $context = []): bool; + } } diff --git a/src/Metadata/UriVariablesConverterInterface.php b/src/Metadata/UriVariablesConverterInterface.php index 22ba1e7214e..8320ba26746 100644 --- a/src/Metadata/UriVariablesConverterInterface.php +++ b/src/Metadata/UriVariablesConverterInterface.php @@ -15,22 +15,35 @@ use ApiPlatform\Metadata\Exception\InvalidIdentifierException; -/** - * Identifier converter. - * - * @author Antoine Bluchet - */ -interface UriVariablesConverterInterface -{ +if (interface_exists(\ApiPlatform\Api\UriVariablesConverterInterface::class)) { + class_alias( + \ApiPlatform\Api\UriVariablesConverterInterface::class, + __NAMESPACE__.'\UriVariablesConverterInterface' + ); + + if (false) { // @phpstan-ignore-line + interface UriVariablesConverterInterface extends \ApiPlatform\Api\UriVariablesConverterInterface + { + } + } +} else { /** - * Takes an array of strings representing URI variables (identifiers) and transform their values to the expected type. - * - * @param array $data URI variables to convert to PHP values - * @param string $class The class to which the URI variables belong to - * - * @throws InvalidIdentifierException + * Identifier converter. * - * @return array Array indexed by identifiers properties with their values denormalized + * @author Antoine Bluchet */ - public function convert(array $data, string $class, array $context = []): array; + interface UriVariablesConverterInterface + { + /** + * Takes an array of strings representing URI variables (identifiers) and transform their values to the expected type. + * + * @param array $data URI variables to convert to PHP values + * @param string $class The class to which the URI variables belong to + * + * @throws InvalidIdentifierException + * + * @return array Array indexed by identifiers properties with their values denormalized + */ + public function convert(array $data, string $class, array $context = []): array; + } } diff --git a/src/Metadata/UrlGeneratorInterface.php b/src/Metadata/UrlGeneratorInterface.php index 5df27ef16e4..82a412bbc41 100644 --- a/src/Metadata/UrlGeneratorInterface.php +++ b/src/Metadata/UrlGeneratorInterface.php @@ -17,68 +17,81 @@ use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\RouteNotFoundException; -/** - * UrlGeneratorInterface is the interface that all URL generator classes must implement. - * - * This interface has been imported and adapted from the Symfony project. - * - * The constants in this interface define the different types of resource references that - * are declared in RFC 3986: http://tools.ietf.org/html/rfc3986 - * We are using the term "URL" instead of "URI" as this is more common in web applications - * and we do not need to distinguish them as the difference is mostly semantical and - * less technical. Generating URIs, i.e. representation-independent resource identifiers, - * is also possible. - * - * @author Fabien Potencier - * @author Tobias Schultze - * @copyright Fabien Potencier - */ -interface UrlGeneratorInterface -{ - /** - * Generates an absolute URL, e.g. "http://example.com/dir/file". - */ - public const ABS_URL = 0; - - /** - * Generates an absolute path, e.g. "/dir/file". - */ - public const ABS_PATH = 1; - - /** - * Generates a relative path based on the current request path, e.g. "../parent-file". - * - * @see UrlGenerator::getRelativePath() - */ - public const REL_PATH = 2; - - /** - * Generates a network path, e.g. "//example.com/dir/file". - * Such reference reuses the current scheme but specifies the host. - */ - public const NET_PATH = 3; +if (interface_exists(\ApiPlatform\Api\UrlGeneratorInterface::class)) { + class_alias( + \ApiPlatform\Api\UrlGeneratorInterface::class, + __NAMESPACE__.'\UrlGeneratorInterface' + ); + if (false) { // @phpstan-ignore-line + interface UrlGeneratorInterface extends \ApiPlatform\Api\UrlGeneratorInterface + { + } + } +} else { /** - * Generates a URL or path for a specific route based on the given parameters. - * - * Parameters that reference placeholders in the route pattern will substitute them in the - * path or host. Extra params are added as query string to the URL. + * UrlGeneratorInterface is the interface that all URL generator classes must implement. * - * When the passed reference type cannot be generated for the route because it requires a different - * host or scheme than the current one, the method will return a more comprehensive reference - * that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH - * but the route requires the https scheme whereas the current scheme is http, it will instead return an - * ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches - * the route in any case. + * This interface has been imported and adapted from the Symfony project. * - * If there is no route with the given name, the generator must throw the RouteNotFoundException. + * The constants in this interface define the different types of resource references that + * are declared in RFC 3986: http://tools.ietf.org/html/rfc3986 + * We are using the term "URL" instead of "URI" as this is more common in web applications + * and we do not need to distinguish them as the difference is mostly semantical and + * less technical. Generating URIs, i.e. representation-independent resource identifiers, + * is also possible. * - * The special parameter _fragment will be used as the document fragment suffixed to the final URL. - * - * @throws RouteNotFoundException If the named route doesn't exist - * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route - * @throws InvalidParameterException When a parameter value for a placeholder is not correct because - * it does not match the requirement + * @author Fabien Potencier + * @author Tobias Schultze + * @copyright Fabien Potencier */ - public function generate(string $name, array $parameters = [], int $referenceType = self::ABS_PATH): string; + interface UrlGeneratorInterface + { + /** + * Generates an absolute URL, e.g. "http://example.com/dir/file". + */ + public const ABS_URL = 0; + + /** + * Generates an absolute path, e.g. "/dir/file". + */ + public const ABS_PATH = 1; + + /** + * Generates a relative path based on the current request path, e.g. "../parent-file". + * + * @see UrlGenerator::getRelativePath() + */ + public const REL_PATH = 2; + + /** + * Generates a network path, e.g. "//example.com/dir/file". + * Such reference reuses the current scheme but specifies the host. + */ + public const NET_PATH = 3; + + /** + * Generates a URL or path for a specific route based on the given parameters. + * + * Parameters that reference placeholders in the route pattern will substitute them in the + * path or host. Extra params are added as query string to the URL. + * + * When the passed reference type cannot be generated for the route because it requires a different + * host or scheme than the current one, the method will return a more comprehensive reference + * that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH + * but the route requires the https scheme whereas the current scheme is http, it will instead return an + * ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches + * the route in any case. + * + * If there is no route with the given name, the generator must throw the RouteNotFoundException. + * + * The special parameter _fragment will be used as the document fragment suffixed to the final URL. + * + * @throws RouteNotFoundException If the named route doesn't exist + * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route + * @throws InvalidParameterException When a parameter value for a placeholder is not correct because + * it does not match the requirement + */ + public function generate(string $name, array $parameters = [], int $referenceType = self::ABS_PATH): string; + } } diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index fb25fa780b9..7ba44f9789a 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -13,6 +13,8 @@ namespace ApiPlatform\Serializer; +use ApiPlatform\Api\IriConverterInterface as LegacyIriConverterInterface; +use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface; use ApiPlatform\Exception\InvalidArgumentException; use ApiPlatform\Exception\ItemNotFoundException; use ApiPlatform\Metadata\ApiProperty; @@ -61,7 +63,7 @@ abstract class AbstractItemNormalizer extends AbstractObjectNormalizer protected array $localCache = []; protected array $localFactoryOptionsCache = []; - public function __construct(protected PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, protected PropertyMetadataFactoryInterface $propertyMetadataFactory, protected IriConverterInterface $iriConverter, protected ResourceClassResolverInterface $resourceClassResolver, PropertyAccessorInterface $propertyAccessor = null, NameConverterInterface $nameConverter = null, ClassMetadataFactoryInterface $classMetadataFactory = null, array $defaultContext = [], ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, protected ?ResourceAccessCheckerInterface $resourceAccessChecker = null) + public function __construct(protected PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, protected PropertyMetadataFactoryInterface $propertyMetadataFactory, protected LegacyIriConverterInterface|IriConverterInterface $iriConverter, protected LegacyResourceClassResolverInterface|ResourceClassResolverInterface $resourceClassResolver, PropertyAccessorInterface $propertyAccessor = null, NameConverterInterface $nameConverter = null, ClassMetadataFactoryInterface $classMetadataFactory = null, array $defaultContext = [], ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, protected ?ResourceAccessCheckerInterface $resourceAccessChecker = null) { if (!isset($defaultContext['circular_reference_handler'])) { $defaultContext['circular_reference_handler'] = fn ($object): ?string => $this->iriConverter->getIriFromResource($object); diff --git a/src/State/UriVariablesResolverTrait.php b/src/State/UriVariablesResolverTrait.php index b9e222aab0a..5982890574f 100644 --- a/src/State/UriVariablesResolverTrait.php +++ b/src/State/UriVariablesResolverTrait.php @@ -13,6 +13,7 @@ namespace ApiPlatform\State; +use ApiPlatform\Api\UriVariablesConverterInterface as LegacyUriVariablesConverterInterface; use ApiPlatform\Metadata\Exception\InvalidIdentifierException; use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\UriVariablesConverterInterface; @@ -20,7 +21,7 @@ trait UriVariablesResolverTrait { - private ?UriVariablesConverterInterface $uriVariablesConverter = null; + private null|LegacyUriVariablesConverterInterface|UriVariablesConverterInterface $uriVariablesConverter = null; /** * Resolves an operation's UriVariables to their identifiers values. diff --git a/src/Symfony/EventListener/ReadListener.php b/src/Symfony/EventListener/ReadListener.php index 5e41061aa5e..7cad346945f 100644 --- a/src/Symfony/EventListener/ReadListener.php +++ b/src/Symfony/EventListener/ReadListener.php @@ -13,11 +13,12 @@ namespace ApiPlatform\Symfony\EventListener; -use ApiPlatform\Api\UriVariablesConverterInterface; +use ApiPlatform\Api\UriVariablesConverterInterface as LegacyUriVariablesConverterInterface; use ApiPlatform\Exception\InvalidIdentifierException; use ApiPlatform\Exception\InvalidUriVariableException; use ApiPlatform\Metadata\Put; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; +use ApiPlatform\Metadata\UriVariablesConverterInterface; use ApiPlatform\Metadata\Util\CloneTrait; use ApiPlatform\Serializer\SerializerContextBuilderInterface; use ApiPlatform\State\Exception\ProviderNotFoundException; @@ -44,7 +45,7 @@ public function __construct( private readonly ProviderInterface $provider, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, private readonly ?SerializerContextBuilderInterface $serializerContextBuilder = null, - UriVariablesConverterInterface $uriVariablesConverter = null, + LegacyUriVariablesConverterInterface|UriVariablesConverterInterface $uriVariablesConverter = null, ) { $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory; $this->uriVariablesConverter = $uriVariablesConverter; diff --git a/src/Symfony/EventListener/WriteListener.php b/src/Symfony/EventListener/WriteListener.php index 08c5db56ae5..88559a323d7 100644 --- a/src/Symfony/EventListener/WriteListener.php +++ b/src/Symfony/EventListener/WriteListener.php @@ -13,6 +13,9 @@ namespace ApiPlatform\Symfony\EventListener; +use ApiPlatform\Api\IriConverterInterface as LegacyIriConverterInterface; +use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface; +use ApiPlatform\Api\UriVariablesConverterInterface as LegacyUriVariablesConverterInterface; use ApiPlatform\Exception\InvalidIdentifierException; use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; @@ -41,10 +44,10 @@ final class WriteListener public function __construct( private readonly ProcessorInterface $processor, - private readonly IriConverterInterface $iriConverter, - private readonly ResourceClassResolverInterface $resourceClassResolver, + private readonly LegacyIriConverterInterface|IriConverterInterface $iriConverter, + private readonly ResourceClassResolverInterface|LegacyResourceClassResolverInterface $resourceClassResolver, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, - UriVariablesConverterInterface $uriVariablesConverter = null, + LegacyUriVariablesConverterInterface|UriVariablesConverterInterface $uriVariablesConverter = null, ) { $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory; $this->uriVariablesConverter = $uriVariablesConverter; diff --git a/tests/Doctrine/EventListener/PublishMercureUpdatesListenerTest.php b/tests/Doctrine/EventListener/PublishMercureUpdatesListenerTest.php index 4e9c87b2644..78a5a1680ba 100644 --- a/tests/Doctrine/EventListener/PublishMercureUpdatesListenerTest.php +++ b/tests/Doctrine/EventListener/PublishMercureUpdatesListenerTest.php @@ -13,17 +13,17 @@ namespace ApiPlatform\Tests\Doctrine\EventListener; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\ResourceClassResolverInterface; -use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\Doctrine\EventListener\PublishMercureUpdatesListener; use ApiPlatform\GraphQl\Subscription\MercureSubscriptionIriGeneratorInterface as GraphQlMercureSubscriptionIriGeneratorInterface; use ApiPlatform\GraphQl\Subscription\SubscriptionManagerInterface as GraphQlSubscriptionManagerInterface; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; +use ApiPlatform\Metadata\ResourceClassResolverInterface; +use ApiPlatform\Metadata\UrlGeneratorInterface; use ApiPlatform\Tests\Fixtures\NotAResource; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCar; diff --git a/tests/Doctrine/EventListener/PurgeHttpCacheListenerTest.php b/tests/Doctrine/EventListener/PurgeHttpCacheListenerTest.php index 726ecc5dfbe..797db055567 100644 --- a/tests/Doctrine/EventListener/PurgeHttpCacheListenerTest.php +++ b/tests/Doctrine/EventListener/PurgeHttpCacheListenerTest.php @@ -13,14 +13,14 @@ namespace ApiPlatform\Tests\Doctrine\EventListener; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\ResourceClassResolverInterface; -use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\Doctrine\EventListener\PurgeHttpCacheListener; use ApiPlatform\Exception\InvalidArgumentException; use ApiPlatform\Exception\ItemNotFoundException; use ApiPlatform\HttpCache\PurgerInterface; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\IriConverterInterface; +use ApiPlatform\Metadata\ResourceClassResolverInterface; +use ApiPlatform\Metadata\UrlGeneratorInterface; use ApiPlatform\Tests\Fixtures\NotAResource; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\ContainNonResource; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; diff --git a/tests/Doctrine/Odm/Filter/SearchFilterTest.php b/tests/Doctrine/Odm/Filter/SearchFilterTest.php index 746db94d55a..845e3a3d11c 100644 --- a/tests/Doctrine/Odm/Filter/SearchFilterTest.php +++ b/tests/Doctrine/Odm/Filter/SearchFilterTest.php @@ -13,9 +13,9 @@ namespace ApiPlatform\Tests\Doctrine\Odm\Filter; -use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Doctrine\Odm\Filter\SearchFilter; use ApiPlatform\Exception\InvalidArgumentException; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Test\DoctrineMongoDbOdmFilterTestCase; use ApiPlatform\Tests\Doctrine\Common\Filter\SearchFilterTestTrait; use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy; diff --git a/tests/Doctrine/Orm/Filter/SearchFilterTest.php b/tests/Doctrine/Orm/Filter/SearchFilterTest.php index 37e74519aab..8644ec7a289 100644 --- a/tests/Doctrine/Orm/Filter/SearchFilterTest.php +++ b/tests/Doctrine/Orm/Filter/SearchFilterTest.php @@ -13,11 +13,11 @@ namespace ApiPlatform\Tests\Doctrine\Orm\Filter; -use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator; use ApiPlatform\Exception\InvalidArgumentException; use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Test\DoctrineOrmFilterTestCase; use ApiPlatform\Tests\Doctrine\Common\Filter\SearchFilterTestTrait; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; diff --git a/tests/Fixtures/TestBundle/Entity/UriVariableMask.php b/tests/Fixtures/TestBundle/Entity/UriVariableMask.php new file mode 100644 index 00000000000..f50d611b43c --- /dev/null +++ b/tests/Fixtures/TestBundle/Entity/UriVariableMask.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; + +use ApiPlatform\Metadata\Operation; +use ApiPlatform\Metadata\Post; +use Doctrine\ORM\Mapping as ORM; + +#[Post(uriTemplate: '/uri_variable_mask/{id}/{direction}', processor: [UriVariableMask::class, 'process'])] +#[ORM\Entity] +class UriVariableMask +{ + #[ORM\Column(type: 'string')] + #[ORM\Id] + public ?string $id; + + public static function process($data, Operation $operation, array $uriVariables = []) + { + return $data; + } +} diff --git a/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php b/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php index 28f9ef27228..1b9c42ff1d8 100644 --- a/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php @@ -13,8 +13,8 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\Serializer\Denormalizer; +use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Metadata\Get; -use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\UrlGeneratorInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Document\RelatedDummy as RelatedDummyDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Document\ThirdLevel as ThirdLevelDocument; diff --git a/tests/Hal/Serializer/EntrypointNormalizerTest.php b/tests/Hal/Serializer/EntrypointNormalizerTest.php index eee21751bde..a1af82bda2e 100644 --- a/tests/Hal/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hal/Serializer/EntrypointNormalizerTest.php @@ -14,16 +14,16 @@ namespace ApiPlatform\Tests\Hal\Serializer; use ApiPlatform\Api\Entrypoint; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\Documentation\Entrypoint as DocumentationEntrypoint; use ApiPlatform\Hal\Serializer\EntrypointNormalizer; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; use ApiPlatform\Metadata\Resource\ResourceNameCollection; +use ApiPlatform\Metadata\UrlGeneratorInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; diff --git a/tests/Hal/Serializer/ItemNormalizerTest.php b/tests/Hal/Serializer/ItemNormalizerTest.php index 04001d90dbd..171d83a4752 100644 --- a/tests/Hal/Serializer/ItemNormalizerTest.php +++ b/tests/Hal/Serializer/ItemNormalizerTest.php @@ -13,13 +13,13 @@ namespace ApiPlatform\Tests\Hal\Serializer; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\ResourceClassResolverInterface; use ApiPlatform\Hal\Serializer\ItemNormalizer; use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; use ApiPlatform\Metadata\Property\PropertyNameCollection; +use ApiPlatform\Metadata\ResourceClassResolverInterface; use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5452\ActivableInterface; use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5452\Author; use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5452\Book; diff --git a/tests/Hal/Serializer/ObjectNormalizerTest.php b/tests/Hal/Serializer/ObjectNormalizerTest.php index c503e3ead2b..5215714635f 100644 --- a/tests/Hal/Serializer/ObjectNormalizerTest.php +++ b/tests/Hal/Serializer/ObjectNormalizerTest.php @@ -13,8 +13,8 @@ namespace ApiPlatform\Tests\Hal\Serializer; -use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Hal\Serializer\ObjectNormalizer; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; diff --git a/tests/Hydra/Serializer/CollectionNormalizerTest.php b/tests/Hydra/Serializer/CollectionNormalizerTest.php index a479a5601c9..2ba7d9e1eb8 100644 --- a/tests/Hydra/Serializer/CollectionNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionNormalizerTest.php @@ -13,11 +13,11 @@ namespace ApiPlatform\Tests\Hydra\Serializer; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\ResourceClassResolverInterface; -use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\Hydra\Serializer\CollectionNormalizer; use ApiPlatform\JsonLd\ContextBuilderInterface; +use ApiPlatform\Metadata\IriConverterInterface; +use ApiPlatform\Metadata\ResourceClassResolverInterface; +use ApiPlatform\Metadata\UrlGeneratorInterface; use ApiPlatform\Serializer\AbstractItemNormalizer; use ApiPlatform\State\Pagination\PaginatorInterface; use ApiPlatform\State\Pagination\PartialPaginatorInterface; diff --git a/tests/Hydra/Serializer/EntrypointNormalizerTest.php b/tests/Hydra/Serializer/EntrypointNormalizerTest.php index da009ff2afc..69b0f7501c9 100644 --- a/tests/Hydra/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hydra/Serializer/EntrypointNormalizerTest.php @@ -14,16 +14,16 @@ namespace ApiPlatform\Tests\Hydra\Serializer; use ApiPlatform\Api\Entrypoint; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\Documentation\Entrypoint as DocumentationEntrypoint; use ApiPlatform\Hydra\Serializer\EntrypointNormalizer; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; use ApiPlatform\Metadata\Resource\ResourceNameCollection; +use ApiPlatform\Metadata\UrlGeneratorInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\FooDummy; use PHPUnit\Framework\TestCase; diff --git a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php index 2bcfa0b1941..eb035c848cc 100644 --- a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php +++ b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php @@ -14,19 +14,19 @@ namespace ApiPlatform\Tests\JsonApi\Serializer; use ApiPlatform\Api\Entrypoint; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\Documentation\Entrypoint as DocumentationEntrypoint; use ApiPlatform\JsonApi\Serializer\EntrypointNormalizer; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; use ApiPlatform\Metadata\Resource\ResourceNameCollection; +use ApiPlatform\Metadata\UrlGeneratorInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyCar; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy; diff --git a/tests/JsonApi/Serializer/ItemNormalizerTest.php b/tests/JsonApi/Serializer/ItemNormalizerTest.php index 802537cd711..e8e40f06c04 100644 --- a/tests/JsonApi/Serializer/ItemNormalizerTest.php +++ b/tests/JsonApi/Serializer/ItemNormalizerTest.php @@ -13,19 +13,19 @@ namespace ApiPlatform\Tests\JsonApi\Serializer; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\ResourceClassResolverInterface; use ApiPlatform\JsonApi\Serializer\ItemNormalizer; use ApiPlatform\JsonApi\Serializer\ReservedAttributeNameConverter; use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; use ApiPlatform\Metadata\Property\PropertyNameCollection; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; +use ApiPlatform\Metadata\ResourceClassResolverInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\CircularReference; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy; diff --git a/tests/JsonLd/ContextBuilderTest.php b/tests/JsonLd/ContextBuilderTest.php index 7671ba6284e..466210fb0c2 100644 --- a/tests/JsonLd/ContextBuilderTest.php +++ b/tests/JsonLd/ContextBuilderTest.php @@ -13,12 +13,11 @@ namespace ApiPlatform\Tests\JsonLd; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\JsonLd\ContextBuilder; use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; @@ -27,6 +26,7 @@ use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; use ApiPlatform\Metadata\Resource\ResourceNameCollection; +use ApiPlatform\Metadata\UrlGeneratorInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\OutputDto; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use PHPUnit\Framework\TestCase; diff --git a/tests/JsonLd/Serializer/ItemNormalizerTest.php b/tests/JsonLd/Serializer/ItemNormalizerTest.php index be607b30d84..9f062bac54d 100644 --- a/tests/JsonLd/Serializer/ItemNormalizerTest.php +++ b/tests/JsonLd/Serializer/ItemNormalizerTest.php @@ -13,20 +13,20 @@ namespace ApiPlatform\Tests\JsonLd\Serializer; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\ResourceClassResolverInterface; -use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\JsonLd\ContextBuilderInterface; use ApiPlatform\JsonLd\Serializer\ItemNormalizer; use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operations; use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; use ApiPlatform\Metadata\Property\PropertyNameCollection; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; +use ApiPlatform\Metadata\ResourceClassResolverInterface; +use ApiPlatform\Metadata\UrlGeneratorInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use PHPUnit\Framework\TestCase; use Prophecy\Argument; diff --git a/tests/JsonLd/Serializer/ObjectNormalizerTest.php b/tests/JsonLd/Serializer/ObjectNormalizerTest.php index 99e8da1d576..65dcfe619b4 100644 --- a/tests/JsonLd/Serializer/ObjectNormalizerTest.php +++ b/tests/JsonLd/Serializer/ObjectNormalizerTest.php @@ -13,9 +13,9 @@ namespace ApiPlatform\Tests\JsonLd\Serializer; -use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\JsonLd\AnonymousContextBuilderInterface; use ApiPlatform\JsonLd\Serializer\ObjectNormalizer; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use PHPUnit\Framework\TestCase; use Prophecy\Argument; diff --git a/tests/State/RespondProcessorTest.php b/tests/State/RespondProcessorTest.php index 4ccb52445a4..449215ab155 100644 --- a/tests/State/RespondProcessorTest.php +++ b/tests/State/RespondProcessorTest.php @@ -13,8 +13,8 @@ namespace ApiPlatform\Tests\State; -use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Operation\Factory\OperationMetadataFactoryInterface; use ApiPlatform\Metadata\ResourceClassResolverInterface; use ApiPlatform\State\Processor\RespondProcessor; diff --git a/tests/Symfony/EventListener/WriteListenerTest.php b/tests/Symfony/EventListener/WriteListenerTest.php index 957ec3f1e0d..9c9992599d7 100644 --- a/tests/Symfony/EventListener/WriteListenerTest.php +++ b/tests/Symfony/EventListener/WriteListenerTest.php @@ -13,11 +13,10 @@ namespace ApiPlatform\Tests\Symfony\EventListener; -use ApiPlatform\Api\IriConverterInterface; -use ApiPlatform\Api\ResourceClassResolverInterface; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Delete; use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\IriConverterInterface; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Operations; @@ -26,6 +25,7 @@ use ApiPlatform\Metadata\Put; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; +use ApiPlatform\Metadata\ResourceClassResolverInterface; use ApiPlatform\State\ProcessorInterface; use ApiPlatform\Symfony\EventListener\WriteListener; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\AttributeResource;