1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Routlt\Results\ServletDispatcherResult |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link http://github.com/appserver-io/routlt |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Routlt\Results; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Routlt\Util\ServletContextAware; |
24
|
|
|
use AppserverIo\Psr\Servlet\ServletContextInterface; |
25
|
|
|
use AppserverIo\Psr\Servlet\ServletRequestInterface; |
26
|
|
|
use AppserverIo\Psr\Servlet\ServletResponseInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Result implementation that dispatches another servlet. |
30
|
|
|
* |
31
|
|
|
* @author Tim Wagner <[email protected]> |
32
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
34
|
|
|
* @link http://github.com/appserver-io/routlt |
35
|
|
|
* @link http://www.appserver.io |
36
|
|
|
*/ |
37
|
|
|
class ServletDispatcherResult implements ResultInterface, ServletContextAware |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Trait proving basic result functionality. |
42
|
|
|
* |
43
|
|
|
* @var \AppserverIo\Routlt\Results\ResultTrait |
44
|
|
|
*/ |
45
|
|
|
use ResultTrait; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The servlet context instance. |
49
|
|
|
* |
50
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletContextInterface |
51
|
|
|
*/ |
52
|
|
|
protected $servletContext; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Sets the actual servlet context instance. |
56
|
|
|
* |
57
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletContextInterface $servletContext The servlet context instance |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
public function setServletContext(ServletContextInterface $servletContext) |
62
|
|
|
{ |
63
|
|
|
$this->servletContext = $servletContext; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Returns the servlet context instance. |
68
|
|
|
* |
69
|
|
|
* @return \AppserverIo\Psr\Servlet\ServletContextInterface The servlet context instance |
70
|
|
|
*/ |
71
|
|
|
public function getServletContext() |
72
|
|
|
{ |
73
|
|
|
return $this->servletContext; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Processes an action result by dispatching the configured servlet. |
78
|
|
|
* |
79
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletRequestInterface $servletRequest The request instance |
80
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletResponseInterface $servletResponse The response sent back to the client |
81
|
|
|
* |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
public function process(ServletRequestInterface $servletRequest, ServletResponseInterface $servletResponse) |
85
|
|
|
{ |
86
|
|
|
|
87
|
|
|
// initialize the variables for the path and the query string |
88
|
|
|
$path = null; |
89
|
|
|
$query = null; |
90
|
|
|
|
91
|
|
|
// load result and session-ID |
92
|
|
|
extract(parse_url($this->getResult())); |
|
|
|
|
93
|
|
|
|
94
|
|
|
// initialize the request URI |
95
|
|
|
if (!empty($path)) { |
96
|
|
|
$servletRequest->setRequestUri($path); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// initialize the query string |
100
|
|
|
if (!empty($query)) { |
101
|
|
|
$servletRequest->setQueryString($query); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
// prepare the request with the new data |
105
|
|
|
$servletRequest->prepare(); |
|
|
|
|
106
|
|
|
|
107
|
|
|
// load the servlet path and session-ID |
108
|
|
|
$servletPath = $servletRequest->getServletPath(); |
109
|
|
|
$sessionId = $servletRequest->getProposedSessionId(); |
|
|
|
|
110
|
|
|
|
111
|
|
|
// load and process the servlet |
112
|
|
|
$servlet = $this->getServletContext()->lookup($servletPath, $sessionId); |
|
|
|
|
113
|
|
|
$servlet->service($servletRequest, $servletResponse); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|