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 src/Action/ExceptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
use ApiPlatform\Util\ErrorFormatGuesser;
use ApiPlatform\Util\OperationRequestInitiatorTrait;
use ApiPlatform\Util\RequestAttributesExtractor;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down
2 changes: 1 addition & 1 deletion src/Api/QueryParameterValidator/Validator/Required.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace ApiPlatform\Api\QueryParameterValidator\Validator;

use ApiPlatform\Util\RequestParser;
use ApiPlatform\State\Util\RequestParser;

final class Required implements ValidatorInterface
{
Expand Down
5 changes: 3 additions & 2 deletions src/Elasticsearch/composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "api-platform/elasticseach",
"description": "Elasticsearch support",
"description": "API Platform Elasticsearch bridge",
"type": "library",
"keywords": [
"Filter",
"Elasticsearch"
"Elasticsearch",
"search"
],
"homepage": "https://api-platform.com",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/HttpCache/EventListener/AddHeadersListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace ApiPlatform\HttpCache\EventListener;

use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Util\OperationRequestInitiatorTrait;
use ApiPlatform\Util\RequestAttributesExtractor;
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
use Symfony\Component\HttpKernel\Event\ResponseEvent;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/HttpCache/EventListener/AddTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use ApiPlatform\State\UriVariablesResolverTrait;
use ApiPlatform\Util\OperationRequestInitiatorTrait;
use ApiPlatform\Util\RequestAttributesExtractor;
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
use Symfony\Component\HttpKernel\Event\ResponseEvent;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/HttpCache/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-platform/http-cache",
"description": "HttpCache support",
"description": "API Platform HttpCache component",
"type": "library",
"keywords": [
"Cache",
Expand Down
2 changes: 1 addition & 1 deletion src/Hydra/EventListener/AddLinkHeaderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use ApiPlatform\Api\UrlGeneratorInterface;
use ApiPlatform\JsonLd\ContextBuilder;
use ApiPlatform\Util\CorsTrait;
use ApiPlatform\State\Util\CorsTrait;
use Psr\Link\EvolvableLinkProviderInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\WebLink\GenericLinkProvider;
Expand Down
5 changes: 4 additions & 1 deletion src/Hydra/State/HydraLinkProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\State\Util\CorsTrait;
use Symfony\Component\WebLink\GenericLinkProvider;
use Symfony\Component\WebLink\Link;

final class HydraLinkProcessor implements ProcessorInterface
{
use CorsTrait;

/**
* @param ProcessorInterface<mixed> $decorated
*/
Expand All @@ -32,7 +35,7 @@ public function __construct(private readonly ProcessorInterface $decorated, priv

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

Expand Down
4 changes: 2 additions & 2 deletions src/RamseyUuid/composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "api-platform/ramsey-uuid",
"description": "API Platform RamseyUuid support",
"description": "API Platform RamseyUuid bridge",
"type": "library",
"keywords": [
"UUid",
"UUID",
"API"
],
"homepage": "https://api-platform.com",
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-platform/serializer",
"description": "Build GraphQL API endpoints",
"description": "API Platform core Serializer",
"type": "library",
"keywords": [
"Serializer",
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</php>

<testsuites>
<testsuite name="Api Platform GraphQL Component Test Suite">
<testsuite name="Api Platform Serializer Component Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
Expand Down
4 changes: 2 additions & 2 deletions src/State/CallableProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

namespace ApiPlatform\State;

use ApiPlatform\Exception\RuntimeException;
use ApiPlatform\Metadata\Exception\RuntimeException;
use ApiPlatform\Metadata\Operation;
use Psr\Container\ContainerInterface;

final class CallableProcessor implements ProcessorInterface
{
public function __construct(private readonly ContainerInterface $locator)
public function __construct(private readonly ?ContainerInterface $locator = null)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/State/CallableProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

final class CallableProvider implements ProviderInterface
{
public function __construct(private readonly ContainerInterface $locator)
public function __construct(private readonly ?ContainerInterface $locator = null)
{
}

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

if (\is_string($provider)) {
if ($this->locator && \is_string($provider)) {
if (!$this->locator->has($provider)) {
throw new ProviderNotFoundException(sprintf('Provider "%s" not found on operation "%s"', $provider, $operation->getName()));
}
Expand Down
6 changes: 3 additions & 3 deletions src/State/Processor/RespondProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

namespace ApiPlatform\State\Processor;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Api\UrlGeneratorInterface;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use ApiPlatform\Metadata\Util\ClassInfoTrait;
use ApiPlatform\Metadata\Util\CloneTrait;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\Util\CloneTrait;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down
9 changes: 4 additions & 5 deletions src/State/Provider/ReadProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Util\CloneTrait;
use ApiPlatform\Serializer\SerializerContextBuilderInterface;
use ApiPlatform\State\Exception\ProviderNotFoundException;
use ApiPlatform\State\ProviderInterface;
use ApiPlatform\State\UriVariablesResolverTrait;
use ApiPlatform\Util\CloneTrait;
use ApiPlatform\Util\OperationRequestInitiatorTrait;
use ApiPlatform\Util\RequestParser;
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
use ApiPlatform\State\Util\RequestParser;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
Expand Down Expand Up @@ -79,8 +79,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if (
null === $data
&& 'POST' !== $operation->getMethod()
&& (
'PUT' !== $operation->getMethod()
&& ('PUT' !== $operation->getMethod()
|| ($operation instanceof Put && !($operation->getAllowCreate() ?? false))
)
) {
Expand Down
58 changes: 58 additions & 0 deletions src/State/Tests/CallableProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\State\Tests;

use ApiPlatform\Metadata\Exception\RuntimeException;
use ApiPlatform\Metadata\Get;
use ApiPlatform\State\CallableProcessor;
use ApiPlatform\State\ProcessorInterface;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

class CallableProcessorTest extends TestCase
{
public function testNoProcessor(): void
{
$operation = new Get(name: 'hello');
$data = new \stdClass();
$this->assertEquals($data, (new CallableProcessor())->process($data, $operation));
}

public function testCallable(): void
{
$operation = new Get(name: 'hello', processor: fn () => ['ok']);
$this->assertEquals((new CallableProcessor())->process(new \stdClass(), $operation), ['ok']);
}

public function testCallableServiceLocator(): void
{
$operation = new Get(name: 'hello', processor: 'processor');
$provider = $this->createMock(ProcessorInterface::class);
$provider->method('process')->willReturn(['ok']);
$container = $this->createMock(ContainerInterface::class);
$container->method('has')->with('processor')->willReturn(true);
$container->method('get')->with('processor')->willReturn($provider);
$this->assertEquals((new CallableProcessor($container))->process(new \stdClass(), $operation), ['ok']);
}

public function testCallableServiceLocatorDoesNotExist(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Processor "processor" not found on operation "hello"');
$operation = new Get(name: 'hello', processor: 'processor');
$container = $this->createMock(ContainerInterface::class);
$container->method('has')->with('processor')->willReturn(false);
(new CallableProcessor($container))->process(new \stdClass(), $operation);
}
}
49 changes: 49 additions & 0 deletions src/State/Tests/CallableProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\State\Tests;

use ApiPlatform\Metadata\Get;
use ApiPlatform\State\CallableProvider;
use ApiPlatform\State\Exception\ProviderNotFoundException;
use ApiPlatform\State\ProviderInterface;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

class CallableProviderTest extends TestCase
{
public function testNoProvider(): void
{
$operation = new Get(name: 'hello');
$this->expectException(ProviderNotFoundException::class);
$this->expectExceptionMessage('Provider not found on operation "hello"');
(new CallableProvider())->provide($operation);
}

public function testCallable(): void
{
$operation = new Get(name: 'hello', provider: fn () => ['ok']);
$this->assertEquals((new CallableProvider())->provide($operation), ['ok']);
}

public function testCallableServiceLocator(): void
{
$operation = new Get(name: 'hello', provider: 'provider');
$provider = $this->createMock(ProviderInterface::class);
$provider->method('provide')->willReturn(['ok']);
$container = $this->createMock(ContainerInterface::class);
$container->method('has')->with('provider')->willReturn(true);
$container->method('get')->with('provider')->willReturn($provider);
$this->assertEquals((new CallableProvider($container))->provide($operation), ['ok']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

declare(strict_types=1);

namespace ApiPlatform\Tests\Util;
namespace ApiPlatform\State\Tests\Util;

use ApiPlatform\Util\RequestParser;
use ApiPlatform\State\Util\RequestParser;
use PHPUnit\Framework\TestCase;

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Util/CorsTrait.php → src/State/Util/CorsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@

declare(strict_types=1);

namespace ApiPlatform\Util;
namespace ApiPlatform\State\Util;

use Symfony\Component\HttpFoundation\Request;

/**
* CORS utils.
*
* To be removed when https://github.com/symfony/symfony/pull/34391 wil be merged.
*
* @internal
*
* @author Kévin Dunglas <dunglas@gmail.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace ApiPlatform\Util;
namespace ApiPlatform\State\Util;

use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace ApiPlatform\Util;
namespace ApiPlatform\State\Util;

use Symfony\Component\HttpFoundation\Request;

Expand Down
Loading