1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/old-town/old-town-workflow |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace OldTown\Workflow\Util\PhpShell; |
7
|
|
|
|
8
|
|
|
use OldTown\PropertySet\PropertySetInterface; |
9
|
|
|
use OldTown\Workflow\Spi\WorkflowEntryInterface; |
10
|
|
|
use OldTown\Workflow\TransientVars\TransientVarsInterface; |
11
|
|
|
use OldTown\Workflow\WorkflowContextInterface; |
12
|
|
|
use OldTown\Workflow\ValidatorInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class PhpShellValidatorProvider |
16
|
|
|
* |
17
|
|
|
* @package OldTown\Workflow\Util\PhpShell |
18
|
|
|
*/ |
19
|
|
|
class PhpShellValidatorProvider implements ValidatorInterface, PhpShellProviderInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* |
23
|
|
|
* @param TransientVarsInterface $transientVars |
24
|
|
|
* @param array $args |
25
|
|
|
* @param PropertySetInterface $ps |
26
|
|
|
* @return bool |
27
|
|
|
* |
28
|
|
|
* @throws \OldTown\Workflow\Exception\RuntimeException |
29
|
|
|
* @throws \OldTown\Workflow\Exception\InvalidArgumentException |
30
|
|
|
*/ |
31
|
4 |
|
public function validate(TransientVarsInterface $transientVars, array $args = [], PropertySetInterface $ps) |
32
|
|
|
{ |
33
|
4 |
|
$script = array_key_exists(static::PHP_SCRIPT, $args) ? $args[static::PHP_SCRIPT] : ''; |
34
|
|
|
|
35
|
|
|
/**@var WorkflowContextInterface $context */ |
36
|
4 |
|
$context = $transientVars->offsetExists('context') ? $transientVars['context'] : null; |
37
|
|
|
|
38
|
|
|
/**@var WorkflowEntryInterface $entry */ |
39
|
4 |
|
$entry = $transientVars->offsetExists('entry') ? $transientVars['entry'] : null; |
40
|
|
|
|
41
|
|
|
|
42
|
4 |
|
$i = new Interpreter($script); |
43
|
|
|
|
44
|
4 |
|
$i->setContextParam('entry', $entry); |
45
|
4 |
|
$i->setContextParam('context', $context); |
46
|
4 |
|
$i->setContextParam('transientVars', $transientVars); |
47
|
4 |
|
$i->setContextParam('propertySet', $ps); |
48
|
4 |
|
$i->setContextParam('args', $args); |
49
|
|
|
|
50
|
|
|
|
51
|
4 |
|
$i->evalScript(); |
52
|
2 |
|
} |
53
|
|
|
} |
54
|
|
|
|