Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/adr/0006-filtering-system-and-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ During the `Provider` phase (`RequestEvent::REQUEST`), we could use a `Parameter
interface ParameterProviderInterface
{
/**
* @param array<string, mixed> $parameters
* @param array<string, mixed>|array{request?: Request, resource_class?: string, operation: HttpOperation} $context
* @param array<string, mixed> $parameters
* @param array<string, mixed> $context
*/
public function provide(Parameter $parameter, array $parameters = [], array $context = []): ?HttpOperation;
}
Expand Down
6 changes: 5 additions & 1 deletion src/GraphQl/Type/ContextAwareTypeBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ interface ContextAwareTypeBuilderInterface
/**
* Gets the object type of the given resource.
*
* @param array<string, mixed>&array{input?: bool, wrapped?: bool, depth?: int} $context
* @param array<string, mixed> $context
*
* @phpstan-param array<string, mixed> $context
*
* @psalm-param array{input?: bool, wrapped?: bool, depth?: int, ...<string, mixed>} $context
*
* @return GraphQLType the object type, possibly wrapped by NonNull
*/
Expand Down
6 changes: 5 additions & 1 deletion src/Laravel/Eloquent/Metadata/ModelMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ private function getCastsWithDates(Model $model): Collection
/**
* Gets the default value for the given column.
*
* @param array<string, mixed>&array{name: string, default: string} $column
* @param array<string, mixed> $column
*
* @phpstan-param array<string, mixed> $column
*
* @psalm-param array{name: string, default: string, ...<string, mixed>} $column
*/
private function getColumnDefault(array $column, Model $model): mixed
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
public function createFromRequest(Request $request, bool $normalization, ?array $extractedAttributes = null): array
{
$context = $this->decorated->createFromRequest($request, $normalization, $extractedAttributes);
if (!isset($context['resource_class']) || !is_a($context['resource_class'], Model::class, true)) {
if (!isset($context['resource_class']) || !\is_string($context['resource_class']) || !is_a($context['resource_class'], Model::class, true)) {
return $context;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Laravel/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public function getRouteCollection(): RouteCollection
/**
* {@inheritdoc}
*
* @return array<string, mixed>|array{_api_resource_class?: class-string|string, _api_operation_name?: string, uri_variables?: array<string, mixed>}
* @return array<string, mixed>
*
* @phpstan-return array<string, mixed>
*
* @psalm-return array{_api_resource_class?: class-string|string, _api_operation_name?: string, uri_variables?: array<string, mixed>, ...<string, mixed>}
*/
public function match(string $pathInfo): array
{
Expand Down
15 changes: 12 additions & 3 deletions src/Metadata/IriConverterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ApiPlatform\Metadata\Exception\ItemNotFoundException;
use ApiPlatform\Metadata\Exception\OperationNotFoundException;
use ApiPlatform\Metadata\Exception\RuntimeException;
use Symfony\Component\HttpFoundation\Request;

/**
* Converts item and resources to IRI and vice versa.
Expand All @@ -28,7 +29,11 @@ interface IriConverterInterface
/**
* Retrieves an item from its IRI.
*
* @param array<string, mixed>|array{request?: Request, resource_class?: string|class-string} $context
* @param array<string, mixed> $context
*
* @phpstan-param array<string, mixed> $context
*
* @psalm-param array{request?: Request, resource_class?: string|class-string, ...<string, mixed>} $context
*
* @throws InvalidArgumentException
* @throws ItemNotFoundException
Expand All @@ -38,8 +43,12 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
/**
* Gets the IRI associated with the given item.
*
* @param object|class-string $resource
* @param array<string, mixed>|array{force_resource_class?: string|class-string, item_uri_template?: string, uri_variables?: array<string, string>} $context
* @param object|class-string $resource
* @param array<string, mixed> $context
*
* @phpstan-param array<string, mixed> $context
*
* @psalm-param array{force_resource_class?: string|class-string, item_uri_template?: string, uri_variables?: array<string, string>, ...<string, mixed>} $context
*
* @throws OperationNotFoundException
* @throws InvalidArgumentException
Expand Down
28 changes: 18 additions & 10 deletions src/Metadata/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
abstract class Parameter
{
/**
* @param (array<string, mixed>&array{type?: string, default?: mixed})|null $schema
* @param array<string, mixed> $extraProperties
* @param ParameterProviderInterface|callable|string|null $provider
* @param list<string> $properties a list of properties this parameter applies to (works with the :property placeholder)
* @param FilterInterface|string|null $filter
* @param mixed $constraints an array of Symfony constraints, or an array of Laravel rules
* @param Type $nativeType the PHP native type, we cast values to an array if its a CollectionType, if not and it's an array with a single value we use it (eg: HTTP Header)
* @param ?bool $castToNativeType whether API Platform should cast your parameter to the nativeType declared
* @param ?callable(mixed): mixed $castFn the closure used to cast your parameter, this gets called only when $castToNativeType is set
* @param array<string, mixed>|null $schema
* @param array<string, mixed> $extraProperties
* @param ParameterProviderInterface|callable|string|null $provider
* @param list<string> $properties a list of properties this parameter applies to (works with the :property placeholder)
* @param FilterInterface|string|null $filter
* @param mixed $constraints an array of Symfony constraints, or an array of Laravel rules
* @param Type $nativeType the PHP native type, we cast values to an array if its a CollectionType, if not and it's an array with a single value we use it (eg: HTTP Header)
* @param ?bool $castToNativeType whether API Platform should cast your parameter to the nativeType declared
* @param ?callable(mixed): mixed $castFn the closure used to cast your parameter, this gets called only when $castToNativeType is set
*
* @phpstan-param array<string, mixed>|null $schema
*
* @psalm-param array{type?: string, default?: mixed, ...<string, mixed>}|null $schema
*/
public function __construct(
protected ?string $key = null,
Expand Down Expand Up @@ -61,7 +65,11 @@ public function getKey(): ?string
}

/**
* @return (array<string, mixed>&array{type?: string, default?: mixed})|null $schema
* @return array<string, mixed>|null
*
* @phpstan-return array<string, mixed>|null
*
* @psalm-return array{type?: string, default?: string, ...<string, mixed>}|null
*/
public function getSchema(): ?array
{
Expand Down
6 changes: 5 additions & 1 deletion src/Serializer/TagCollectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ interface TagCollectorInterface
/**
* Collect cache tags for cache invalidation.
*
* @param array<string, mixed>&array{iri?: string, data?: mixed, object?: mixed, property_metadata?: \ApiPlatform\Metadata\ApiProperty, api_attribute?: string, resources?: array<string, string>, format?: string, operation?: \ApiPlatform\Metadata\Operation} $context
* @param array<string, mixed> $context
*
* @phpstan-param array<string, mixed> $context
*
* @psalm-param array{iri?: string, data?: mixed, object?: mixed, property_metadata?: \ApiPlatform\Metadata\ApiProperty, api_attribute?: string, resources?: array<string, string>, format?: string, operation?: \ApiPlatform\Metadata\Operation, ...<string, mixed>} $context
*/
public function collect(array $context = []): void;
}
9 changes: 7 additions & 2 deletions src/State/ParameterProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@

use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Parameter;
use Symfony\Component\HttpFoundation\Request;

/**
* Optionnaly transforms request parameters and provides modification to the current Operation.
*/
interface ParameterProviderInterface
{
/**
* @param array<string, mixed> $parameters
* @param array<string, mixed>|array{request?: Request, resource_class?: string, operation: Operation} $context
* @param array<string, mixed> $parameters
* @param array<string, mixed> $context
*
* @phpstan-param array<string, mixed> $context
*
* @psalm-param array{request?: Request, resource_class?: string, operation: Operation, ...<string, mixed>} $context
*/
public function provide(Parameter $parameter, array $parameters = [], array $context = []): ?Operation;
}
10 changes: 7 additions & 3 deletions src/State/ProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ interface ProcessorInterface
/**
* Handles the state.
*
* @param T1 $data
* @param array<string, mixed> $uriVariables
* @param array<string, mixed>&array{request?: Request, previous_data?: mixed, resource_class?: string|null, original_data?: mixed} $context
* @param T1 $data
* @param array<string, mixed> $uriVariables
* @param array<string, mixed> $context
*
* @phpstan-param array<string, mixed> $context
*
* @psalm-param array{request?: Request, previous_data?: mixed, resource_class?: string|null, original_data?: mixed, ...<string, mixed>} $context
*
* @return T2
*/
Expand Down
8 changes: 6 additions & 2 deletions src/State/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ interface ProviderInterface
/**
* Provides data.
*
* @param array<string, mixed> $uriVariables
* @param array<string, mixed>|array{request?: Request, resource_class?: string} $context
* @param array<string, mixed> $uriVariables
* @param array<string, mixed> $context
*
* @phpstan-param array<string, mixed> $context
*
* @psalm-param array{request?: Request, resource_class?: string, ...<string, mixed>} $context
*
* @return T|PartialPaginatorInterface<T>|iterable<T>|null
*/
Expand Down
7 changes: 6 additions & 1 deletion src/State/SerializerContextBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ interface SerializerContextBuilderInterface
*
* @throws RuntimeException
*
* @return array<string, mixed>&array{
* @return array<string, mixed>
*
* @phpstan-return array<string, mixed>
*
* @psalm-return array{
* groups?: string[]|string,
* operation_name?: string,
* operation?: HttpOperation,
Expand All @@ -55,6 +59,7 @@ interface SerializerContextBuilderInterface
* attributes?: string[],
* deserializer_type?: string,
* api_assign_object_to_populate?: bool,
* ...<string, mixed>
* }
*/
public function createFromRequest(Request $request, bool $normalization, ?array $extractedAttributes = null): array;
Expand Down
Loading