-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathAbstractActionManager.php
More file actions
88 lines (73 loc) · 2.7 KB
/
AbstractActionManager.php
File metadata and controls
88 lines (73 loc) · 2.7 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
<?php
namespace Spy\TimelineBundle\Driver\Doctrine;
use Doctrine\Persistence\ObjectManager;
use Spy\Timeline\Model\ActionInterface;
use Spy\Timeline\ResultBuilder\ResultBuilderInterface;
use Spy\Timeline\Driver\AbstractActionManager as BaseActionManager;
use Spy\Timeline\Model\ComponentInterface;
use Spy\Timeline\ResolveComponent\ValueObject\ResolvedComponentData;
abstract class AbstractActionManager extends BaseActionManager
{
/**
* @var ObjectManager
*/
protected $objectManager;
/**
* @var ResultBuilderInterface
*/
protected $resultBuilder;
/**
* @param ObjectManager $objectManager objectManager
* @param ResultBuilderInterface $resultBuilder resultBuilder
* @param string $actionClass actionClass
* @param string $componentClass componentClass
* @param string $actionComponentClass actionComponentClass
*/
public function __construct(ObjectManager $objectManager, ResultBuilderInterface $resultBuilder, $actionClass, $componentClass, $actionComponentClass)
{
$this->objectManager = $objectManager;
$this->resultBuilder = $resultBuilder;
parent::__construct($actionClass, $componentClass, $actionComponentClass);
}
/**
* {@inheritdoc}
*/
public function updateAction(ActionInterface $action)
{
$this->objectManager->persist($action);
$this->objectManager->flush();
$this->deployActionDependOnDelivery($action);
}
/**
* {@inheritdoc}
*/
public function createComponent($model, $identifier = null, $flush = true)
{
$resolvedComponentData = $this->resolveModelAndIdentifier($model, $identifier);
return $this->createComponentFromResolvedComponentData($resolvedComponentData, $flush);
}
/**
* {@inheritdoc}
*/
public function flushComponents()
{
$this->objectManager->flush();
}
/**
* Creates a component from a resolved model and identifier and optionally stores it to the storage engine.
*
* @param ResolvedComponentData $resolved The resolved component data
* @param boolean $flush Whether to flush or not, defaults to true
*
* @return ComponentInterface The newly created and populated component
*/
protected function createComponentFromResolvedComponentData(ResolvedComponentData $resolved, $flush = true)
{
$component = $this->getComponentFromResolvedComponentData($resolved);
$this->objectManager->persist($component);
if ($flush) {
$this->flushComponents();
}
return $component;
}
}