Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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