|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pim\Bundle\CustomEntityBundle\Action; |
|
4
|
|
|
|
|
5
|
|
|
use Pim\Bundle\CustomEntityBundle\Configuration\Registry; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @author Antoine Guigan <[email protected]> |
|
10
|
|
|
* @copyright 2013 Akeneo SAS (http://www.akeneo.com) |
|
11
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
12
|
|
|
*/ |
|
13
|
|
|
class ActionFactory |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var ContainerInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $container; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var Registry |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $configurationRegistry; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var ActionInterface[][] |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $actions = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param ContainerInterface $container |
|
32
|
|
|
* @param Registry $configurationRegistry |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(ContainerInterface $container, Registry $configurationRegistry) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->container = $container; |
|
37
|
|
|
$this->configurationRegistry = $configurationRegistry; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param string $customEntityName |
|
42
|
|
|
* @param string $actionType |
|
43
|
|
|
* |
|
44
|
|
|
* @return ActionInterface |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getAction($customEntityName, $actionType) |
|
47
|
|
|
{ |
|
48
|
|
|
if (isset($this->actions[$customEntityName][$actionType])) { |
|
49
|
|
|
return $this->actions[$customEntityName][$actionType]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if (!$this->configurationRegistry->has($customEntityName)) { |
|
53
|
|
|
return null; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$configuration = $this->configurationRegistry->get($customEntityName); |
|
57
|
|
|
|
|
58
|
|
|
if (!$configuration->hasAction($actionType)) { |
|
59
|
|
|
return null; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (!isset($this->actions[$customEntityName])) { |
|
63
|
|
|
$this->actions[$customEntityName] = []; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$action = $this->container->get($configuration->getAction($actionType)); |
|
67
|
|
|
$this->actions[$customEntityName][$actionType] = $action; |
|
68
|
|
|
$action->setConfiguration($configuration); |
|
69
|
|
|
|
|
70
|
|
|
return $action; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|