Completed
Push — master ( 84255c...a7d7e4 )
by Thomas
14:38
created

AbstractAction::getTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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;
0 ignored issues
show
Unused Code introduced by
The property $domainBackup is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
29
30
	public function __construct(Action $model, AbstractModule $module, AbstractResponse $response) {
31
		$this->model = $model;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
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);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter $resolver is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
}