ServletDispatcherResult::process()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 14
cts 14
cp 1
rs 9.488
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 3
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()));
0 ignored issues
show
Bug introduced by
parse_url($this->getResult()) cannot be passed to extract() as the parameter $var_array expects a reference.
Loading history...
89
90
        // initialize the request URI
91 1
        if (!empty($path)) {
92 1
            $servletRequest->setRequestUri($path);
0 ignored issues
show
Bug introduced by
The method setRequestUri() does not seem to exist on object<AppserverIo\Psr\S...ervletRequestInterface>.

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.

Loading history...
93 1
        }
94
95
        // initialize the query string
96 1
        if (!empty($query)) {
97 1
            $servletRequest->setQueryString($query);
0 ignored issues
show
Bug introduced by
The method setQueryString() does not seem to exist on object<AppserverIo\Psr\S...ervletRequestInterface>.

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.

Loading history...
98 1
        }
99
100
        // prepare the request with the new data
101 1
        $servletRequest->prepare();
0 ignored issues
show
Bug introduced by
The method prepare() does not seem to exist on object<AppserverIo\Psr\S...ervletRequestInterface>.

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.

Loading history...
102
103
        // load the servlet and process it
104 1
        $servlet = $this->getServletContext()->lookup($servletRequest->getServletPath());
0 ignored issues
show
Bug introduced by
The method lookup() does not seem to exist on object<AppserverIo\Psr\S...ervletContextInterface>.

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.

Loading history...
105 1
        $servlet->service($servletRequest, $servletResponse);
106 1
    }
107
}
108