Skip to content

Commit a1448a3

Browse files
committed
docs(state): advertising Linked Data Platform headers (Allow & Accept-Post)
1 parent 5896ecc commit a1448a3

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/State/Processor/LinkedDataPlatformProcessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
6161
foreach ($resource->getOperations() as $op) {
6262
if ($op->getUriTemplate() === $operation->getUriTemplate()) {
6363
$allowedMethods[] = $method = $op->getMethod();
64-
if ('POST' === $method && $outputFormats = $op->getOutputFormats()) {
65-
$acceptPost = array_map('strval', $outputFormats);
64+
if ('POST' === $method && \is_array($outputFormats = $op->getOutputFormats())) {
65+
$acceptPost = implode(', ', array_merge(...array_values($outputFormats)));
6666
}
6767
}
6868
}
6969
}
7070
if ($acceptPost) {
71-
$response->headers->set('Accept-Post', implode(', ', array_values($acceptPost)));
71+
$response->headers->set('Accept-Post', $acceptPost);
7272
}
7373

7474
$response->headers->set('Allow', implode(', ', $allowedMethods));

src/State/Tests/Processor/LinkedDataPlatformProcessorTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ protected function setUp(): void
6767

6868
public function testHeadersAcceptPostIsReturnWhenPostAllowed(): void
6969
{
70-
// $operation = (new HttpOperation('GET', '/dummy{._format}', class: 'DummyResource'));
71-
$operation = new Get('/dummy{._format}');
70+
/** @var class-string $dummy */
71+
$dummy = "dummy";
72+
$operation = new Get('/dummy{._format}', class: $dummy);
7273

7374
$context = $this->getContext();
7475

@@ -101,7 +102,9 @@ public function testHeadersAcceptPostIsNotSetWhenPostIsNotAllowed(): void
101102

102103
public function testHeaderAllowReflectsResourceAllowedMethods(): void
103104
{
104-
$operation = new Get('/dummy{._format}', class: Dummy::class);
105+
/** @var class-string $dummy */
106+
$dummy = 'dummy';
107+
$operation = new Get('/dummy{._format}', class: $dummy);
105108
$context = $this->getContext();
106109

107110
$processor = new LinkedDataPlatformProcessor(
@@ -116,8 +119,9 @@ public function testHeaderAllowReflectsResourceAllowedMethods(): void
116119
$this->assertStringContainsString('HEAD', $allowHeader);
117120
$this->assertStringContainsString('GET', $allowHeader);
118121
$this->assertStringContainsString('POST', $allowHeader);
119-
120-
$operation = new Get('/dummy/{dummyResourceId}{._format}');
122+
/** @var class-string $dummy */
123+
$dummy = 'dummy';
124+
$operation = new Get('/dummy/{dummyResourceId}{._format}', class: $dummy);
121125

122126

123127
/** @var Response $response */

0 commit comments

Comments
 (0)