1: <?php
2: /**
3: *
4: *
5: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6: * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7: *
8: * Licensed under The MIT License
9: * For full copyright and license information, please see the LICENSE.txt
10: * Redistributions of files must retain the above copyright notice.
11: *
12: * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13: * @link http://cakephp.org CakePHP(tm) Project
14: * @package Cake.Routing
15: * @since CakePHP(tm) v 2.2
16: * @license http://www.opensource.org/licenses/mit-license.php MIT License
17: */
18:
19: App::uses('CakeEventListener', 'Event');
20:
21: /**
22: * This abstract class represents a filter to be applied to a dispatcher cycle. It acts as as
23: * event listener with the ability to alter the request or response as needed before it is handled
24: * by a controller or after the response body has already been built.
25: *
26: * @package Cake.Routing
27: */
28: abstract class DispatcherFilter implements CakeEventListener {
29:
30: /**
31: * Default priority for all methods in this filter
32: *
33: * @var integer
34: */
35: public $priority = 10;
36:
37: /**
38: * Returns the list of events this filter listens to.
39: * Dispatcher notifies 2 different events `Dispatcher.before` and `Dispatcher.after`.
40: * By default this class will attach `preDispatch` and `postDispatch` method respectively.
41: *
42: * Override this method at will to only listen to the events you are interested in.
43: *
44: * @return array
45: */
46: public function implementedEvents() {
47: return array(
48: 'Dispatcher.beforeDispatch' => array('callable' => 'beforeDispatch', 'priority' => $this->priority),
49: 'Dispatcher.afterDispatch' => array('callable' => 'afterDispatch', 'priority' => $this->priority),
50: );
51: }
52:
53: /**
54: * Method called before the controller is instantiated and called to serve a request.
55: * If used with default priority, it will be called after the Router has parsed the
56: * URL and set the routing params into the request object.
57: *
58: * If a CakeResponse object instance is returned, it will be served at the end of the
59: * event cycle, not calling any controller as a result. This will also have the effect of
60: * not calling the after event in the dispatcher.
61: *
62: * If false is returned, the event will be stopped and no more listeners will be notified.
63: * Alternatively you can call `$event->stopPropagation()` to achieve the same result.
64: *
65: * @param CakeEvent $event container object having the `request`, `response` and `additionalParams`
66: * keys in the data property.
67: * @return CakeResponse|boolean
68: */
69: public function beforeDispatch(CakeEvent $event) {
70: }
71:
72: /**
73: * Method called after the controller served a request and generated a response.
74: * It is possible to alter the response object at this point as it is not sent to the
75: * client yet.
76: *
77: * If false is returned, the event will be stopped and no more listeners will be notified.
78: * Alternatively you can call `$event->stopPropagation()` to achieve the same result.
79: *
80: * @param CakeEvent $event container object having the `request` and `response`
81: * keys in the data property.
82: * @return mixed boolean to stop the event dispatching or null to continue
83: */
84: public function afterDispatch(CakeEvent $event) {
85: }
86: }
87: