Skip to content

Commit b7c094a

Browse files
authored
fix(metadata): interface breaking in 3.2 (#5883)
To ease subtree split we move the `Api` to `Metadata` namespace.
1 parent de8d583 commit b7c094a

40 files changed

+568
-269
lines changed

src/Api/FilterInterface.php

+39-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,44 @@
1313

1414
namespace ApiPlatform\Api;
1515

16-
interface FilterInterface extends \ApiPlatform\Metadata\FilterInterface
16+
/**
17+
* Filters applicable on a resource.
18+
*
19+
* @author Kévin Dunglas <[email protected]>
20+
*/
21+
interface FilterInterface
1722
{
23+
/**
24+
* Gets the description of this filter for the given resource.
25+
*
26+
* Returns an array with the filter parameter names as keys and array with the following data as values:
27+
* - property: the property where the filter is applied
28+
* - type: the type of the filter
29+
* - required: if this filter is required
30+
* - strategy (optional): the used strategy
31+
* - is_collection (optional): if this filter is for collection
32+
* - swagger (optional): additional parameters for the path operation,
33+
* e.g. 'swagger' => [
34+
* 'description' => 'My Description',
35+
* 'name' => 'My Name',
36+
* 'type' => 'integer',
37+
* ]
38+
* - openapi (optional): additional parameters for the path operation in the version 3 spec,
39+
* e.g. 'openapi' => [
40+
* 'description' => 'My Description',
41+
* 'name' => 'My Name',
42+
* 'schema' => [
43+
* 'type' => 'integer',
44+
* ]
45+
* ]
46+
* - schema (optional): schema definition,
47+
* e.g. 'schema' => [
48+
* 'type' => 'string',
49+
* 'enum' => ['value_1', 'value_2'],
50+
* ]
51+
* The description can contain additional data specific to a filter.
52+
*
53+
* @see \ApiPlatform\OpenApi\Factory\OpenApiFactory::getFiltersParameters
54+
*/
55+
public function getDescription(string $resourceClass): array;
1856
}

src/Api/FilterLocatorTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ApiPlatform\Api;
1515

1616
use ApiPlatform\Exception\InvalidArgumentException;
17-
use ApiPlatform\Metadata\FilterInterface;
17+
use ApiPlatform\Metadata\FilterInterface as MetadataFilterInterface;
1818
use Psr\Container\ContainerInterface;
1919

2020
/**
@@ -45,7 +45,7 @@ private function setFilterLocator(?ContainerInterface $filterLocator, bool $allo
4545
/**
4646
* Gets a filter with a backward compatibility.
4747
*/
48-
private function getFilter(string $filterId): ?FilterInterface
48+
private function getFilter(string $filterId): null|FilterInterface|MetadataFilterInterface
4949
{
5050
if ($this->filterLocator && $this->filterLocator->has($filterId)) {
5151
return $this->filterLocator->get($filterId);

src/Api/IdentifiersExtractorInterface.php

+15-10
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313

1414
namespace ApiPlatform\Api;
1515

16-
class_exists(\ApiPlatform\Metadata\IdentifiersExtractorInterface::class);
16+
use ApiPlatform\Metadata\Exception\RuntimeException;
17+
use ApiPlatform\Metadata\Operation;
1718

18-
class_alias(
19-
\ApiPlatform\Metadata\IdentifiersExtractorInterface::class,
20-
__NAMESPACE__.'\IdentifiersExtractorInterface'
21-
);
22-
23-
if (false) { // @phpstan-ignore-line
24-
interface IdentifiersExtractorInterface extends \ApiPlatform\Metadata\IdentifiersExtractorInterface
25-
{
26-
}
19+
/**
20+
* Extracts identifiers for a given Resource according to the retrieved Metadata.
21+
*
22+
* @author Antoine Bluchet <[email protected]>
23+
*/
24+
interface IdentifiersExtractorInterface
25+
{
26+
/**
27+
* Finds identifiers from an Item (object).
28+
*
29+
* @throws RuntimeException
30+
*/
31+
public function getIdentifiersFromItem(object $item, Operation $operation = null, array $context = []): array;
2732
}

src/Api/IriConverterInterface.php

+27-9
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,33 @@
1313

1414
namespace ApiPlatform\Api;
1515

16-
class_exists(\ApiPlatform\Metadata\IriConverterInterface::class);
16+
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
17+
use ApiPlatform\Metadata\Exception\ItemNotFoundException;
18+
use ApiPlatform\Metadata\Exception\RuntimeException;
19+
use ApiPlatform\Metadata\Operation;
1720

18-
class_alias(
19-
\ApiPlatform\Metadata\IriConverterInterface::class,
20-
__NAMESPACE__.'\IriConverterInterface'
21-
);
21+
/**
22+
* Converts item and resources to IRI and vice versa.
23+
*
24+
* @author Kévin Dunglas <[email protected]>
25+
*/
26+
interface IriConverterInterface
27+
{
28+
/**
29+
* Retrieves an item from its IRI.
30+
*
31+
* @throws InvalidArgumentException
32+
* @throws ItemNotFoundException
33+
*/
34+
public function getResourceFromIri(string $iri, array $context = [], Operation $operation = null): object;
2235

23-
if (false) { // @phpstan-ignore-line
24-
interface IriConverterInterface extends \ApiPlatform\Metadata\IriConverterInterface
25-
{
26-
}
36+
/**
37+
* Gets the IRI associated with the given item.
38+
*
39+
* @param object|class-string $resource
40+
*
41+
* @throws InvalidArgumentException
42+
* @throws RuntimeException
43+
*/
44+
public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, Operation $operation = null, array $context = []): ?string;
2745
}

src/Api/ResourceClassResolverInterface.php

+22-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,27 @@
1313

1414
namespace ApiPlatform\Api;
1515

16-
class_exists(\ApiPlatform\Metadata\ResourceClassResolverInterface::class);
16+
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
1717

18-
if (false) { // @phpstan-ignore-line
19-
interface ResourceClassResolverInterface extends \ApiPlatform\Metadata\ResourceClassResolverInterface
20-
{
21-
}
18+
/**
19+
* Guesses which resource is associated with a given object.
20+
*
21+
* @author Kévin Dunglas <[email protected]>
22+
*/
23+
interface ResourceClassResolverInterface
24+
{
25+
/**
26+
* Guesses the associated resource.
27+
*
28+
* @param string $resourceClass The expected resource class
29+
* @param bool $strict If true, value must match the expected resource class
30+
*
31+
* @throws InvalidArgumentException
32+
*/
33+
public function getResourceClass(mixed $value, string $resourceClass = null, bool $strict = false): string;
34+
35+
/**
36+
* Is the given class a resource class?
37+
*/
38+
public function isResourceClass(string $type): bool;
2239
}

src/Api/UriVariableTransformerInterface.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@
1313

1414
namespace ApiPlatform\Api;
1515

16-
interface UriVariableTransformerInterface extends \ApiPlatform\Metadata\UriVariableTransformerInterface
16+
use ApiPlatform\Exception\InvalidUriVariableException;
17+
18+
interface UriVariableTransformerInterface
1719
{
20+
/**
21+
* Transforms the value of a URI variable (identifier) to its type.
22+
*
23+
* @param mixed $value The URI variable value to transform
24+
* @param array $types The guessed type behind the URI variable
25+
* @param array $context Options available to the transformer
26+
*
27+
* @throws InvalidUriVariableException Occurs when the URI variable could not be transformed
28+
*/
29+
public function transform(mixed $value, array $types, array $context = []);
30+
31+
/**
32+
* Checks whether the value of a URI variable can be transformed to its type by this transformer.
33+
*
34+
* @param mixed $value The URI variable value to transform
35+
* @param array $types The types to which the URI variable value should be transformed
36+
* @param array $context Options available to the transformer
37+
*/
38+
public function supportsTransformation(mixed $value, array $types, array $context = []): bool;
1839
}

src/Api/UriVariablesConverterInterface.php

+19-10
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@
1313

1414
namespace ApiPlatform\Api;
1515

16-
class_exists(\ApiPlatform\Metadata\UriVariablesConverterInterface::class);
16+
use ApiPlatform\Metadata\Exception\InvalidIdentifierException;
1717

18-
class_alias(
19-
\ApiPlatform\Metadata\UriVariablesConverterInterface::class,
20-
__NAMESPACE__.'\UriVariablesConverterInterface'
21-
);
22-
23-
if (false) { // @phpstan-ignore-line
24-
interface UriVariablesConverterInterface extends \ApiPlatform\Metadata\UriVariablesConverterInterface
25-
{
26-
}
18+
/**
19+
* Identifier converter.
20+
*
21+
* @author Antoine Bluchet <[email protected]>
22+
*/
23+
interface UriVariablesConverterInterface
24+
{
25+
/**
26+
* Takes an array of strings representing URI variables (identifiers) and transform their values to the expected type.
27+
*
28+
* @param array $data URI variables to convert to PHP values
29+
* @param string $class The class to which the URI variables belong to
30+
*
31+
* @throws InvalidIdentifierException
32+
*
33+
* @return array Array indexed by identifiers properties with their values denormalized
34+
*/
35+
public function convert(array $data, string $class, array $context = []): array;
2736
}

src/Api/UrlGeneratorInterface.php

+68-9
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,72 @@
1313

1414
namespace ApiPlatform\Api;
1515

16-
class_alias(
17-
\ApiPlatform\Metadata\UrlGeneratorInterface::class,
18-
__NAMESPACE__.'\UrlGeneratorInterface'
19-
);
20-
21-
if (false) { // @phpstan-ignore-line
22-
interface UrlGeneratorInterface extends \ApiPlatform\Metadata\UrlGeneratorInterface
23-
{
24-
}
16+
use Symfony\Component\Routing\Exception\InvalidParameterException;
17+
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
18+
use Symfony\Component\Routing\Exception\RouteNotFoundException;
19+
20+
/**
21+
* UrlGeneratorInterface is the interface that all URL generator classes must implement.
22+
*
23+
* This interface has been imported and adapted from the Symfony project.
24+
*
25+
* The constants in this interface define the different types of resource references that
26+
* are declared in RFC 3986: http://tools.ietf.org/html/rfc3986
27+
* We are using the term "URL" instead of "URI" as this is more common in web applications
28+
* and we do not need to distinguish them as the difference is mostly semantical and
29+
* less technical. Generating URIs, i.e. representation-independent resource identifiers,
30+
* is also possible.
31+
*
32+
* @author Fabien Potencier <[email protected]>
33+
* @author Tobias Schultze <http://tobion.de>
34+
* @copyright Fabien Potencier
35+
*/
36+
interface UrlGeneratorInterface
37+
{
38+
/**
39+
* Generates an absolute URL, e.g. "http://example.com/dir/file".
40+
*/
41+
public const ABS_URL = 0;
42+
43+
/**
44+
* Generates an absolute path, e.g. "/dir/file".
45+
*/
46+
public const ABS_PATH = 1;
47+
48+
/**
49+
* Generates a relative path based on the current request path, e.g. "../parent-file".
50+
*
51+
* @see UrlGenerator::getRelativePath()
52+
*/
53+
public const REL_PATH = 2;
54+
55+
/**
56+
* Generates a network path, e.g. "//example.com/dir/file".
57+
* Such reference reuses the current scheme but specifies the host.
58+
*/
59+
public const NET_PATH = 3;
60+
61+
/**
62+
* Generates a URL or path for a specific route based on the given parameters.
63+
*
64+
* Parameters that reference placeholders in the route pattern will substitute them in the
65+
* path or host. Extra params are added as query string to the URL.
66+
*
67+
* When the passed reference type cannot be generated for the route because it requires a different
68+
* host or scheme than the current one, the method will return a more comprehensive reference
69+
* that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH
70+
* but the route requires the https scheme whereas the current scheme is http, it will instead return an
71+
* ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches
72+
* the route in any case.
73+
*
74+
* If there is no route with the given name, the generator must throw the RouteNotFoundException.
75+
*
76+
* The special parameter _fragment will be used as the document fragment suffixed to the final URL.
77+
*
78+
* @throws RouteNotFoundException If the named route doesn't exist
79+
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
80+
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
81+
* it does not match the requirement
82+
*/
83+
public function generate(string $name, array $parameters = [], int $referenceType = self::ABS_PATH): string;
2584
}

src/Doctrine/Odm/Filter/SearchFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function __construct(ManagerRegistry $managerRegistry, IriConverterInterf
149149
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
150150
}
151151

152-
protected function getIriConverter(): IriConverterInterface
152+
protected function getIriConverter(): LegacyIriConverterInterface|IriConverterInterface
153153
{
154154
return $this->iriConverter;
155155
}

src/Doctrine/Orm/Filter/SearchFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function __construct(ManagerRegistry $managerRegistry, IriConverterInterf
148148
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
149149
}
150150

151-
protected function getIriConverter(): IriConverterInterface
151+
protected function getIriConverter(): IriConverterInterface|LegacyIriConverterInterface
152152
{
153153
return $this->iriConverter;
154154
}

src/Hydra/Serializer/CollectionFiltersNormalizer.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
namespace ApiPlatform\Hydra\Serializer;
1515

16+
use ApiPlatform\Api\FilterInterface as LegacyFilterInterface;
1617
use ApiPlatform\Api\FilterLocatorTrait;
18+
use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface;
1719
use ApiPlatform\Doctrine\Odm\State\Options as ODMOptions;
1820
use ApiPlatform\Doctrine\Orm\State\Options;
1921
use ApiPlatform\Metadata\FilterInterface;
@@ -40,7 +42,7 @@ final class CollectionFiltersNormalizer implements NormalizerInterface, Normaliz
4042
/**
4143
* @param ContainerInterface $filterLocator The new filter locator or the deprecated filter collection
4244
*/
43-
public function __construct(private readonly NormalizerInterface $collectionNormalizer, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly ResourceClassResolverInterface $resourceClassResolver, ContainerInterface $filterLocator)
45+
public function __construct(private readonly NormalizerInterface $collectionNormalizer, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly LegacyResourceClassResolverInterface|ResourceClassResolverInterface $resourceClassResolver, ContainerInterface $filterLocator)
4446
{
4547
$this->setFilterLocator($filterLocator);
4648
}
@@ -142,7 +144,7 @@ public function setNormalizer(NormalizerInterface $normalizer): void
142144
/**
143145
* Returns the content of the Hydra search property.
144146
*
145-
* @param FilterInterface[] $filters
147+
* @param LegacyFilterInterface[]|FilterInterface[] $filters
146148
*/
147149
private function getSearch(string $resourceClass, array $parts, array $filters): array
148150
{

0 commit comments

Comments
 (0)