-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFilterList.php
91 lines (84 loc) · 2.32 KB
/
FilterList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/*
* This file has its roots as part of the Mojavi package which was
* Copyright (c) 2003 Sean Kerr. It has been incorporated into this
* derivative work under the terms of the LGPL V2.1.
* (http://www.gnu.org/licenses/lgpl-2.1.html)
*/
namespace Xmf\Xadr;
/**
* A FilterList provides for registering a sequence of filters in a form that
* can be added to the FilterChain. The Controller will look for classes to
* instantiate both a global and a per-unit filter list using specific classes
* which extend FilterList:
*
* - NS\GlobalFilterList
* - NS\UNIT\Filters\UNITFilterList
*
* where NS = declared namespace, and UNIT = unit name
*
* The lists established in these classes will be used to create the FilterChain.
*
* @category Xmf\Xadr\FilterList
* @package Xmf
* @author Richard Griffith <richard@geekwright.com>
* @author Sean Kerr <skerr@mojavi.org>
* @copyright 2013-2015 XOOPS Project (http://xoops.org)
* @copyright 2003 Sean Kerr
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
* @link http://xoops.org
*/
abstract class FilterList extends ContextAware
{
/**
* An associative array of filters.
*
* @var array
*/
protected $filters = array();
/**
* initContextAware - called by ContextAware::__construct
*
* @return void
*/
protected function initContextAware()
{
$this->initialize();
}
/**
* addFilter - add a filter to the chain
*
* @param Filter $filter filter object to add to the list
* @return void
*/
protected function addFilter(Filter $filter)
{
$this->filters[] = $filter;
}
/**
* initialize - build the filter list
*
* set filters, i.e.:
*
* $this->addFilter($this->controller()->getFilter('Name'));
*
* @return void
*/
abstract protected function initialize();
/**
* Register filters.
*
* _This method should never be called manually._
*
* @param FilterChain $filterChain a FilterChain instance
*
* @return void
*/
public function registerFilters(FilterChain $filterChain)
{
// loop through filters array and register them
foreach ($this->filters as $key => $value) {
$filterChain->register($value);
}
}
}