1
|
|
|
<?php |
2
|
|
|
namespace keeko\core\package; |
3
|
|
|
|
4
|
|
|
use keeko\core\kernel\KernelTargetInterface; |
5
|
|
|
use keeko\core\model\Action; |
6
|
|
|
use keeko\core\preferences\Preferences; |
7
|
|
|
use keeko\core\service\ServiceContainer; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
10
|
|
|
|
11
|
|
|
abstract class AbstractAction implements KernelTargetInterface { |
12
|
|
|
|
13
|
|
|
/** @var Action */ |
14
|
|
|
protected $model; |
15
|
|
|
|
16
|
|
|
/** @var AbstractModule */ |
17
|
|
|
protected $module; |
18
|
|
|
|
19
|
|
|
/** @var \Twig_Environment */ |
20
|
|
|
protected $twig; |
21
|
|
|
|
22
|
|
|
/** @var array */ |
23
|
|
|
protected $params = []; |
24
|
|
|
|
25
|
|
|
/** @var AbstractResponse */ |
26
|
|
|
protected $response; |
27
|
|
|
|
28
|
|
|
private $domainBackup; |
|
|
|
|
29
|
|
|
|
30
|
|
|
public function __construct(Action $model, AbstractModule $module, AbstractResponse $response) { |
31
|
|
|
$this->model = $model; |
|
|
|
|
32
|
|
|
$this->response = $response; |
33
|
|
|
|
34
|
|
|
$this->module = $module; |
35
|
|
|
$templatePath = sprintf('%s/%s/templates/', KEEKO_PATH_MODULES, $module->getModel()->getName()); |
36
|
|
|
|
37
|
|
|
if (file_exists($templatePath)) { |
38
|
|
|
$loader = new \Twig_Loader_Filesystem($templatePath); |
|
|
|
|
39
|
|
|
$this->twig = new \Twig_Environment($loader); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns the actions name |
45
|
|
|
* |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function getName() { |
49
|
|
|
return $this->model->getName(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns the canonical actions name |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getCanonicalName() { |
58
|
|
|
return $this->module->getCanonicalName() . '.' . $this->model->getName(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the actions title |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function getTitle() { |
67
|
|
|
return $this->model->getTitle(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the service container |
72
|
|
|
* |
73
|
|
|
* @return ServiceContainer |
74
|
|
|
*/ |
75
|
|
|
protected function getServiceContainer() { |
76
|
|
|
return $this->module->getServiceContainer(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the module's preferences |
81
|
|
|
* |
82
|
|
|
* @return Preferences |
83
|
|
|
*/ |
84
|
|
|
protected function getPreferences() { |
85
|
|
|
return $this->module->getPreferences(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function setParams($params) { |
89
|
|
|
$resolver = new OptionsResolver(); |
90
|
|
|
$this->configureParams($resolver); |
91
|
|
|
$this->params = $resolver->resolve($params); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
protected function configureParams(OptionsResolver $resolver) { |
|
|
|
|
95
|
|
|
// does nothing, extend this method and provide functionality for your action |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Returns the param |
100
|
|
|
* |
101
|
|
|
* @param string $name the param name |
102
|
|
|
* @return mixed |
103
|
|
|
*/ |
104
|
|
|
protected function getParam($name) { |
105
|
|
|
return $this->params[$name]; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Returns the associated action model |
110
|
|
|
* |
111
|
|
|
* @return Action |
112
|
|
|
*/ |
113
|
|
|
public function getModel() { |
114
|
|
|
return $this->model; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Returns the associated module |
119
|
|
|
* |
120
|
|
|
* @return AbstractModule |
121
|
|
|
*/ |
122
|
|
|
protected function getModule() { |
123
|
|
|
return $this->module; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Returns the modules twig |
128
|
|
|
* |
129
|
|
|
* @return \Twig_Environment |
130
|
|
|
*/ |
131
|
|
|
protected function getTwig() { |
132
|
|
|
return $this->module->getTwig(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
abstract public function run(Request $request); |
136
|
|
|
|
137
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.