1<?php
2/**
3 * CFilter class file.
4 *
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.yiiframework.com/
7 * @copyright Copyright &copy; 2008-2010 Yii Software LLC
8 * @license http://www.yiiframework.com/license/
9 */
10
11/**
12 * CFilter is the base class for all filters.
13 *
14 * A filter can be applied before and after an action is executed.
15 * It can modify the context that the action is to run or decorate the result that the
16 * action generates.
17 *
18 * Override {@link preFilter()} to specify the filtering logic that should be applied
19 * before the action, and {@link postFilter()} for filtering logic after the action.
20 *
21 * @author Qiang Xue <qiang.xue@gmail.com>
22 * @version $Id: CFilter.php 2377 2010-08-30 16:11:20Z qiang.xue $
23 * @package system.web.filters
24 * @since 1.0
25 */
26class CFilter extends CComponent implements IFilter
27{
28	/**
29	 * Performs the filtering.
30	 * The default implementation is to invoke {@link preFilter}
31	 * and {@link postFilter} which are meant to be overridden
32	 * child classes. If a child class needs to override this method,
33	 * make sure it calls <code>$filterChain->run()</code>
34	 * if the action should be executed.
35	 * @param CFilterChain the filter chain that the filter is on.
36	 */
37	public function filter($filterChain)
38	{
39		if($this->preFilter($filterChain))
40		{
41			$filterChain->run();
42			$this->postFilter($filterChain);
43		}
44	}
45
46	/**
47	 * Initializes the filter.
48	 * This method is invoked after the filter properties are initialized
49	 * and before {@link preFilter} is called.
50	 * You may override this method to include some initialization logic.
51	 * @since 1.1.4
52	 */
53	public function init()
54	{
55	}
56
57	/**
58	 * Performs the pre-action filtering.
59	 * @param CFilterChain the filter chain that the filter is on.
60	 * @return boolean whether the filtering process should continue and the action
61	 * should be executed.
62	 */
63	protected function preFilter($filterChain)
64	{
65		return true;
66	}
67
68	/**
69	 * Performs the post-action filtering.
70	 * @param CFilterChain the filter chain that the filter is on.
71	 */
72	protected function postFilter($filterChain)
73	{
74	}
75}