php设计模式 Delegation(委托模式)

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?php
/**
* 委托模式 示例
*
* @create_date: 2010-01-04
*/
class PlayList
{
var $_songs = array();
var $_object = null;
function PlayList($type)
{
$object = $type."PlayListDelegation";
$this->_object = new $object();
}
function addSong($location,$title)
{
$this->_songs[] = array("location"=>$location,"title"=>$title);
}
function getPlayList()
{
return $this->_object->getPlayList($this->_songs);
}
}
class mp3PlayListDelegation
{
function getPlayList($songs)
{
$aResult = array();
foreach($songs as $key=>$item)
{
$path = pathinfo($item['location']);
if(strtolower($item['extension']) == "mp3")
{
$aResult[] = $item;
}
}
return $aResult;
}
}
class rmvbPlayListDelegation
{
function getPlayList($songs)
{
$aResult = array();
foreach($songs as $key=>$item)
{
$path = pathinfo($item['location']);
if(strtolower($item['extension']) == "rmvb")
{
$aResult[] = $item;
}
}
return $aResult;
}
}
$oMP3PlayList = new PlayList("mp3");
$oMP3PlayList->getPlayList();
$oRMVBPlayList = new PlayList("rmvb");
$oRMVBPlayList->getPlayList();
?>

相关文章

php 图片上添加透明度渐变的效果

复制代码 代码如下:<?php ////$strimgsrc = file_get_contents("/zb_users/upload/202003/e4lf1fxwbqa.jp...

php 上传功能实例代码

1.上传表单 upload.html 复制代码 代码如下: <form enctype="multipart/form-data" action="upload.php" meth...

php select,radio和checkbox默认选择的实现方法

这是扩展yibing的select默认选择的实现方法 复制代码 代码如下: <select name="wuyeleixing" size="1"> <option &...

PHP5中的时间相差8小时的解决办法

方法1:        找到php.ini中的“;date.timezone =”这行,将“;”去掉,改成...

PHP中获取内网用户MAC地址(WINDOWS/linux)的实现代码

复制代码 代码如下: function ce_getmac() { if(PHP_OS == 'WINNT') { $return_array = array(); $temp_arra...