Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/Hydra/State/JsonStreamerProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use ApiPlatform\State\Pagination\PartialPaginatorInterface;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\State\Util\HttpResponseHeadersTrait;
use Psr\Container\ContainerInterface;
use ApiPlatform\State\Util\HttpResponseStatusTrait;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
Expand Down Expand Up @@ -59,11 +60,13 @@ public function __construct(
private readonly string $enabledParameterName = 'pagination',
private readonly int $urlGenerationStrategy = UrlGeneratorInterface::ABS_PATH,
?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null,
?ContainerInterface $responseHeaderProviderLocator = null,
) {
$this->resourceClassResolver = $resourceClassResolver;
$this->iriConverter = $iriConverter;
$this->operationMetadataFactory = $operationMetadataFactory;
$this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
$this->responseHeaderProviderLocator = $responseHeaderProviderLocator;
}

public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
Expand Down
2 changes: 2 additions & 0 deletions src/Laravel/ApiPlatformDeferredProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
use ApiPlatform\State\ErrorProvider;
use ApiPlatform\State\Pagination\Pagination;
use ApiPlatform\State\ParameterProviderInterface;
use ApiPlatform\State\ResponseHeaderProviderInterface;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\State\Provider\ParameterProvider;
use ApiPlatform\State\Provider\SecurityParameterProvider;
Expand Down Expand Up @@ -160,6 +161,7 @@ public function register(): void
});

$this->autoconfigure($classes, ParameterProviderInterface::class, [SerializerFilterParameterProvider::class, SortFilterParameterProvider::class, SparseFieldsetParameterProvider::class]);
$this->autoconfigure($classes, ResponseHeaderProviderInterface::class, []);

$this->app->bind(FilterQueryExtension::class, static function (Application $app) {
$tagged = iterator_to_array($app->tagged(EloquentFilterInterface::class));
Expand Down
9 changes: 8 additions & 1 deletion src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
use ApiPlatform\State\Processor\WriteProcessor;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\State\Provider\ContentNegotiationProvider;
use ApiPlatform\State\ResponseHeaderProviderInterface;
use ApiPlatform\State\Provider\DeserializeProvider;
use ApiPlatform\State\Provider\ObjectMapperProvider;
use ApiPlatform\State\Provider\ParameterProvider;
Expand Down Expand Up @@ -473,11 +474,17 @@ public function register(): void
}

$this->app->singleton(RespondProcessor::class, static function (Application $app) {
$responseHeaderProviders = [];
foreach ($app->tagged(ResponseHeaderProviderInterface::class) as $provider) {
$responseHeaderProviders[$provider::class] = $provider;
}

$decorated = new RespondProcessor(
$app->make(IriConverterInterface::class),
$app->make(ResourceClassResolverInterface::class),
$app->make(OperationMetadataFactoryInterface::class),
$app->make(ResourceMetadataCollectionFactoryInterface::class)
$app->make(ResourceMetadataCollectionFactoryInterface::class),
new ServiceLocator($responseHeaderProviders),
);

if (class_exists(AddHeadersProcessor::class)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
?string $condition = null,
?string $controller = null,
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,
?array $hydraContext = null,
Expand Down Expand Up @@ -126,6 +127,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
?string $condition = null,
?string $controller = null,
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,
?array $hydraContext = null,
Expand Down Expand Up @@ -120,6 +121,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
?string $condition = null,
?string $controller = null,
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,
?array $hydraContext = null,
Expand Down Expand Up @@ -125,6 +126,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/GetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
?string $condition = null,
?string $controller = null,
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,
?array $hydraContext = null,
Expand Down Expand Up @@ -126,6 +127,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
23 changes: 22 additions & 1 deletion src/Metadata/HttpOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class HttpOperation extends Operation
* no_transform?: bool,
* immutable?: bool,
* }|null $cacheHeaders {@see https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers}
* @param array<string, string>|null $headers
* @param array<string, string>|null $headers
* @param array<string, ResponseHeader>|null $responseHeaders
* @param list<array{
* field: string,
* direction: string,
Expand Down Expand Up @@ -161,6 +162,7 @@ public function __construct(
protected ?string $condition = null,
protected ?string $controller = null,
protected ?array $headers = null,
protected ?array $responseHeaders = null,
protected ?array $cacheHeaders = null,
protected ?array $paginationViaCursor = null,
protected ?array $hydraContext = null,
Expand Down Expand Up @@ -582,6 +584,25 @@ public function getHeaders(): ?array
return $this->headers;
}

/**
* @return array<string, ResponseHeader>|null
*/
public function getResponseHeaders(): ?array
{
return $this->responseHeaders;
}

/**
* @param array<string, ResponseHeader> $responseHeaders
*/
public function withResponseHeaders(array $responseHeaders): static
{
$self = clone $this;
$self->responseHeaders = $responseHeaders;

return $self;
}

public function withHeaders(array $headers): static
{
$self = clone $this;
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/McpResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public function __construct(
?string $condition = null,
?string $controller = null,
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,
?array $hydraContext = null,
Expand Down Expand Up @@ -206,6 +207,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/McpTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function __construct(
?string $condition = null,
?string $controller = null,
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,
?array $hydraContext = null,
Expand Down Expand Up @@ -200,6 +201,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/NotExposed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function __construct(
?string $condition = null,
?string $controller = 'api_platform.action.not_exposed',
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,

Expand Down Expand Up @@ -132,6 +133,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
?string $condition = null,
?string $controller = null,
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,
?array $hydraContext = null,
Expand Down Expand Up @@ -126,6 +127,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
?string $condition = null,
?string $controller = null,
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,
?array $hydraContext = null,
Expand Down Expand Up @@ -127,6 +128,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
?string $condition = null,
?string $controller = null,
?array $headers = null,
?array $responseHeaders = null,
?array $cacheHeaders = null,
?array $paginationViaCursor = null,
?array $hydraContext = null,
Expand Down Expand Up @@ -127,6 +128,7 @@ public function __construct(
condition: $condition,
controller: $controller,
headers: $headers,
responseHeaders: $responseHeaders,
cacheHeaders: $cacheHeaders,
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
Expand Down
Loading
Loading