1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Hello\Modules\AbstractModule\Controllers\Traits; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Trait AbstractAuthenticationControllerTrait |
7
|
|
|
* @package ByTIC\Hello\Modules\AbstractModule\Controllers\Traits |
8
|
|
|
*/ |
9
|
|
|
trait AbstractAuthenticationControllerTrait |
10
|
|
|
{ |
11
|
|
|
use HasAuthenticationVariablesTrait; |
12
|
|
|
|
13
|
|
|
protected function beforeAction() |
14
|
|
|
{ |
15
|
|
|
parent::beforeAction(); |
16
|
|
|
$this->checkIsAuthenticated(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function afterActionViewVariables() |
20
|
|
|
{ |
21
|
|
|
parent::afterActionViewVariables(); |
22
|
|
|
|
23
|
|
|
$this->setAuthenticationVariablesInView(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param null $type |
|
|
|
|
28
|
|
|
*/ |
29
|
|
|
protected function checkIsAuthenticated() |
30
|
|
|
{ |
31
|
|
|
if ($this->getName() != 'logout' && $this->_getUser()->authenticated()) { |
|
|
|
|
32
|
|
|
$this->doSuccessRedirect(); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param null $type |
38
|
|
|
*/ |
39
|
|
|
protected function doSuccessRedirect($type = null) |
40
|
|
|
{ |
41
|
|
|
$type = empty($type) ? $this->getName() : $type; |
|
|
|
|
42
|
|
|
$this->flashRedirect( |
43
|
|
|
$this->getModelManager()->getMessage($type . '-success'), |
44
|
|
|
$this->getRedirectURL(), |
45
|
|
|
'success', |
46
|
|
|
'index' |
|
|
|
|
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
protected function getRedirectURL() |
54
|
|
|
{ |
55
|
|
|
$redirectVariable = $this->getAuthenticationValue('redirect'); |
56
|
|
|
if (!empty($redirectVariable)) { |
57
|
|
|
$url = urldecode($redirectVariable); |
58
|
|
|
if (valid_url($url)) { |
59
|
|
|
return $url; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
return $this->getGenericRedirectURL(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string|null |
67
|
|
|
*/ |
68
|
|
|
protected function getGenericRedirectURL() |
69
|
|
|
{ |
70
|
|
|
$module = $this->getRequest()->getModuleName(); |
71
|
|
|
return $this->Url()->assemble($module . '.logged_in'); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param $action |
76
|
|
|
*/ |
77
|
|
|
protected function _setMeta($action) |
78
|
|
|
{ |
79
|
|
|
$label = $this->getModelManager()->getLabel($action . '-title'); |
80
|
|
|
$urlMethod = 'get' . ucfirst($action) . 'URL'; |
81
|
|
|
$this->getView()->Breadcrumbs()->addItem($label, $this->_getUser()->getManager()->$urlMethod()); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$this->getView()->Meta()->prependTitle($label); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritdoc |
88
|
|
|
*/ |
89
|
|
|
protected function generateModelName() |
90
|
|
|
{ |
91
|
|
|
return get_class($this->_getUser()->getManager()); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.