1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: execut |
4
|
|
|
* Date: 06.07.15 |
5
|
|
|
* Time: 17:51 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace execut\actions; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use execut\actions\action\Adapter; |
12
|
|
|
use execut\actions\action\Params; |
13
|
|
|
use yii\web\Response; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Action |
17
|
|
|
* |
18
|
|
|
* @property Adapter $adapter |
19
|
|
|
* @package execut\actions |
20
|
|
|
*/ |
21
|
|
|
class Action extends \yii\base\Action |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Adapter |
25
|
|
|
*/ |
26
|
|
|
protected $_adapter; |
27
|
|
|
protected $_view; |
28
|
|
|
public $flashes = []; |
29
|
|
|
public $response = null; |
30
|
|
|
|
31
|
|
|
public function init() |
32
|
|
|
{ |
33
|
|
|
parent::init(); // TODO: Change the autogenerated stub |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function setView($view) { |
37
|
|
|
if (is_array($view)) { |
38
|
|
|
$view = \Yii::createObject($view); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$this->_view = $view; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getView() { |
45
|
|
|
return $this->_view; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function setAdapter($adapter) { |
49
|
|
|
if (is_array($adapter)) { |
50
|
|
|
$adapter = \Yii::createObject($adapter); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$adapter->action = $this; |
54
|
|
|
|
55
|
|
|
$this->_adapter = $adapter; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return Adapter |
60
|
|
|
*/ |
61
|
|
|
public function getAdapter() { |
62
|
|
|
|
63
|
|
|
return $this->_adapter; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function run() { |
67
|
|
|
$this->trigger('beforeRun'); |
68
|
|
|
if ($adapter = $this->adapter) { |
69
|
|
|
$adapter->actionParams = $this->getParams(); |
70
|
|
|
|
71
|
|
|
$response = $adapter->run(); |
72
|
|
|
$this->response = $response; |
73
|
|
|
if ($response->flashes) { |
74
|
|
|
foreach ($response->flashes as $key => $flash) { |
75
|
|
|
$this->addFlash($key, $flash); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($response->content instanceof Response) { |
|
|
|
|
80
|
|
|
\yii::$app->layout = false; |
81
|
|
|
return $response->content; |
82
|
|
|
} |
83
|
|
|
} else { |
84
|
|
|
$response = []; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$this->trigger('beforeRender'); |
88
|
|
|
if ($adapter) { |
89
|
|
|
if ($this->getParams()->isAjax) { |
90
|
|
|
\yii::$app->layout = false; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if ($response->format === Response::FORMAT_HTML) { |
94
|
|
|
if ($view = $this->view) { |
95
|
|
|
$result = $this->controller->render($view, $response->content); |
96
|
|
|
} else { |
97
|
|
|
$result = $this->controller->renderContent($response->content); |
98
|
|
|
} |
99
|
|
|
} else { |
100
|
|
|
\yii::$app->response->format = $response->format; |
101
|
|
|
$result = $response->content; |
102
|
|
|
} |
103
|
|
|
} else { |
104
|
|
|
$result = $response; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$this->trigger('afterRun'); |
108
|
|
|
|
109
|
|
|
return $result; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
protected function addFlash($key, $flash) { |
113
|
|
|
$session = \yii::$app->session; |
114
|
|
|
if ($oldFlash = $session->getFlash($key)) { |
115
|
|
|
$flash = $oldFlash . "<br>" . $flash; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$session->setFlash($key, $flash); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getParams() { |
122
|
|
|
return Params::createFromAction($this); |
123
|
|
|
} |
124
|
|
|
} |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.