Skip to content

Commit 41f26ad

Browse files
committed
Merge 4.1
2 parents 136b45d + e410342 commit 41f26ad

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

ApiPlatformDeferredProvider.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
use ApiPlatform\State\Provider\ParameterProvider;
8484
use ApiPlatform\State\Provider\SecurityParameterProvider;
8585
use ApiPlatform\State\ProviderInterface;
86-
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerInterface;
86+
use Illuminate\Contracts\Debug\ExceptionHandler;
8787
use Illuminate\Contracts\Foundation\Application;
8888
use Illuminate\Contracts\Support\DeferrableProvider;
8989
use Illuminate\Support\ServiceProvider;
@@ -252,9 +252,9 @@ public function register(): void
252252
);
253253
});
254254

255-
$this->app->singleton(
256-
ExceptionHandlerInterface::class,
257-
function (Application $app) {
255+
$this->app->extend(
256+
ExceptionHandler::class,
257+
function (ExceptionHandler $decorated, Application $app) {
258258
/** @var ConfigRepository */
259259
$config = $app['config'];
260260

@@ -267,7 +267,8 @@ function (Application $app) {
267267
$app->make(Negotiator::class),
268268
$config->get('api-platform.exception_to_status'),
269269
$config->get('app.debug'),
270-
$config->get('api-platform.error_formats')
270+
$config->get('api-platform.error_formats'),
271+
$decorated
271272
);
272273
}
273274
);

Exception/ErrorHandler.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Illuminate\Auth\Access\AuthorizationException;
2828
use Illuminate\Auth\AuthenticationException;
2929
use Illuminate\Contracts\Container\Container;
30+
use Illuminate\Contracts\Debug\ExceptionHandler;
3031
use Illuminate\Foundation\Exceptions\Handler as ExceptionsHandler;
3132
use Negotiation\Negotiator;
3233
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
@@ -54,6 +55,7 @@ public function __construct(
5455
private readonly ?array $exceptionToStatus = null,
5556
private readonly ?bool $debug = false,
5657
private readonly ?array $errorFormats = null,
58+
private readonly ?ExceptionHandler $decorated = null,
5759
) {
5860
$this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
5961
$this->negotiator = $negotiator;
@@ -65,7 +67,7 @@ public function render($request, \Throwable $exception)
6567
$apiOperation = $this->initializeOperation($request);
6668

6769
if (!$apiOperation) {
68-
return parent::render($request, $exception);
70+
return $this->decorated ? $this->decorated->render($request, $exception) : parent::render($request, $exception);
6971
}
7072

7173
$formats = $this->errorFormats ?? ['jsonproblem' => ['application/problem+json']];
@@ -157,9 +159,12 @@ public function render($request, \Throwable $exception)
157159
}
158160

159161
try {
160-
return $this->apiPlatformController->__invoke($dup);
162+
$response = $this->apiPlatformController->__invoke($dup);
163+
$this->decorated->render($dup, $exception);
164+
165+
return $response;
161166
} catch (\Throwable $e) {
162-
return parent::render($dup, $e);
167+
return $this->decorated ? $this->decorated->render($request, $exception) : parent::render($request, $exception);
163168
}
164169
}
165170

workbench/app/Models/Book.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
use Illuminate\Database\Eloquent\Factories\HasFactory;
3838
use Illuminate\Database\Eloquent\Model;
3939
use Illuminate\Database\Eloquent\Relations\BelongsTo;
40+
use Symfony\Component\TypeInfo\Type\BuiltinType;
41+
use Symfony\Component\TypeInfo\TypeIdentifier;
4042
use Workbench\App\Http\Requests\BookFormRequest;
4143

4244
#[ApiResource(
@@ -79,7 +81,7 @@
7981
property: 'name'
8082
)]
8183
#[QueryParameter(key: 'properties', filter: PropertyFilter::class)]
82-
#[QueryParameter(key: 'published', filter: BooleanFilter::class)]
84+
#[QueryParameter(key: 'published', filter: BooleanFilter::class, nativeType: new BuiltinType(TypeIdentifier::BOOL))]
8385
class Book extends Model
8486
{
8587
use HasFactory;

0 commit comments

Comments
 (0)