1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Spiral\Queue\Interceptor\Push; |
6
|
|
|
|
7
|
|
|
use Spiral\Core\ContainerScope; |
8
|
|
|
use Spiral\Core\CoreInterface; |
9
|
|
|
use Spiral\Interceptors\Context\CallContext; |
10
|
|
|
use Spiral\Interceptors\HandlerInterface; |
11
|
|
|
use Spiral\Queue\Options; |
12
|
|
|
use Spiral\Queue\OptionsInterface; |
13
|
|
|
use Spiral\Queue\QueueInterface; |
14
|
|
|
use Spiral\Telemetry\NullTracer; |
15
|
|
|
use Spiral\Telemetry\TracerInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @internal |
19
|
|
|
* @psalm-type TParameters = array{options: ?OptionsInterface, payload: mixed} |
20
|
|
|
*/ |
21
|
|
|
final class Core implements CoreInterface, HandlerInterface |
|
|
|
|
22
|
|
|
{ |
23
|
10 |
|
public function __construct( |
24
|
|
|
private readonly QueueInterface $connection, |
25
|
|
|
) { |
26
|
10 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param-assert TParameters $parameters |
30
|
|
|
* @deprecated |
31
|
|
|
*/ |
32
|
6 |
|
public function callAction( |
33
|
|
|
string $controller, |
34
|
|
|
string $action, |
35
|
|
|
array $parameters = ['options' => null, 'payload' => []], |
36
|
|
|
): string { |
37
|
6 |
|
if ($parameters['options'] === null) { |
38
|
4 |
|
$parameters['options'] = new Options(); |
39
|
|
|
} |
40
|
|
|
|
41
|
6 |
|
$tracer = $this->getTracer(); |
42
|
|
|
|
43
|
6 |
|
if (\method_exists($parameters['options'], 'withHeader')) { |
44
|
5 |
|
foreach ($tracer->getContext() as $key => $data) { |
45
|
1 |
|
$parameters['options'] = $parameters['options']->withHeader($key, $data); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
6 |
|
return $tracer->trace( |
50
|
6 |
|
name: \sprintf('Job push [%s]', $controller), |
51
|
6 |
|
callback: fn (): string => $this->connection->push( |
52
|
6 |
|
name: $controller, |
53
|
6 |
|
payload: $parameters['payload'], |
54
|
6 |
|
options: $parameters['options'], |
55
|
6 |
|
), |
56
|
6 |
|
attributes: [ |
57
|
6 |
|
'queue.handler' => $controller, |
58
|
6 |
|
], |
59
|
6 |
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
2 |
|
public function handle(CallContext $context): mixed |
63
|
|
|
{ |
64
|
2 |
|
$args = $context->getArguments(); |
65
|
2 |
|
$controller = $context->getTarget()->getPath()[0]; |
66
|
2 |
|
$action = $context->getTarget()->getPath()[1]; |
67
|
|
|
|
68
|
2 |
|
return $this->callAction($controller, $action, $args); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
6 |
|
private function getTracer(): TracerInterface |
72
|
|
|
{ |
73
|
|
|
try { |
74
|
6 |
|
return ContainerScope::getContainer()->get(TracerInterface::class); |
75
|
5 |
|
} catch (\Throwable $e) { |
76
|
5 |
|
return new NullTracer(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.