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
|
|
|
* @date 08.08.16 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Exception\RuntimeException; |
15
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
16
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Checks that all necessary options for scheduler are set for classes supported by corresponding workflows |
22
|
|
|
*/ |
23
|
|
|
class CheckSubjectManipulatorConfigPass implements CompilerPassInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Workflow registry definition id |
27
|
|
|
*/ |
28
|
|
|
const WORKFLOW_REGISTRY_ID= 'workflow.registry'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Workflow id prefix used in main workflow bundle |
32
|
|
|
*/ |
33
|
|
|
const WORKFLOW_ID_PREFIX = 'workflow.'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Name of the method used to register workflows in registry |
37
|
|
|
*/ |
38
|
|
|
const WORKFLOW_REGISTRY_ADD_WORKFLOW_METHOD_NAME = "add"; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function process(ContainerBuilder $container) |
44
|
|
|
{ |
45
|
|
|
if (false === $container->hasDefinition(static::WORKFLOW_REGISTRY_ID)) { |
46
|
|
|
return; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (false === $container->hasDefinition('gtt.workflow.transition_scheduler')) { |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$subjectClassesWithSubjectFromDomain = $container->getParameter('gtt.workflow.subject_classes_with_subject_from_domain'); |
54
|
|
|
$workflowsWithScheduling = $container->getParameter('gtt.workflow.workflows_with_scheduling'); |
55
|
|
|
|
56
|
|
|
$registryDefinition = $container->getDefinition(self::WORKFLOW_REGISTRY_ID); |
57
|
|
|
foreach ($registryDefinition->getMethodCalls() as $call) { |
58
|
|
|
if ($call[0] == self::WORKFLOW_REGISTRY_ADD_WORKFLOW_METHOD_NAME) { |
59
|
|
|
$callArgs = $call[1]; |
60
|
|
|
|
61
|
|
|
if (count($callArgs) != 2 || !$callArgs[0] instanceof Reference || !is_string($callArgs[1])) { |
62
|
|
|
throw new RuntimeException( |
63
|
|
|
sprintf( |
64
|
|
|
'Workflow registry service have unsupported signature for "%s" method', |
65
|
|
|
self::WORKFLOW_REGISTRY_ADD_WORKFLOW_METHOD_NAME |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** @var Reference $workflowReference */ |
71
|
|
|
$workflowReference = $callArgs[0]; |
72
|
|
|
$workflowSupportedClass = $callArgs[1]; |
73
|
|
|
|
74
|
|
|
$workflowIdWithPrefix = (string) $workflowReference; |
75
|
|
|
if (substr($workflowIdWithPrefix, 0, strlen(self::WORKFLOW_ID_PREFIX)) != self::WORKFLOW_ID_PREFIX) { |
76
|
|
|
throw new RuntimeException( |
77
|
|
|
sprintf( |
78
|
|
|
"Workflow registry works with workflow id '%s'in unsupported format", |
79
|
|
|
$workflowIdWithPrefix |
80
|
|
|
) |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$workflowId = substr($workflowIdWithPrefix, strlen(self::WORKFLOW_ID_PREFIX)); |
85
|
|
|
|
86
|
|
|
if (in_array($workflowId, $workflowsWithScheduling) && |
87
|
|
|
!in_array(ltrim($workflowSupportedClass, "\\"), $subjectClassesWithSubjectFromDomain)) { |
88
|
|
|
throw new InvalidConfigurationException( |
89
|
|
|
sprintf( |
90
|
|
|
'Workflow "%s" configured to use scheduler so all the supported subject classes for it'. |
91
|
|
|
'must be configured with "subject_from_domain" option under "subject_manipulator". '. |
92
|
|
|
'This option for "%s" class is missing.', |
93
|
|
|
$workflowId, |
94
|
|
|
$workflowSupportedClass |
95
|
|
|
) |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |