接口类
<?php namespace AppInterfaces; interface ProductInterface { public function create($name); public function edit($name); }
目标类
<?php namespace AppInterfacesTargets; use AppInterfacesProductInterface; class Product implements ProductInterface { public function create($name) { // TODO: Implement create() method. echo "目标类创建"; } public function edit($name) { // TODO: Implement edit() method. echo "目标类编辑"; } }
代理类
<?php namespace AppInterfacesProxy; use AppInterfacesProductInterface; use AppInterfacesTargetsProduct; class ProductProxy implements ProductInterface { private $product; /** * ProductProxy constructor. */ public function __construct(Product $product) { $this->product = $product; } public function create($name) { // TODO: Implement create() method. echo "befare "; $this->product->create($name); echo "after "; } public function edit($name) { // TODO: Implement edit() method. echo "befare "; $this->product->edit($name); echo "after "; } }
消费者
/** * @RequestMapping(route="product/test",method={RequestMethod::GET}) */ public function test(){ $mb_obj = new AppInterfacesTargetsProduct(); $pdt_obj = new ProductProxy($mb_obj); $pdt_obj->create('张三'); }