zoukankan      html  css  js  c++  java
  • AOP-动态代理

    目标类

    <?php
    
    
    namespace app	argets;
    
    
    class Goods
    {
        public function create($name){
            echo "目标类创建:{$name}";
        }
    
        public function edit($name){
            echo "目标类编辑:{$name}";
        }
    }
    

      代理类

    namespace appproxy;
    
    
    class GoodsProxy
    {
        private $obj ;
    
        /**
         * GoodsProxy constructor.
         * @param $obj
         */
        public function __construct($class)
        {
            $this->obj = new $class();
        }
    
        public function __call($name, $arguments)
        {
            // TODO: Implement __call() method.
            $reflection = new ReflectionClass($this->obj);
            if($method = $reflection->getMethod($name)){
                if($method->isPublic() && !$method->isAbstract()){
                    $method->invoke($this->obj,$arguments[0]);
                }
            }
        }
    
    }
    

     消费者

    public function hello()
        {
            //** @var Goods $proxy */
            /*$proxy = new ProductProxy(new Product());
            $proxy->create("张三");*/
            /** @var Goods $proxy */
            $proxy = new GoodsProxy(Goods::class);
            $proxy->create("张三");
            $proxy->edit("张三2");
        }
    

      

     

  • 相关阅读:
    python 列表、元组、字典总结
    python 字典
    python 元组
    python 列表
    JMeter的作用域与执行顺序
    JMeter第一个实战
    JMeter录制的两种方法
    JMeter常用功能
    初识jmeter2
    handler的拒绝策略:
  • 原文地址:https://www.cnblogs.com/finnlee/p/15057316.html
Copyright © 2011-2022 走看看