-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRefreshInterceptor.php
More file actions
36 lines (29 loc) · 939 Bytes
/
RefreshInterceptor.php
File metadata and controls
36 lines (29 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
declare(strict_types=1);
namespace BEAR\QueryRepository;
use BEAR\QueryRepository\Exception\ReturnValueIsNotResourceObjectException;
use BEAR\Resource\Code;
use BEAR\Resource\ResourceObject;
use Override;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;
final readonly class RefreshInterceptor implements MethodInterceptor
{
public function __construct(
private RefreshAnnotatedCommand $command,
) {
}
#[Override]
public function invoke(MethodInvocation $invocation): ResourceObject
{
/** @psalm-suppress MixedAssignment */
$ro = $invocation->proceed();
if (! $ro instanceof ResourceObject) {
throw new ReturnValueIsNotResourceObjectException($invocation->getThis()::class); // @codeCoverageIgnore
}
if ($ro->code < Code::BAD_REQUEST) {
$this->command->command($invocation, $ro);
}
return $ro;
}
}