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 pathWorkflowManager.php
More file actions
64 lines (48 loc) · 1.74 KB
/
WorkflowManager.php
File metadata and controls
64 lines (48 loc) · 1.74 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
<?php
namespace GOC\WorkflowBundle;
use Symfony\Component\DependencyInjection\Container;
use GOC\WorkflowBundle\Entity\Progress;
class WorkflowManager
{
private $container;
private $progress;
public function __construct(Container $container)
{
$this->container = $container;
}
public function create($definition, $id)
{
if (!is_object($definition)) {
$definition = $this->loadDefinitionByString($definition);
}
if (is_object($definition) && !$definition instanceof WorkflowDefinition) {
throw Exception::illegalDefinitionObject($definition);
}
$em = $this->container->get('doctrine')->getEntityManager();
// TODO: nicht sonderlich sauber ;)
if (!$id) {
$progress = new Progress();
$progress->setName($definition->getName());
} else if ($id instanceof Progress) {
$progress = $id;
} else if ($id > 0) {
$progress = $em->find('GOCWorkflowBundle:Progress', $id);
}
$em->persist($progress);
$em->flush();
return new Workflow($this->container, $definition, $progress);
}
public function loadDefinitionByString($definition)
{
if (!preg_match('#^([_a-zA-Z0-9]+Bundle):([/_a-zA-Z0-9]+)$#', $definition, $matches)) {
throw Exception::illegalDefinitionString($definition);
}
$bundle = $matches[1];
$class = $matches[2];
$bundle = preg_replace('#([A-Z])#', '/\1', $bundle);
$bundle = substr($bundle, 1, -strlen('_Bundle')) . 'Bundle';
$class = '/' . $bundle . '/Workflow/' . $class;
$class = str_replace('/', '\\', $class);
return new $class($this->container);
}
}