Skip to content

Commit 91d0ca4

Browse files
committed
chore: move internal dependencies
1 parent 98c88d1 commit 91d0ca4

35 files changed

+296
-95
lines changed

src/Action/ExceptionAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use ApiPlatform\Metadata\HttpOperation;
1818
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
1919
use ApiPlatform\Util\ErrorFormatGuesser;
20-
use ApiPlatform\Util\OperationRequestInitiatorTrait;
21-
use ApiPlatform\Util\RequestAttributesExtractor;
20+
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
21+
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
2222
use Symfony\Component\ErrorHandler\Exception\FlattenException;
2323
use Symfony\Component\HttpFoundation\Request;
2424
use Symfony\Component\HttpFoundation\Response;

src/HttpCache/EventListener/AddHeadersListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
namespace ApiPlatform\HttpCache\EventListener;
1515

1616
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
17-
use ApiPlatform\Util\OperationRequestInitiatorTrait;
18-
use ApiPlatform\Util\RequestAttributesExtractor;
17+
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
18+
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
1919
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2020

2121
/**

src/HttpCache/EventListener/AddTagsListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
2020
use ApiPlatform\Metadata\UrlGeneratorInterface;
2121
use ApiPlatform\State\UriVariablesResolverTrait;
22-
use ApiPlatform\Util\OperationRequestInitiatorTrait;
23-
use ApiPlatform\Util\RequestAttributesExtractor;
22+
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
23+
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
2424
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2525

2626
/**

src/Hydra/State/HydraLinkProcessor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
use ApiPlatform\Metadata\Operation;
1919
use ApiPlatform\Metadata\UrlGeneratorInterface;
2020
use ApiPlatform\State\ProcessorInterface;
21+
use ApiPlatform\State\Util\CorsTrait;
2122
use Symfony\Component\WebLink\GenericLinkProvider;
2223
use Symfony\Component\WebLink\Link;
2324

2425
final class HydraLinkProcessor implements ProcessorInterface
2526
{
27+
use CorsTrait;
28+
2629
/**
2730
* @param ProcessorInterface<mixed> $decorated
2831
*/
@@ -32,7 +35,7 @@ public function __construct(private readonly ProcessorInterface $decorated, priv
3235

3336
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
3437
{
35-
if (!($request = $context['request'] ?? null) || !$operation instanceof HttpOperation) {
38+
if (!($request = $context['request'] ?? null) || !$operation instanceof HttpOperation || $this->isPreflightRequest($request)) {
3639
return $this->decorated->process($data, $operation, $uriVariables, $context);
3740
}
3841

src/Serializer/phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</php>
1414

1515
<testsuites>
16-
<testsuite name="Api Platform GraphQL Component Test Suite">
16+
<testsuite name="Api Platform Serializer Component Test Suite">
1717
<directory>./Tests/</directory>
1818
</testsuite>
1919
</testsuites>

src/State/CallableProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
namespace ApiPlatform\State;
1515

16-
use ApiPlatform\Exception\RuntimeException;
16+
use ApiPlatform\Metadata\Exception\RuntimeException;
1717
use ApiPlatform\Metadata\Operation;
1818
use Psr\Container\ContainerInterface;
1919

2020
final class CallableProcessor implements ProcessorInterface
2121
{
22-
public function __construct(private readonly ContainerInterface $locator)
22+
public function __construct(private readonly ?ContainerInterface $locator = null)
2323
{
2424
}
2525

src/State/CallableProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
final class CallableProvider implements ProviderInterface
2121
{
22-
public function __construct(private readonly ContainerInterface $locator)
22+
public function __construct(private readonly ?ContainerInterface $locator = null)
2323
{
2424
}
2525

@@ -32,7 +32,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
3232
return $provider($operation, $uriVariables, $context);
3333
}
3434

35-
if (\is_string($provider)) {
35+
if ($this->locator && \is_string($provider)) {
3636
if (!$this->locator->has($provider)) {
3737
throw new ProviderNotFoundException(sprintf('Provider "%s" not found on operation "%s"', $provider, $operation->getName()));
3838
}

src/State/Processor/RespondProcessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
namespace ApiPlatform\State\Processor;
1515

16-
use ApiPlatform\Api\IriConverterInterface;
17-
use ApiPlatform\Api\UrlGeneratorInterface;
16+
use ApiPlatform\Metadata\IriConverterInterface;
17+
use ApiPlatform\Metadata\UrlGeneratorInterface;
1818
use ApiPlatform\Metadata\HttpOperation;
1919
use ApiPlatform\Metadata\Operation;
2020
use ApiPlatform\Metadata\Put;
2121
use ApiPlatform\Metadata\ResourceClassResolverInterface;
2222
use ApiPlatform\Metadata\Util\ClassInfoTrait;
2323
use ApiPlatform\State\ProcessorInterface;
24-
use ApiPlatform\Util\CloneTrait;
24+
use ApiPlatform\Metadata\Util\CloneTrait;
2525
use Symfony\Component\HttpFoundation\Response;
2626

2727
/**

src/State/Provider/ReadProvider.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
use ApiPlatform\State\Exception\ProviderNotFoundException;
2121
use ApiPlatform\State\ProviderInterface;
2222
use ApiPlatform\State\UriVariablesResolverTrait;
23-
use ApiPlatform\Util\CloneTrait;
24-
use ApiPlatform\Util\OperationRequestInitiatorTrait;
25-
use ApiPlatform\Util\RequestParser;
23+
use ApiPlatform\Metadata\Util\CloneTrait;
24+
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
25+
use ApiPlatform\State\Util\RequestParser;
2626
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2727

2828
/**
@@ -79,8 +79,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
7979
if (
8080
null === $data
8181
&& 'POST' !== $operation->getMethod()
82-
&& (
83-
'PUT' !== $operation->getMethod()
82+
&& ('PUT' !== $operation->getMethod()
8483
|| ($operation instanceof Put && !($operation->getAllowCreate() ?? false))
8584
)
8685
) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace ApiPlatform\State\Tests;
4+
5+
use ApiPlatform\Metadata\Exception\RuntimeException;
6+
use ApiPlatform\Metadata\Get;
7+
use ApiPlatform\State\CallableProcessor;
8+
use ApiPlatform\State\ProcessorInterface;
9+
use PHPUnit\Framework\TestCase;
10+
use Psr\Container\ContainerInterface;
11+
12+
class CallableProcessorTest extends TestCase
13+
{
14+
public function testNoProcessor(): void
15+
{
16+
$operation = new Get(name: 'hello');
17+
$data = new \stdClass();
18+
$this->assertEquals($data, (new CallableProcessor())->process($data, $operation));
19+
}
20+
21+
public function testCallable(): void
22+
{
23+
$operation = new Get(name: 'hello', processor: fn () => ['ok']);
24+
$this->assertEquals((new CallableProcessor())->process(new \stdClass(), $operation), ['ok']);
25+
}
26+
27+
public function testCallableServiceLocator(): void
28+
{
29+
$operation = new Get(name: 'hello', processor: 'processor');
30+
$provider = $this->createMock(ProcessorInterface::class);
31+
$provider->method('process')->willReturn(['ok']);
32+
$container = $this->createMock(ContainerInterface::class);
33+
$container->method('has')->with('processor')->willReturn(true);
34+
$container->method('get')->with('processor')->willReturn($provider);
35+
$this->assertEquals((new CallableProcessor($container))->process(new \stdClass(), $operation), ['ok']);
36+
}
37+
38+
public function testCallableServiceLocatorDoesNotExist(): void
39+
{
40+
$this->expectException(RuntimeException::class);
41+
$this->expectExceptionMessage('Processor "processor" not found on operation "hello"');
42+
$operation = new Get(name: 'hello', processor: 'processor');
43+
$container = $this->createMock(ContainerInterface::class);
44+
$container->method('has')->with('processor')->willReturn(false);
45+
(new CallableProcessor($container))->process(new \stdClass(), $operation);
46+
}
47+
}

0 commit comments

Comments
 (0)