1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Global Trading Technologies Ltd workflow-extension-bundle package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* (c) fduch <[email protected]> |
9
|
|
|
* |
10
|
|
|
* Date: 14.09.16 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\Action\Reference; |
14
|
|
|
|
15
|
|
|
use ReflectionMethod; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Reference to static class method |
19
|
|
|
* |
20
|
|
|
* @author fduch <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class StaticMethod implements ActionReferenceInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* FQCN which static method is used as an action |
26
|
|
|
* |
27
|
|
|
* @var string|null |
28
|
|
|
*/ |
29
|
|
|
private $className; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Method name used as action |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $methodName; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Action type |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $type; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Action method reflection |
47
|
|
|
* |
48
|
|
|
* @var ReflectionMethod |
49
|
|
|
*/ |
50
|
|
|
private $reflectionMethod; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* ActionReference constructor. |
54
|
|
|
* |
55
|
|
|
* @param string $methodName method name |
56
|
|
|
* @param string $className FQCN of the class which method is used as an action |
57
|
|
|
* @param string $type action reference type |
58
|
|
|
*/ |
59
|
|
|
public function __construct($methodName, $className, $type = self::TYPE_REGULAR) |
60
|
|
|
{ |
61
|
|
|
$this->methodName = $methodName; |
62
|
|
|
$this->className = $className; |
63
|
|
|
$this->type = $type; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Returns action type |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getType() |
72
|
|
|
{ |
73
|
|
|
return $this->type; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Invokes action |
78
|
|
|
* |
79
|
|
|
* @param array $args action args |
80
|
|
|
* |
81
|
|
|
* @return mixed |
82
|
|
|
*/ |
83
|
|
|
public function invoke(array $args) |
84
|
|
|
{ |
85
|
|
|
return $this->getReflectionMethod()->invokeArgs(null, $args); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Returns reflection method |
90
|
|
|
* |
91
|
|
|
* @return ReflectionMethod |
92
|
|
|
*/ |
93
|
|
|
private function getReflectionMethod() |
94
|
|
|
{ |
95
|
|
|
if (!$this->reflectionMethod) { |
96
|
|
|
$this->reflectionMethod = new ReflectionMethod($this->className, $this->methodName); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $this->reflectionMethod; |
100
|
|
|
} |
101
|
|
|
} |