|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Zikula package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright Zikula Foundation - http://zikula.org/ |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Zikula\Bundle\WorkflowBundle\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
15
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
19
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
20
|
|
|
use Zikula\ThemeModule\Engine\Annotation\Theme; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Workflow editor controller class. |
|
24
|
|
|
* |
|
25
|
|
|
* @Route("/editor") |
|
26
|
|
|
*/ |
|
27
|
|
|
class EditorController extends Controller |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* This is the default action handling the index action. |
|
31
|
|
|
* |
|
32
|
|
|
* @Route("/index", |
|
33
|
|
|
* methods = {"GET"} |
|
34
|
|
|
* ) |
|
35
|
|
|
* @Theme("admin") |
|
36
|
|
|
* @Template |
|
37
|
|
|
* |
|
38
|
|
|
* @param Request $request Current request instance |
|
39
|
|
|
* |
|
40
|
|
|
* @return Response Output |
|
41
|
|
|
* |
|
42
|
|
|
* @throws AccessDeniedException Thrown if the user doesn't have required permissions |
|
43
|
|
|
* @throws NotFoundHttpException Thrown if the desired workflow could not be found |
|
44
|
|
|
*/ |
|
45
|
|
|
public function indexAction(Request $request) |
|
46
|
|
|
{ |
|
47
|
|
|
if (!$this->get('zikula_permissions_module.api.permission')->hasPermission('ZikulaWorkflowBundle::', '::', ACCESS_ADMIN)) { |
|
48
|
|
|
throw new AccessDeniedException(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$workflowType = 'workflow'; |
|
52
|
|
|
$workflowName = $workflowType . '.' . $request->query->get('workflow', ''); |
|
53
|
|
|
if (!$this->get('service_container')->has($workflowName)) { |
|
54
|
|
|
$workflowType = 'state_machine'; |
|
55
|
|
|
$workflowName = $workflowType . '.' . $request->query->get('workflow', ''); |
|
56
|
|
|
} |
|
57
|
|
|
if (!$this->get('service_container')->has($workflowName)) { |
|
58
|
|
|
throw new NotFoundHttpException($this->get('translator.default')->__f('Workflow "%workflow%" not found.', ['%workflow%' => $workflowName])); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$workflow = $this->get($workflowName); |
|
62
|
|
|
$workflowDefinition = $workflow->getDefinition(); |
|
63
|
|
|
|
|
64
|
|
|
$markingStoreType = ''; |
|
65
|
|
|
$markingStoreField = ''; |
|
66
|
|
|
$supportedEntityClassNames = []; |
|
67
|
|
|
try { |
|
68
|
|
|
$reflection = new \ReflectionClass('Symfony\Component\Workflow\Workflow'); |
|
69
|
|
|
$markingStoreProperty = $reflection->getProperty('markingStore'); |
|
70
|
|
|
$markingStoreProperty->setAccessible(true); |
|
71
|
|
|
$markingStore = $markingStoreProperty->getValue($workflow); |
|
72
|
|
|
if ($markingStore instanceof \Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore) { |
|
|
|
|
|
|
73
|
|
|
$markingStoreType = 'multiple_state'; |
|
74
|
|
|
} elseif ($markingStore instanceof \Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore) { |
|
|
|
|
|
|
75
|
|
|
$markingStoreType = 'single_state'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$reflection = new \ReflectionClass(get_class($markingStore)); |
|
79
|
|
|
$markingStoreFieldProperty = $reflection->getProperty('property'); |
|
80
|
|
|
$markingStoreFieldProperty->setAccessible(true); |
|
81
|
|
|
$markingStoreField = $markingStoreFieldProperty->getValue($markingStore); |
|
82
|
|
|
|
|
83
|
|
|
$registry = $this->get('workflow.registry'); |
|
84
|
|
|
$reflection = new \ReflectionClass(get_class($registry)); |
|
85
|
|
|
$workflowsProperty = $reflection->getProperty('workflows'); |
|
86
|
|
|
$workflowsProperty->setAccessible(true); |
|
87
|
|
|
$workflows = $workflowsProperty->getValue($registry); |
|
88
|
|
|
foreach ($workflows as list($aWorkflow, $className)) { |
|
89
|
|
|
if ($aWorkflow->getName() == $workflow->getName()) { |
|
90
|
|
|
$supportedEntityClassNames[] = $className; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} catch (\ReflectionException $e) { |
|
94
|
|
|
$markingStoreType = 'single_state'; |
|
95
|
|
|
$markingStoreField = 'state'; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return [ |
|
99
|
|
|
'name' => $workflow->getName(), |
|
100
|
|
|
'type' => $workflowType, |
|
101
|
|
|
'markingStoreType' => $markingStoreType, |
|
102
|
|
|
'markingStoreField' => $markingStoreField, |
|
103
|
|
|
'supportedEntities' => $supportedEntityClassNames, |
|
104
|
|
|
'workflow' => $workflowDefinition |
|
105
|
|
|
]; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.