php 调节者模式(代码)
来源:互联网 发布:微信做宣传的软件 编辑:程序博客网 时间:2024/06/14 17:15
<?php
/**
* AbstractColleague.
*/
interface Filter
{
public function filter($value);
}
/**
* Colleague. We decide in the implementation phase
* that Colleagues should not know the next Colleague
* in the chain, resorting to a Mediator to link them together.
* This choice succesfully avoids a base abstract class
* for Filters.
* Remember that this is an example: it is not only
* Chain of Responsibility that can be alternatively implemented
* as a Mediator.
*/
class TrimFilter implements Filter
{
public function filter($value)
{
return trim($value,'/');
}
}
/**
* Colleague.
*/
class NullFilter implements Filter
{
public function filter($value)
{
return str_replace(" ",'a',$value);
}
}
/**
* Colleague.
*/
class HtmlEntitiesFilter implements Filter
{
public function filter($value)
{
return htmlentities($value);
}
}
/**
* The Mediator. We avoid referencing it from ConcreteColleagues
* and so the need for an interface. We leave the implementation
* of a bidirectional channel for the Observer pattern's example.
* This class responsibility is to store the value and coordinate
* filters computation 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 $_filters;
protected $_value;
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";
?>
/**
* AbstractColleague.
*/
interface Filter
{
public function filter($value);
}
/**
* Colleague. We decide in the implementation phase
* that Colleagues should not know the next Colleague
* in the chain, resorting to a Mediator to link them together.
* This choice succesfully avoids a base abstract class
* for Filters.
* Remember that this is an example: it is not only
* Chain of Responsibility that can be alternatively implemented
* as a Mediator.
*/
class TrimFilter implements Filter
{
public function filter($value)
{
return trim($value,'/');
}
}
/**
* Colleague.
*/
class NullFilter implements Filter
{
public function filter($value)
{
return str_replace(" ",'a',$value);
}
}
/**
* Colleague.
*/
class HtmlEntitiesFilter implements Filter
{
public function filter($value)
{
return htmlentities($value);
}
}
/**
* The Mediator. We avoid referencing it from ConcreteColleagues
* and so the need for an interface. We leave the implementation
* of a bidirectional channel for the Observer pattern's example.
* This class responsibility is to store the value and coordinate
* filters computation 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 $_filters;
protected $_value;
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";
?>
- php 调节者模式(代码)
- 相似度(参数调节代码)
- 直接命令行中执行PHP代码(PHP CLI模式)
- php 访问者模式代码学习
- eclipse中调节代码字体大小
- vs2008 自动调节代码格式
- PHP设计模式-建造者模式(Builder For PHP)
- PHP 单例模式 工厂模式 策略模式代码理解
- PHP设计模式-观察者模式(订阅者模式)
- PHP设计模式-观察者模式(订阅者模式)
- PHP设计模式-观察者模式(订阅者模式)
- PHP单例模式示例代码
- PHP各种设计模式代码示例
- PID调节(理论)
- PID调节(理论)
- 调节
- 调节
- 调节
- 无线网络加密方式对比
- ME_PURCHDOC_POSTED
- 《程序员的自我修养——链接、装载与库》
- 单例,应用程序委托和顶层数据
- mjpg-streamer和jpegsrc.v8b.tar.gc的编译
- php 调节者模式(代码)
- socket的服务器/客户端模型——时间服务器的版本演进
- 转载
- 如何隐藏system函数的窗口
- android访问本地web(不是127.0.0.1而是10.0.2.2)
- Oracle DB Server内存划分参考
- 原型设计
- java 通过反射获取泛型的类型
- Google三大论文中文版 pdf