时间:2021-07-01 10:21:17 帮助过:22人阅读
- <br><!--?php <BR-->/** <br>* 委托模式 示例 <br>* <br>* @create_date: 2010-01-04 <br>*/ <br>class PlayList <br>{ <br>var $_songs = array(); <br>var $_object = null; <br>function PlayList($type) <br>{ <br>$object = $type."PlayListDelegation"; <br>$this->_object = new $object(); <br>} <br>function addSong($location,$title) <br>{ <br>$this->_songs[] = array("location"=>$location,"title"=>$title); <br>} <br>function getPlayList() <br>{ <br>return $this->_object->getPlayList($this->_songs); <br>} <br>} <br>class mp3PlayListDelegation <br>{ <br>function getPlayList($songs) <br>{ <br>$aResult = array(); <br>foreach($songs as $key=>$item) <br>{ <br>$path = pathinfo($item['location']); <br>if(strtolower($item['extension']) == "mp3") <br>{ <br>$aResult[] = $item; <br>} <br>} <br>return $aResult; <br>} <br>} <br>class rmvbPlayListDelegation <br>{ <br>function getPlayList($songs) <br>{ <br>$aResult = array(); <br>foreach($songs as $key=>$item) <br>{ <br>$path = pathinfo($item['location']); <br>if(strtolower($item['extension']) == "rmvb") <br>{ <br>$aResult[] = $item; <br>} <br>} <br>return $aResult; <br>} <br>} <br>$oMP3PlayList = new PlayList("mp3"); <br>$oMP3PlayList->getPlayList(); <br>$oRMVBPlayList = new PlayList("rmvb"); <br>$oRMVBPlayList->getPlayList(); <br>?>