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 02.08.16 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\MarkingStore; |
13
|
|
|
|
14
|
|
|
use Doctrine\Bundle\DoctrineBundle\Registry; |
15
|
|
|
use Symfony\Component\Workflow\Marking; |
16
|
|
|
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Decorates original marking store with ORM persisting feature during mutating the subject marking |
20
|
|
|
*/ |
21
|
|
|
class OrmPersistentMarkingStore implements MarkingStoreInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Origin marking store |
25
|
|
|
* |
26
|
|
|
* @var MarkingStoreInterface |
27
|
|
|
*/ |
28
|
|
|
private $originMarkingStore; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Doctrine registry |
32
|
|
|
* |
33
|
|
|
* @var Registry |
34
|
|
|
*/ |
35
|
|
|
private $doctrineRegistry; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* OrmPersistentMarkingStore constructor. |
39
|
|
|
* |
40
|
|
|
* @param MarkingStoreInterface $originMarkingStore origin marking store |
41
|
|
|
* @param Registry $doctrineRegistry doctrine registry |
42
|
|
|
*/ |
43
|
|
|
public function __construct(MarkingStoreInterface $originMarkingStore, Registry $doctrineRegistry) |
44
|
|
|
{ |
45
|
|
|
$this->doctrineRegistry = $doctrineRegistry; |
46
|
|
|
$this->originMarkingStore = $originMarkingStore; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function getMarking($subject) |
53
|
|
|
{ |
54
|
|
|
return $this->originMarkingStore->getMarking($subject); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Updates subject's marking and persists it using ORM |
59
|
|
|
* |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function setMarking($subject, Marking $marking) |
63
|
|
|
{ |
64
|
|
|
$this->originMarkingStore->setMarking($subject, $marking); |
65
|
|
|
|
66
|
|
|
$manager = $this->doctrineRegistry->getManagerForClass(get_class($subject)); |
67
|
|
|
// for DEFERRED_EXPLICIT change tracking policies we also persisting subject here |
68
|
|
|
$manager->persist($subject); |
69
|
|
|
$manager->flush(); |
70
|
|
|
} |
71
|
|
|
} |