1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Routlt\Results\JsonResult |
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\Http\HttpProtocol; |
24
|
|
|
use AppserverIo\Routlt\Annotations\Result; |
25
|
|
|
use AppserverIo\Routlt\Util\ValidationAware; |
26
|
|
|
use AppserverIo\Psr\Servlet\ServletRequestInterface; |
27
|
|
|
use AppserverIo\Psr\Servlet\ServletResponseInterface; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Result implementation that JSON encodes the response body. |
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
|
|
|
* @deprecated Since 2.0.0-alpha5, use AppserverIo\Routlt\Results\RawResult instead |
38
|
|
|
* |
39
|
|
|
* @Result(shared=false) |
40
|
|
|
*/ |
41
|
|
|
class JsonResult extends AbstractResult |
42
|
|
|
{ |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The key for the data that has to be JSON encoded. |
46
|
|
|
* |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
const DATA = 'json-result.data'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Processes an action result by dispatching the configured servlet. |
53
|
|
|
* |
54
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletRequestInterface $servletRequest The request instance |
55
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletResponseInterface $servletResponse The response sent back to the client |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
public function process(ServletRequestInterface $servletRequest, ServletResponseInterface $servletResponse) |
60
|
|
|
{ |
61
|
|
|
|
62
|
|
|
// load the action instance |
63
|
|
|
$action = $this->getAction(); |
64
|
|
|
|
65
|
|
|
// query whether the action contains errors or not |
66
|
|
|
if ($action instanceof ValidationAware && $action->hasErrors()) { |
67
|
|
|
$content = $action->getErrors(); |
68
|
|
|
} else { |
69
|
|
|
$content = $servletRequest->getAttribute(JsonResult::DATA); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// add the header for the JSON content type |
73
|
|
|
$servletResponse->addHeader(HttpProtocol::HEADER_CONTENT_TYPE, 'application/json'); |
|
|
|
|
74
|
|
|
|
75
|
|
|
// append the JSON encoded content to the servlet response |
76
|
|
|
$servletResponse->appendBodyStream(json_encode($content)); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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.