-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRefreshSameCommand.php
More file actions
53 lines (45 loc) · 1.34 KB
/
RefreshSameCommand.php
File metadata and controls
53 lines (45 loc) · 1.34 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace BEAR\QueryRepository;
use BEAR\Resource\ResourceObject;
use Ray\Aop\MethodInvocation;
use ReflectionException;
use function array_values;
use function call_user_func_array;
use function is_callable;
// phpcs:ignoreFile SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing -- for call_user_func_array
final readonly class RefreshSameCommand implements CommandInterface
{
public function __construct(
private QueryRepositoryInterface $repository,
private MatchQueryInterface $matchQuery
){
}
/**
* @return void
*/
#[\Override]
public function command(MethodInvocation $invocation, ResourceObject $ro)
{
unset($invocation);
$getQuery = $this->getQuery($ro);
$delUri = clone $ro->uri;
$delUri->query = $getQuery;
// delete data in repository
$this->repository->purge($delUri);
// GET for re-generate (in interceptor)
$ro->uri->query = $getQuery;
$get = [$ro, 'onGet'];
if (is_callable($get)) {
call_user_func_array($get, array_values($getQuery));
}
}
/**
* @return array<string, mixed>
*
* @throws ReflectionException
*/
private function getQuery(ResourceObject $ro): array
{
return $this->matchQuery->__invoke($ro);
}
}