PHP代理模式的实现

小天天天天    PHP    999+ 次    2017-05-08 03:22:31


代理模式是把难复制的、占资源多的、远程速度慢的对象。各自对应一个代理对象,被代理后进行本地的操作。

<?php

class Printer{
    public function doPrint(){
        echo "I can Print!";
    }
}

class TakePhoto{
    private $printer;
    public function __construct($printer){
        $this->printer=$printer;
    }
    public function doPhoto(){
        echo "I can takePhoto";
    }
    public function __call($method,$args="") {
        if (method_exists($this->printer, $method)) {
            $this->printer->$method($args);
        }
    }
    
}

$p=new Printer();
$t=new TakePhoto($p);
$t->doPrint();



如果你觉得本篇文章对您有帮助,请打赏作者

上一篇: htmlpurifier过滤UEditer提交的数据,避免XSS

下一篇: 理解Javascript的对象

最新评论

暂无评论

热门文章

最新评论

网站数据

网站文章数:481

今日UV/PV/IP:20/24/20

昨日UV/PV/IP:11/14 /10

TOP