1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Routlt\Results\AbstractResult |
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\ActionInterface; |
24
|
|
|
use AppserverIo\Routlt\Util\ActionAware; |
25
|
|
|
use AppserverIo\Routlt\Util\DescriptorAware; |
26
|
|
|
use AppserverIo\Routlt\Description\ResultConfigurationDescriptorInterface; |
27
|
|
|
use AppserverIo\Psr\Deployment\DescriptorInterface; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Abstract result implementation that provides basic result functionality. |
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
|
|
|
abstract class AbstractResult implements ResultInterface, ActionAware, DescriptorAware |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The descriptor instance. |
43
|
|
|
* |
44
|
|
|
* @var \AppserverIo\Routlt\Description\ResultDescriptorInterface |
45
|
|
|
*/ |
46
|
|
|
protected $descriptor; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The action result name. |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected $name; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The action result type. |
57
|
|
|
* |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $type; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* The action result value. |
64
|
|
|
* |
65
|
|
|
* @var array |
66
|
|
|
*/ |
67
|
|
|
protected $result; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* The HTTP response code that has to be send. |
71
|
|
|
* |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
protected $code = 200; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Initializes the result from the result configuration descriptor instance. |
78
|
|
|
* |
79
|
|
|
* @param \AppserverIo\Routlt\Description\ResultConfigurationDescriptorInterface $resultConfigurationDescriptor The result configuration descriptor |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
9 |
|
public function init(ResultConfigurationDescriptorInterface $resultConfigurationDescriptor) |
84
|
|
|
{ |
85
|
|
|
|
86
|
|
|
// initialize the properites |
87
|
9 |
|
$this->name = $resultConfigurationDescriptor->getName(); |
88
|
9 |
|
$this->type = $resultConfigurationDescriptor->getType(); |
89
|
9 |
|
$this->code = $resultConfigurationDescriptor->getCode(); |
|
|
|
|
90
|
9 |
|
$this->result = $resultConfigurationDescriptor->getResult(); |
|
|
|
|
91
|
9 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns the action result name. |
95
|
|
|
* |
96
|
|
|
* @return string The action result name |
97
|
|
|
*/ |
98
|
3 |
|
public function getName() |
99
|
|
|
{ |
100
|
3 |
|
return $this->name; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Returns the action result type. |
105
|
|
|
* |
106
|
|
|
* @return string The action result type |
107
|
|
|
*/ |
108
|
3 |
|
public function getType() |
109
|
|
|
{ |
110
|
3 |
|
return $this->type; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns the action result value. |
115
|
|
|
* |
116
|
|
|
* @return string The action result value |
117
|
|
|
*/ |
118
|
6 |
|
public function getResult() |
119
|
|
|
{ |
120
|
6 |
|
return $this->result; |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Returns the HTTP response code that has to be send. |
125
|
|
|
* |
126
|
|
|
* @return integer The HTTP response code |
127
|
|
|
*/ |
128
|
|
|
public function getCode() |
129
|
|
|
{ |
130
|
|
|
return $this->code; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Sets the actual action instance. |
135
|
|
|
* |
136
|
|
|
* @param \AppserverIo\Routlt\ActionInterface $action The action instance |
137
|
|
|
* |
138
|
|
|
* @return void |
139
|
|
|
*/ |
140
|
5 |
|
public function setAction(ActionInterface $action) |
141
|
|
|
{ |
142
|
5 |
|
$this->action = $action; |
|
|
|
|
143
|
5 |
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Returns the action instance. |
147
|
|
|
* |
148
|
|
|
* @return \AppserverIo\Routlt\ActionInterface The action instance |
149
|
|
|
*/ |
150
|
5 |
|
public function getAction() |
151
|
|
|
{ |
152
|
5 |
|
return $this->action; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Sets the descriptor instance. |
157
|
|
|
* |
158
|
|
|
* @param \AppserverIo\Psr\Deployment\DescriptorInterface $descriptor The descriptor instance |
159
|
|
|
* |
160
|
|
|
* @return void |
161
|
|
|
*/ |
162
|
|
|
public function setDescriptor(DescriptorInterface $descriptor) |
163
|
|
|
{ |
164
|
|
|
$this->descriptor = $descriptor; |
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Returns the descriptor instance. |
169
|
|
|
* |
170
|
|
|
* @return \AppserverIo\Psr\Deployment\DescriptorInterface The descriptor instance |
171
|
|
|
*/ |
172
|
|
|
public function getDescriptor() |
173
|
|
|
{ |
174
|
|
|
return $this->descriptor; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.