omputation when they have to be applied to the value. * Filtering responsibilities are obviously a concern of * the Colleagues, which are Filter implementations. */ class InputElement { protected
PHP设计模式之调解者模式的深入解析_网学
public function addFilter(Filter $filter) { $this->_filters[] = $filter; return $this; }
public function setValue($value) { $this->_value = $this->_filter($value); }
protected function _filter($value) { foreach ($this->_filters as $filter) { $value = $filter->filter($value); } return $value; }
public function getValue() { return $this->_value; } }
$input = new InputElement(); $input->addFilter(new NullFilter()) ->addFilter(new TrimFilter()) ->addFilter(new HtmlEntitiesFilter()); $input->setValue('' You should use the <h1>-<h6> tags for your headings.''); echo $input->getValue(), "\n"; </PRE> <PRE></PRE>