This repository was archived by the owner on Oct 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorkflow.php
More file actions
93 lines (73 loc) · 2.23 KB
/
Workflow.php
File metadata and controls
93 lines (73 loc) · 2.23 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace GOC\WorkflowBundle;
use Symfony\Component\DependencyInjection\Container;
use GOC\WorkflowBundle\Entity\Progress;
use GOC\WorkflowBundle\Form\WorkflowType;
class Workflow
{
private $container;
private $definition;
private $progress;
public function __construct(Container $container, WorkflowDefinition $definition, Progress $progress)
{
$this->container = $container;
$this->definition = $definition;
$this->progress = $progress;
}
public function getDefinition()
{
return $this->definition;
}
public function execute($action, $data = null)
{
$this->getDefinition()->execute($action, $this->progress, $data);
}
public function getStatus()
{
return $this->progress->getStatus();
}
public function setActor($actor)
{
$this->progress->setActor($actor);
}
public function getActor()
{
return $this->progress->getActor();
}
public function getForm()
{
return $this->getDefinition()->getForm();
}
public function getView()
{
return $this->getDefinition()->getView();
}
public function getParameters(array $params)
{
return array(
'workflow' => $this,
) + $params;
}
public function getData()
{
return $this->getDefinition()->getData();
}
public function createResponse($postCheck = true)
{
$this->progress->setData($this->getData());
$type = new WorkflowType($this->getForm());
$form = $this->container->get('form.factory')->create($type, $this->progress);
$request = $this->container->get('request');
if ($postCheck && $request->getMethod() === 'POST') {
$form->bindRequest($request);
$actions = $request->request->get('submit');
$action = key($actions);
if ($form->isValid()) {
$this->execute($action, $form->getData()->getData());
return $this->createResponse(false);
}
}
return $this->container->get('templating')->renderResponse(
$this->getView(), $this->getParameters(array('form' => $form->createView())));
}
}