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\Annotations\Result; |
24
|
|
|
use AppserverIo\Routlt\Util\ServletContextAware; |
25
|
|
|
use AppserverIo\Psr\Servlet\ServletContextInterface; |
26
|
|
|
use AppserverIo\Psr\Servlet\ServletRequestInterface; |
27
|
|
|
use AppserverIo\Psr\Servlet\ServletResponseInterface; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Result implementation that dispatches another servlet. |
31
|
|
|
* |
32
|
|
|
* @author Tim Wagner <[email protected]> |
33
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
34
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
35
|
|
|
* @link http://github.com/appserver-io/routlt |
36
|
|
|
* @link http://www.appserver.io |
37
|
|
|
* |
38
|
|
|
* @Result(shared=false) |
39
|
|
|
*/ |
40
|
|
|
class ServletDispatcherResult extends AbstractResult implements ServletContextAware |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The servlet context instance. |
45
|
|
|
* |
46
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletContextInterface |
47
|
|
|
*/ |
48
|
|
|
protected $servletContext; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Sets the actual servlet context instance. |
52
|
|
|
* |
53
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletContextInterface $servletContext The servlet context instance |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
1 |
|
public function setServletContext(ServletContextInterface $servletContext) |
58
|
|
|
{ |
59
|
1 |
|
$this->servletContext = $servletContext; |
60
|
1 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the servlet context instance. |
64
|
|
|
* |
65
|
|
|
* @return \AppserverIo\Psr\Servlet\ServletContextInterface The servlet context instance |
66
|
|
|
*/ |
67
|
1 |
|
public function getServletContext() |
68
|
|
|
{ |
69
|
1 |
|
return $this->servletContext; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Processes an action result by dispatching the configured servlet. |
74
|
|
|
* |
75
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletRequestInterface $servletRequest The request instance |
76
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletResponseInterface $servletResponse The response sent back to the client |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
1 |
|
public function process(ServletRequestInterface $servletRequest, ServletResponseInterface $servletResponse) |
81
|
|
|
{ |
82
|
|
|
|
83
|
|
|
// initialize the variables for the path and the query string |
84
|
1 |
|
$path = null; |
85
|
1 |
|
$query = null; |
86
|
|
|
|
87
|
|
|
// load result and session-ID |
88
|
1 |
|
extract(parse_url($this->getResult())); |
|
|
|
|
89
|
|
|
|
90
|
|
|
// initialize the request URI |
91
|
1 |
|
if (!empty($path)) { |
92
|
1 |
|
$servletRequest->setRequestUri($path); |
|
|
|
|
93
|
1 |
|
} |
94
|
|
|
|
95
|
|
|
// initialize the query string |
96
|
1 |
|
if (!empty($query)) { |
97
|
1 |
|
$servletRequest->setQueryString($query); |
|
|
|
|
98
|
1 |
|
} |
99
|
|
|
|
100
|
|
|
// prepare the request with the new data |
101
|
1 |
|
$servletRequest->prepare(); |
|
|
|
|
102
|
|
|
|
103
|
|
|
// load the servlet and process it |
104
|
1 |
|
$servlet = $this->getServletContext()->lookup($servletRequest->getServletPath()); |
|
|
|
|
105
|
1 |
|
$servlet->service($servletRequest, $servletResponse); |
106
|
1 |
|
} |
107
|
|
|
} |
108
|
|
|
|