diff --git a/src/Laravel/ApiPlatformDeferredProvider.php b/src/Laravel/ApiPlatformDeferredProvider.php index 18e549f06f5..227e2f9c680 100644 --- a/src/Laravel/ApiPlatformDeferredProvider.php +++ b/src/Laravel/ApiPlatformDeferredProvider.php @@ -83,7 +83,7 @@ use ApiPlatform\State\Provider\ParameterProvider; use ApiPlatform\State\Provider\SecurityParameterProvider; use ApiPlatform\State\ProviderInterface; -use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerInterface; +use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Support\ServiceProvider; @@ -252,9 +252,9 @@ public function register(): void ); }); - $this->app->singleton( - ExceptionHandlerInterface::class, - function (Application $app) { + $this->app->extend( + ExceptionHandler::class, + function (ExceptionHandler $decorated, Application $app) { /** @var ConfigRepository */ $config = $app['config']; @@ -267,7 +267,8 @@ function (Application $app) { $app->make(Negotiator::class), $config->get('api-platform.exception_to_status'), $config->get('app.debug'), - $config->get('api-platform.error_formats') + $config->get('api-platform.error_formats'), + $decorated ); } ); diff --git a/src/Laravel/Eloquent/Paginator.php b/src/Laravel/Eloquent/Paginator.php index 93ee8379aec..4085cb18255 100644 --- a/src/Laravel/Eloquent/Paginator.php +++ b/src/Laravel/Eloquent/Paginator.php @@ -16,10 +16,9 @@ use ApiPlatform\State\Pagination\HasNextPagePaginatorInterface; use ApiPlatform\State\Pagination\PaginatorInterface; use Illuminate\Pagination\LengthAwarePaginator; -use IteratorAggregate; /** - * @implements IteratorAggregate + * @implements \IteratorAggregate * @implements PaginatorInterface */ final class Paginator implements PaginatorInterface, HasNextPagePaginatorInterface, \IteratorAggregate diff --git a/src/Laravel/Eloquent/PartialPaginator.php b/src/Laravel/Eloquent/PartialPaginator.php index 9560b2d859d..004cb228ab1 100644 --- a/src/Laravel/Eloquent/PartialPaginator.php +++ b/src/Laravel/Eloquent/PartialPaginator.php @@ -15,10 +15,9 @@ use ApiPlatform\State\Pagination\PartialPaginatorInterface; use Illuminate\Pagination\AbstractPaginator; -use IteratorAggregate; /** - * @implements IteratorAggregate + * @implements \IteratorAggregate * @implements PartialPaginatorInterface */ final class PartialPaginator implements PartialPaginatorInterface, \IteratorAggregate diff --git a/src/Laravel/Exception/ErrorHandler.php b/src/Laravel/Exception/ErrorHandler.php index f496c5d1eb5..8a207acea28 100644 --- a/src/Laravel/Exception/ErrorHandler.php +++ b/src/Laravel/Exception/ErrorHandler.php @@ -27,6 +27,7 @@ use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\AuthenticationException; use Illuminate\Contracts\Container\Container; +use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionsHandler; use Negotiation\Negotiator; use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface; @@ -54,6 +55,7 @@ public function __construct( private readonly ?array $exceptionToStatus = null, private readonly ?bool $debug = false, private readonly ?array $errorFormats = null, + private readonly ?ExceptionHandler $decorated = null, ) { $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory; $this->negotiator = $negotiator; @@ -65,7 +67,7 @@ public function render($request, \Throwable $exception) $apiOperation = $this->initializeOperation($request); if (!$apiOperation) { - return parent::render($request, $exception); + return $this->decorated ? $this->decorated->render($request, $exception) : parent::render($request, $exception); } $formats = $this->errorFormats ?? ['jsonproblem' => ['application/problem+json']]; @@ -157,9 +159,12 @@ public function render($request, \Throwable $exception) } try { - return $this->apiPlatformController->__invoke($dup); + $response = $this->apiPlatformController->__invoke($dup); + $this->decorated->render($dup, $exception); + + return $response; } catch (\Throwable $e) { - return parent::render($dup, $e); + return $this->decorated ? $this->decorated->render($request, $exception) : parent::render($request, $exception); } }