1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TRedirect.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license https://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec <[email protected]> |
8
|
|
|
* @package iPublikuj:Application! |
9
|
|
|
* @subpackage UI |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 05.02.15 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\Application\UI; |
18
|
|
|
|
19
|
|
|
use Nette\Application; |
20
|
|
|
use Nette\Application\Responses; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Add improved redirects & forwarding into presenters & components |
24
|
|
|
* |
25
|
|
|
* @package iPublikuj:Application! |
26
|
|
|
* @subpackage UI |
27
|
|
|
* |
28
|
|
|
* @author Adam Kadlec <[email protected]> |
29
|
|
|
* |
30
|
|
|
* @method Application\UI\Presenter getPresenter() |
31
|
|
|
* @method string getUniqueId() |
32
|
|
|
* @method redrawControl($snippet = NULL, $redraw = TRUE) |
33
|
|
|
* @method redirect($code, $destination = NULL, $args = []) |
34
|
|
|
*/ |
35
|
1 |
|
trait TRedirect |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* Redirect only if not ajax |
39
|
|
|
* |
40
|
|
|
* @param string $destination |
41
|
|
|
* @param array $args |
42
|
|
|
* @param array $snippets |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
final public function go($destination, $args = [], $snippets = []) : void |
47
|
|
|
{ |
48
|
|
|
// Get presenter object |
49
|
1 |
|
$presenter = ($this instanceof Application\UI\Presenter) ? $this : $this->getPresenter(); |
|
|
|
|
50
|
|
|
|
51
|
1 |
|
if ($presenter->isAjax()) { |
52
|
1 |
|
foreach ($snippets as $snippet) { |
53
|
|
|
$this->redrawControl($snippet); |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
if ($destination !== 'this') { |
57
|
1 |
|
$this->forward($destination, $args); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} else { |
61
|
1 |
|
$this->redirect($destination, $args); |
62
|
|
|
} |
63
|
1 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Forward request to another |
67
|
|
|
* |
68
|
|
|
* @param string $destination |
69
|
|
|
* @param array $args |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
* |
73
|
|
|
* @throws Application\AbortException |
74
|
|
|
*/ |
75
|
|
|
public function forward($destination, $args = []) : void |
76
|
|
|
{ |
77
|
1 |
|
if (!$this->isPresenter()) { |
78
|
|
|
$name = $this->getUniqueId(); |
79
|
|
|
|
80
|
|
|
if ($destination != 'this') { |
81
|
|
|
$destination = "$name-$destination"; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$params = []; |
85
|
|
|
|
86
|
|
|
foreach ($args as $key => $val) { |
87
|
|
|
$params["$name-$key"] = $val; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// Process forwarding in control |
91
|
|
|
$this->getPresenter()->forward($destination, $params); |
92
|
|
|
|
93
|
|
|
} else { |
94
|
|
|
// Process forwarding in presenter |
95
|
1 |
|
parent::forward($destination, $args); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
|
|
private function isPresenter() : bool |
103
|
|
|
{ |
104
|
1 |
|
if ($this instanceof Application\UI\Presenter) { |
|
|
|
|
105
|
1 |
|
return TRUE; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return FALSE; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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.