Hoa central
Abstract.php
Go to the documentation of this file.
1 <?php
2 
46 import('Filter.Exception');
47 
62 abstract class Hoa_Filter_Abstract {
63 
69  protected $arguments = array();
70 
76  private $filterArguments = array();
77 
78 
79 
88  public function __construct ( Array $args = array() ) {
89 
90  $this->setFilterArguments($args);
91  }
92 
100  protected function _checkArguments ( ) {
101 
102  $needed = array();
103  $args = $this->getFilterArguments();
104 
105  foreach($this->getArguments() as $name => $label)
106  if(!isset($args[$name]))
107  $needed[] = $name . ' : ' . $label;
108 
109  if(empty($needed))
110  return true;
111 
112  $message = get_class($this) . ' needs parameters :' . "\n - " .
113  implode("\n" . ' - ', $needed);
114 
115  throw new Hoa_Filter_Exception($message, 0);
116 
117  return false;
118  }
119 
128  private function setFilterArguments ( Array $args = array() ) {
129 
130  $old = $this->filterArguments;
131  $this->filterArguments = $args;
132 
133  $this->_checkArguments();
134 
135  return $old;
136  }
137 
146  public function getFilterArgument ( $name ) {
147 
148  if( null !== $this->filterArguments[$name]
149  && !isset($this->filterArguments[$name]))
150  throw new Hoa_Filter_Exception(
151  'The argument %s does not exit.', 1, $name);
152 
153  return $this->filterArguments[$name];
154  }
155 
162  public function getFilterArguments ( ) {
163 
164  return $this->filterArguments;
165  }
166 
173  protected function getArguments ( ) {
174 
175  return $this->arguments;
176  }
177 
185  abstract public function filter ( $string = null );
186 }
getFilterArgument($name)
Definition: Abstract.php:146
setFilterArguments(Array $args=array())
Definition: Abstract.php:128
filter($string=null)
__construct(Array $args=array())
Definition: Abstract.php:88