1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace AtAdmin\Controller\Plugin;
|
4
|
|
|
|
5
|
|
|
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
|
6
|
|
|
use Zend\Session\Container;
|
7
|
|
|
|
8
|
|
|
class BackTo extends AbstractPlugin
|
9
|
|
|
{
|
10
|
|
|
/**
|
11
|
|
|
* @var string
|
12
|
|
|
*/
|
13
|
|
|
protected $paramName = 'backto';
|
14
|
|
|
|
15
|
|
|
/**
|
16
|
|
|
* @var Container
|
17
|
|
|
*/
|
18
|
|
|
protected $sessionContainer;
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* @param $name
|
22
|
|
|
*/
|
23
|
|
|
public function setParamName($name)
|
24
|
|
|
{
|
25
|
|
|
$this->paramName = (string) $name;
|
26
|
|
|
}
|
27
|
|
|
|
28
|
|
|
/**
|
29
|
|
|
* @param Container $container
|
30
|
|
|
* @return $this
|
31
|
|
|
*/
|
32
|
|
|
public function setSessionContainer(Container $container)
|
33
|
|
|
{
|
34
|
|
|
$this->sessionContainer = $container;
|
35
|
|
|
return $this;
|
36
|
|
|
}
|
37
|
|
|
|
38
|
|
|
/**
|
39
|
|
|
* @return Container
|
40
|
|
|
*/
|
41
|
|
|
public function getSessionContainer()
|
42
|
|
|
{
|
43
|
|
|
if (!$this->sessionContainer) {
|
44
|
|
|
$this->sessionContainer = new Container('at_base');
|
45
|
|
|
}
|
46
|
|
|
|
47
|
|
|
return $this->sessionContainer;
|
48
|
|
|
}
|
49
|
|
|
|
50
|
|
|
/**
|
51
|
|
|
* @param null $url
|
52
|
|
|
*/
|
53
|
|
|
public function setBackUrl($url = null)
|
54
|
|
|
{
|
55
|
|
|
if ($url) {
|
56
|
|
|
$url = (string) $url;
|
57
|
|
|
} else {
|
58
|
|
|
$url = $this->getController()->getRequest()->getRequestUri();
|
59
|
|
|
}
|
60
|
|
|
|
61
|
|
|
$session = $this->getSessionContainer();
|
62
|
|
|
$session->{$this->paramName} = $url;
|
63
|
|
|
}
|
64
|
|
|
|
65
|
|
|
/**
|
66
|
|
|
* @param bool $flush
|
67
|
|
|
* @return string
|
68
|
|
|
*/
|
69
|
|
|
public function getBackUrl($flush = true)
|
70
|
|
|
{
|
71
|
|
|
$backUrl = '/';
|
72
|
|
|
|
73
|
|
|
$session = $this->getSessionContainer();
|
74
|
|
|
if (isset($session->{$this->paramName})) {
|
75
|
|
|
$backUrl = $session->{$this->paramName};
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
if ($flush) {
|
79
|
|
|
$this->flush();
|
80
|
|
|
}
|
81
|
|
|
|
82
|
|
|
return $backUrl;
|
83
|
|
|
}
|
84
|
|
|
|
85
|
|
|
/**
|
86
|
|
|
* @return $this
|
87
|
|
|
*/
|
88
|
|
|
public function flush()
|
89
|
|
|
{
|
90
|
|
|
$session = $this->getSessionContainer();
|
91
|
|
|
unset($session->{$this->paramName});
|
92
|
|
|
return $this;
|
93
|
|
|
}
|
94
|
|
|
|
95
|
|
|
/**
|
96
|
|
|
* @param null $message
|
97
|
|
|
*/
|
98
|
|
|
public function previous($message = null)
|
99
|
|
|
{
|
100
|
|
|
// Return if it is ajax request
|
101
|
|
|
if ($this->getController()->getRequest()->isXmlHttpRequest()) {
|
102
|
|
|
return;
|
103
|
|
|
}
|
104
|
|
|
|
105
|
|
|
if ($message) {
|
106
|
|
|
$this->getController()->flashMessenger()->addMessage($message);
|
|
|
|
|
107
|
|
|
}
|
108
|
|
|
|
109
|
|
|
$this->getController()->redirect()->toUrl($this->getBackUrl());
|
|
|
|
|
110
|
|
|
}
|
111
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.