Controller::handleError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
// +---------------------------------------------------------------------------+
4
// | This file is part of the Agavi package.                                   |
5
// | Copyright (c) 2005-2011 the Agavi Project.                                |
6
// | Based on the Mojavi3 MVC Framework, Copyright (c) 2003-2005 Sean Kerr.    |
7
// |                                                                           |
8
// | For the full copyright and license information, please view the LICENSE   |
9
// | file that was distributed with this source code. You can also view the    |
10
// | LICENSE file online at http://www.agavi.org/LICENSE.txt                   |
11
// |   vi: set noexpandtab:                                                    |
12
// |   Local Variables:                                                        |
13
// |   indent-tabs-mode: t                                                     |
14
// |   End:                                                                    |
15
// +---------------------------------------------------------------------------+
16
namespace Agavi\Controller;
17
18
use Agavi\Core\Context;
19
use Agavi\Dispatcher\ExecutionContainer;
20
use Agavi\Request\RequestDataHolder;
21
22
/**
23
 * Controller allows you to separate application and business logic from your
24
 * presentation. By providing a core set of methods used by the framework,
25
 * automation in the form of security and validation can occur.
26
 *
27
 * @package    agavi
28
 * @subpackage controller
29
 *
30
 * @author     Sean Kerr <[email protected]>
31
 * @author     David Zülke <[email protected]>
32
 * @copyright  Authors
33
 * @copyright  The Agavi Project
34
 *
35
 * @since      0.9.0
36
 *
37
 * @version    $Id$
38
 */
39
abstract class Controller
40
{
41
    /**
42
     * @var        ExecutionContainer This controller's execution container.
43
     */
44
    protected $container = null;
45
46
    /**
47
     * @var        Context A Context instance.
48
     */
49
    protected $context = null;
50
51
    /**
52
     * Retrieve the current application context.
53
     *
54
     * @return     Context The current Context instance.
55
     *
56
     * @author     Sean Kerr <[email protected]>
57
     * @since      0.9.0
58
     */
59
    final public function getContext()
60
    {
61
        return $this->context;
62
    }
63
64
    /**
65
     * Retrieve the execution container for this controller.
66
     *
67
     * @return     ExecutionContainer This controller's execution container.
68
     *
69
     * @author     David Zülke <[email protected]>
70
     * @since      0.11.0
71
     */
72
    final public function getContainer()
73
    {
74
        return $this->container;
75
    }
76
77
    /**
78
     * Retrieve the credential required to access this controller.
79
     *
80
     * @return     mixed Data that indicates the level of security for this
81
     *                   controller.
82
     *
83
     * @author     Sean Kerr <[email protected]>
84
     * @author     David Zülke <[email protected]>
85
     * @since      0.9.0
86
     */
87
    public function getCredentials()
88
    {
89
        return null;
90
    }
91
92
    /**
93
     * Execute any post-validation error application logic.
94
     *
95
     * @param      RequestDataHolder $rd The controller's request data holder.
96
     *
97
     * @return     mixed A string containing the view name associated with this
98
     *                   controller.
99
     *                   Or an array with the following indices:
100
     *                   - The parent module of the view that will be executed.
101
     *                   - The view that will be executed.
102
     *
103
     * @author     Sean Kerr <[email protected]>
104
     * @author     David Zülke <[email protected]>
105
     * @since      0.9.0
106
     */
107
    public function handleError(RequestDataHolder $rd)
0 ignored issues
show
Unused Code introduced by
The parameter $rd is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
108
    {
109
        return 'Error';
110
    }
111
112
    /**
113
     * Initialize this controller.
114
     *
115
     * @param      ExecutionContainer $container This Controller's execution container.
116
     *
117
     * @author     David Zülke <[email protected]>
118
     * @since      0.9.0
119
     */
120
    public function initialize(ExecutionContainer $container)
121
    {
122
        $this->container = $container;
123
124
        $this->context = $container->getContext();
125
    }
126
127
    /**
128
     * Indicates that this controller requires security.
129
     *
130
     * @return     bool true, if this controller requires security, otherwise false.
131
     *
132
     * @author     Sean Kerr <[email protected]>
133
     * @since      0.9.0
134
     */
135
    public function isSecure()
136
    {
137
        return false;
138
    }
139
140
    /**
141
     * Whether or not this controller is "simple", i.e. does not use validation etc.
142
     *
143
     * @return     bool true, if this controller should act in simple mode, or false.
144
     *
145
     * @author     David Zülke <[email protected]>
146
     * @since      0.11.0
147
     */
148
    public function isSimple()
149
    {
150
        return false;
151
    }
152
153
    /**
154
     * Manually register validators for this controller.
155
     *
156
     * @author     Sean Kerr <[email protected]>
157
     * @since      0.9.0
158
     */
159
    public function registerValidators()
160
    {
161
    }
162
163
    /**
164
     * Manually validate files and parameters.
165
     *
166
     * @param      RequestDataHolder $rd The controller's request data holder.
167
     *
168
     * @return     bool true, if validation completed successfully, otherwise
169
     *                  false.
170
     *
171
     * @author     Sean Kerr <[email protected]>
172
     * @author     David Zülke <[email protected]>
173
     * @since      0.9.0
174
     */
175
    public function validate(RequestDataHolder $rd)
0 ignored issues
show
Unused Code introduced by
The parameter $rd is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
176
    {
177
        return true;
178
    }
179
180
    /**
181
     * Get the default View name if this Controller doesn't serve the Request method.
182
     *
183
     * @return     mixed A string containing the view name associated with this
184
     *                   controller.
185
     *                   Or an array with the following indices:
186
     *                   - The parent module of the view that will be executed.
187
     *                   - The view that will be executed.
188
     *
189
     * @author     David Zülke <[email protected]>
190
     * @since      0.11.0
191
     */
192
    public function getDefaultViewName()
193
    {
194
        return 'Input';
195
    }
196
197
    /**
198
     * @see        AttributeHolder::clearAttributes()
199
     *
200
     * @author     David Zülke <[email protected]>
201
     * @since      0.9.0
202
     */
203
    public function clearAttributes()
204
    {
205
        $this->container->clearAttributes();
206
    }
207
208
    /**
209
     * @see        AttributeHolder::getAttribute()
210
     *
211
     * @author     David Zülke <[email protected]>
212
     * @since      0.9.0
213
     */
214
    public function &getAttribute($name, $default = null)
215
    {
216
        return $this->container->getAttribute($name, null, $default);
217
    }
218
219
    /**
220
     * @see        AttributeHolder::getAttributeNames()
221
     *
222
     * @author     David Zülke <[email protected]>
223
     * @since      0.9.0
224
     */
225
    public function getAttributeNames()
226
    {
227
        return $this->container->getAttributeNames();
228
    }
229
230
    /**
231
     * @see        AttributeHolder::getAttributes()
232
     *
233
     * @author     David Zülke <[email protected]>
234
     * @since      0.11.0
235
     */
236
    public function &getAttributes()
237
    {
238
        return $this->container->getAttributes();
239
    }
240
241
    /**
242
     * @see        AttributeHolder::hasAttribute()
243
     *
244
     * @author     David Zülke <[email protected]>
245
     * @since      0.9.0
246
     */
247
    public function hasAttribute($name)
248
    {
249
        return $this->container->hasAttribute($name);
250
    }
251
252
    /**
253
     * @see        AttributeHolder::removeAttribute()
254
     *
255
     * @author     David Zülke <[email protected]>
256
     * @since      0.9.0
257
     */
258
    public function &removeAttribute($name)
259
    {
260
        return $this->container->removeAttribute($name);
261
    }
262
263
    /**
264
     * @see        AttributeHolder::setAttribute()
265
     *
266
     * @author     David Zülke <[email protected]>
267
     * @since      0.9.0
268
     */
269
    public function setAttribute($name, $value)
270
    {
271
        $this->container->setAttribute($name, $value);
272
    }
273
274
    /**
275
     * @see        AttributeHolder::appendAttribute()
276
     *
277
     * @author     David Zülke <[email protected]>
278
     * @since      0.10.0
279
     */
280
    public function appendAttribute($name, $value)
281
    {
282
        $this->container->appendAttribute($name, $value);
283
    }
284
285
    /**
286
     * @see        AttributeHolder::setAttributeByRef()
287
     *
288
     * @author     David Zülke <[email protected]>
289
     * @since      0.9.0
290
     */
291
    public function setAttributeByRef($name, &$value)
292
    {
293
        $this->container->setAttributeByRef($name, $value);
294
    }
295
296
    /**
297
     * @see        AttributeHolder::appendAttributeByRef()
298
     *
299
     * @author     David Zülke <[email protected]>
300
     * @since      0.10.0
301
     */
302
    public function appendAttributeByRef($name, &$value)
303
    {
304
        $this->container->appendAttributeByRef($name, $value);
305
    }
306
307
    /**
308
     * @see        AttributeHolder::setAttributes()
309
     *
310
     * @author     David Zülke <[email protected]>
311
     * @since      0.9.0
312
     */
313
    public function setAttributes(array $attributes)
314
    {
315
        $this->container->setAttributes($attributes);
316
    }
317
318
    /**
319
     * @see        AttributeHolder::setAttributesByRef()
320
     *
321
     * @author     David Zülke <[email protected]>
322
     * @since      0.9.0
323
     */
324
    public function setAttributesByRef(array &$attributes)
325
    {
326
        $this->container->setAttributesByRef($attributes);
327
    }
328
}
329