Skip to content

Commit

Permalink
fix handler decoration bc internal
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Jun 18, 2024
1 parent 38fafc4 commit f3a3a3d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 37 deletions.
7 changes: 1 addition & 6 deletions src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,16 +562,11 @@ public function register(): void
);
});

$this->app->singleton(
\Illuminate\Foundation\Exceptions\Handler::class,
\Illuminate\Foundation\Exceptions\Handler::class
);

$this->app->singleton(
ExceptionHandlerInterface::class,
function (Application $app) {
return new Handler(
$app->make(\Illuminate\Foundation\Exceptions\Handler::class),
$app,
$app->make(ResourceMetadataCollectionFactoryInterface::class),
$app->make(ApiPlatformController::class),
$app->make(IdentifiersExtractorInterface::class),
Expand Down
36 changes: 7 additions & 29 deletions src/Laravel/Exception/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
use ApiPlatform\Symfony\Validator\Exception\ConstraintViolationListAwareExceptionInterface;
use ApiPlatform\Validator\Exception\ValidationException;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Container\Container;
use Illuminate\Foundation\Exceptions\Handler as ExceptionsHandler;
use Illuminate\Http\Request;
use Negotiation\Negotiator;
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface as SymfonyHttpExceptionInterface;

class Handler implements ExceptionHandler
class Handler extends ExceptionsHandler
{
use ContentNegotiationTrait;
use OperationRequestInitiatorTrait;
private static mixed $error;

public function __construct(
private readonly ExceptionHandler $decorated,
Container $container,
ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
private readonly ApiPlatformController $apiPlatformController,
private readonly ?IdentifiersExtractorInterface $identifiersExtractor = null,
Expand All @@ -48,15 +47,14 @@ public function __construct(
) {
$this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
$this->negotiator = $negotiator;
// calls register
parent::__construct($container);
$this->register();
}

public function register(): void
{
if (!$this->decorated instanceof ExceptionsHandler) {
return;
}

$this->decorated->renderable(function (\Throwable $exception, Request $request) {
$this->renderable(function (\Throwable $exception, Request $request) {
$apiOperation = $this->initializeOperation($request);
if (!$apiOperation) {
return null;
Expand Down Expand Up @@ -204,24 +202,4 @@ public static function provide(): mixed

throw new \LogicException(sprintf('We could not find the thrown exception in the %s.', self::class));
}

public function report(\Throwable $e): void
{
$this->decorated->report($e);
}

public function shouldReport(\Throwable $e): bool
{
return $this->decorated->shouldReport($e);
}

public function render($request, \Throwable $e): Response
{
return $this->decorated->render($request, $e);
}

public function renderForConsole($output, \Throwable $e): void
{
$this->decorated->renderForConsole($output, $e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
namespace Workbench\App\Providers;

use Illuminate\Console\OutputStyle;
use Illuminate\Console\View\Components\Factory;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\ServiceProvider;
use Orchestra\Testbench\Foundation\Events\ServeCommandStarted;
use Orchestra\Testbench\Workbench\Workbench;
use Orchestra\Workbench\Listeners\AddAssetSymlinkFolders;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Illuminate\Console\View\Components\Factory;
use Illuminate\Filesystem\Filesystem;

class WorkbenchServiceProvider extends ServiceProvider
{
Expand Down

0 comments on commit f3a3a3d

Please sign in to comment.