Hoa central
Filter.php
Go to the documentation of this file.
1 <?php
2 
45 import('Filter.Exception');
46 
50 import('Filter.Abstract');
51 
55 import('Factory.~');
56 
71 
77  protected $filters = array();
78 
79 
88  public function addFilter ( $filters ) {
89 
90  if(!is_array($filters))
91  $filters = array($filters => array());
92 
93  foreach($filters as $filter => $arguments) {
94 
95  if(is_int($filter)) {
96 
97  $filter = $arguments;
98  $arguments = array();
99  }
100 
101  if(is_array($filter)) {
102 
103  $arguments = current($filter);
104  $filter = key($filter);
105  }
106 
107  if(!is_array($arguments))
108  $arguments = array($arguments);
109 
110  $arguments = array($arguments);
111 
112  $filter = Hoa_Factory::get('Filter', $filter, $arguments);
113 
114  if(!($filter instanceof Hoa_Filter_Abstract))
115  throw new Hoa_Filter_Exception(
116  'The filter %s does not extend Hoa_Filter_Abstract.',
117  0, get_class($filter));
118 
119  if($this->filterExists(get_class($filter)))
120  throw new Hoa_Filter_Exception(
121  'The filter %s already exists.',
122  1, get_class($filter));
123 
124  $this->filters[get_class($filter)] = $filter;
125  }
126  }
127 
135  public function filterExists ( $filter ) {
136 
137  return isset($this->filters[$filter]);
138  }
139 
146  protected function getFilters ( ) {
147 
148  return $this->filters;
149  }
150 
158  public function filter ( $string = null ) {
159 
160  foreach($this->getFilters() as $name => $filter)
161  $string = $filter->filter($string);
162 
163  return $string;
164  }
165 }
filterExists($filter)
Definition: Filter.php:135
getFilters()
Definition: Filter.php:146
addFilter($filters)
Definition: Filter.php:88
filter($string=null)
Definition: Filter.php:158