1 | <?php |
||
42 | abstract class BaseAction extends Object implements ActionInterface, ValidationAware, ServletContextAware, DescriptorAware |
||
43 | { |
||
44 | |||
45 | /** |
||
46 | * Holds the name of the default method to invoke if the parameter with the method name to invoke is not specified. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | const DEFAULT_METHOD_NAME = 'perform'; |
||
51 | |||
52 | /** |
||
53 | * The context for the actual request. |
||
54 | * |
||
55 | * @var \AppserverIo\Psr\Servlet\ServletContextInterface |
||
56 | */ |
||
57 | protected $servletContext = null; |
||
58 | |||
59 | /** |
||
60 | * The array with the action errors. |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | protected $errors = array(); |
||
65 | |||
66 | /** |
||
67 | * The action specific attributes. |
||
68 | * |
||
69 | * @var array |
||
70 | */ |
||
71 | protected $attributes = array(); |
||
72 | |||
73 | /** |
||
74 | * The array with the action results. |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $results = array(); |
||
79 | |||
80 | /** |
||
81 | * The descriptor instance. |
||
82 | * |
||
83 | * @var \AppserverIo\Psr\Deployment\DescriptorInterface |
||
84 | */ |
||
85 | protected $descriptor; |
||
86 | |||
87 | /** |
||
88 | * Sets the actual servlet context instance. |
||
89 | * |
||
90 | * @param \AppserverIo\Psr\Servlet\ServletContextInterface $servletContext The servlet context instance |
||
91 | * |
||
92 | * @return void |
||
93 | */ |
||
94 | public function setServletContext(ServletContextInterface $servletContext) |
||
98 | |||
99 | /** |
||
100 | * Returns the servlet context instance. |
||
101 | * |
||
102 | * @return \AppserverIo\Psr\Servlet\ServletContextInterface The servlet context instance |
||
103 | */ |
||
104 | public function getServletContext() |
||
108 | |||
109 | /** |
||
110 | * Method that will be invoked before we dispatch the request. |
||
111 | * |
||
112 | * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The request instance |
||
113 | * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance |
||
114 | * |
||
115 | * @return void |
||
116 | * @see \AppserverIo\Routlt\ActionInterface::preDispatch() |
||
117 | */ |
||
118 | 1 | public function preDispatch(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse) |
|
122 | |||
123 | /** |
||
124 | * Method that will be invoked after we've dispatched the request. |
||
125 | * |
||
126 | * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The request instance |
||
127 | * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance |
||
128 | * |
||
129 | * @return void |
||
130 | * @see \AppserverIo\Routlt\ActionInterface::postDispatch() |
||
131 | */ |
||
132 | 1 | public function postDispatch(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse) |
|
136 | |||
137 | /** |
||
138 | * This method returns the default action method name that has to be invoked . |
||
139 | * |
||
140 | * @return string The default action method name that has to be invoked |
||
141 | */ |
||
142 | 1 | public function getDefaultMethod() |
|
146 | |||
147 | /** |
||
148 | * Returns the attributes of the action instance. |
||
149 | * |
||
150 | * @return array The attributes of the action instance |
||
151 | */ |
||
152 | public function getAttributes() |
||
156 | |||
157 | /** |
||
158 | * Query's whether or not an attribute with the passed key has been |
||
159 | * attached to the action instance. |
||
160 | * |
||
161 | * @param string $key The key of the attribute to query for |
||
162 | * |
||
163 | * @return boolean TRUE if the attribute has been attached, else FALSE |
||
164 | */ |
||
165 | public function hasAttribute($key) |
||
169 | |||
170 | /** |
||
171 | * Attaches the passed value with passed key to the action instance. |
||
172 | * |
||
173 | * @param string $key The key to attach the data with |
||
174 | * @param mixed $value The data to be attached |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | 2 | public function setAttribute($key, $value) |
|
182 | |||
183 | /** |
||
184 | * Returns the data with the passed key from the context of the action instance. |
||
185 | * |
||
186 | * @param string $key The key to return the data for |
||
187 | * |
||
188 | * @return mixed The requested data |
||
189 | */ |
||
190 | 2 | public function getAttribute($key) |
|
196 | |||
197 | /** |
||
198 | * Adds the result to the action. |
||
199 | * |
||
200 | * @param \AppserverIo\Routlt\Results\ResultInterface $result The result that has to be added |
||
201 | * |
||
202 | * @return void |
||
203 | * @see \AppserverIo\Routlt\ActionInterface::addResult() |
||
204 | */ |
||
205 | 1 | public function addResult(ResultInterface $result) |
|
209 | |||
210 | /** |
||
211 | * Tries to find and return the result with the passed name. |
||
212 | * |
||
213 | * @param string $name The name of the result to return |
||
214 | * |
||
215 | * @return \AppserverIo\Routlt\Results\ResultInterface|null The requested result |
||
216 | * @see \AppserverIo\Routlt\ActionInterface::findResult() |
||
217 | */ |
||
218 | 2 | public function findResult($name) |
|
224 | |||
225 | /** |
||
226 | * Adds a field error with the passed name and message. |
||
227 | * |
||
228 | * @param string $name The name to add the message with |
||
229 | * @param string $message The message to add |
||
230 | * |
||
231 | * @return void |
||
232 | * @see \AppserverIo\Routlt\Util\ValidationAware::addFieldError() |
||
233 | */ |
||
234 | 1 | public function addFieldError($name, $message) |
|
238 | |||
239 | /** |
||
240 | * Returns TRUE if validation found errors, else FALSE. |
||
241 | * |
||
242 | * @return boolean TRUE if validation found errors, else FALSE |
||
243 | * @see \AppserverIo\Routlt\Util\ValidationAware::hasErrors() |
||
244 | */ |
||
245 | 1 | public function hasErrors() |
|
249 | |||
250 | /** |
||
251 | * Returns the array with action errors. |
||
252 | * |
||
253 | * @return array The array with action errors |
||
254 | * @see \AppserverIo\Routlt\Util\ValidationAware::getErrors() |
||
255 | */ |
||
256 | 1 | public function getErrors() |
|
260 | |||
261 | /** |
||
262 | * Sets the descriptor instance. |
||
263 | * |
||
264 | * @param \AppserverIo\Psr\Deployment\DescriptorInterface $descriptor The descriptor instance |
||
265 | * |
||
266 | * @return void |
||
267 | */ |
||
268 | public function setDescriptor(DescriptorInterface $descriptor) |
||
272 | |||
273 | /** |
||
274 | * Returns the descriptor instance. |
||
275 | * |
||
276 | * @return \AppserverIo\Psr\Deployment\DescriptorInterface The descriptor instance |
||
277 | */ |
||
278 | public function getDescriptor() |
||
282 | } |
||
283 |