打赏

单例模式

单例模式

<?php
//单例模式
class Request
{
    private static $request;

    protected $method;

    protected $uriPath;

    public function __construct()
    {
    }
    private function __clone()
    {
        // TODO: Implement __clone() method.
    }

    public static function getRequest()
    {
        if (self::$request == null) {
            self::$request = new Request();
        }

        self::$request->method = $_SERVER['REQUEST_METHOD'];
        self::$request->uriPath = $_SERVER['REQUEST_URI'];
        return self::$request;
    }

    public function getMehod()
    {
        return $this->method;
    }
    public function getUriPath()
    {
        return $this->uriPath;
    }

    public function isMethod($method): bool
    {
        return $this->method === strtoupper($method);
    }
}

$request = Request::getRequest();
var_dump($request->isMethod('post'));

var_dump($request->getMehod());

var_dump($request->getUriPath());

 

posted on 2021-08-22 11:12  头大的冯冯  阅读(10)  评论(0编辑  收藏  举报

导航