-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathExternalWorkflowProxy.php
More file actions
66 lines (55 loc) · 1.74 KB
/
ExternalWorkflowProxy.php
File metadata and controls
66 lines (55 loc) · 1.74 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
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Temporal\Internal\Workflow;
use React\Promise\PromiseInterface;
use Temporal\Internal\Declaration\Prototype\WorkflowPrototype;
use Temporal\Internal\Support\Reflection;
use Temporal\Workflow\ExternalWorkflowStubInterface;
/**
* @template-covariant T of object
* @mixin T
* @internal
*/
final class ExternalWorkflowProxy extends Proxy
{
/**
* @var string
*/
private const ERROR_INVALID_SIGNAL_METHOD =
'External workflows only support signal methods, however the called ' .
'method named "%s" of external workflow "%s" is not valid signal method.'
;
/**
* @var class-string
*/
private string $class;
private WorkflowPrototype $workflow;
private ExternalWorkflowStubInterface $stub;
/**
* @param class-string $class
*/
public function __construct(string $class, WorkflowPrototype $workflow, ExternalWorkflowStubInterface $stub)
{
$this->class = $class;
$this->workflow = $workflow;
$this->stub = $stub;
}
public function __call(string $method, array $args): PromiseInterface
{
foreach ($this->workflow->getSignalHandlers() as $name => $definition) {
if ($method === $definition->method->getName()) {
$args = Reflection::orderArguments($definition->method, $args);
return $this->stub->signal($name, $args);
}
}
throw new \BadMethodCallException(
\sprintf(self::ERROR_INVALID_SIGNAL_METHOD, $method, $this->class),
);
}
}