zoukankan      html  css  js  c++  java
  • php 代理模式

    代理模式为其他对象提供一种代理以控制对这个对象的访问。

    Irequest.php

    <?php
    namespace proxy;
    
    interface Irequest{
        function sendRequest();
    }


    Request.php

    <?php
    namespace proxy;
    
    class Request{
        function sendRequest(){
            echo "send Request";
        }
    }

    RequestProxy.php

    <?php
    namespace proxy;
    
    class RequestProxy{
        private $_request;
    
        function __construct(){
            $this->_request = new Request();
        }
    
        function sendRequest(){
            $this->beforeRequest();
            echo "<br>";
            $this->_request->sendRequest();
            echo "<br>";
            $this->afterRequest();
        }
        protected function beforeRequest(){
            echo "before";
        }
        protected function afterRequest(){
            echo "after";
        }
    }


    client.php

    <?php
    namespace proxy;
    require '../autoload.php';
    $request = new RequestProxy();
    $request->sendRequest();

    autoload.php

    <?php
    spl_autoload_register(function ($class_name) {
        $file_dir = str_replace('\','/',$class_name);
        require_once $file_dir . '.php';
    });

    client.php为客户端发起请求的文件,autoload.php为自动加载类的文件

  • 相关阅读:
    BCTF赛后
    有道前端面试总结
    来更新一篇blog吧
    好久没更新了,开学新气象
    leetcode--N-Queens II
    leetcode--N-Queens
    leetcode--Scramble String
    leetcode--Maximal Rectangle
    leetcode--Distinct Subsequences
    leetcode--Sudoku Solver
  • 原文地址:https://www.cnblogs.com/changfengSven/p/7677127.html
Copyright © 2011-2022 走看看