۱ علی طباطبایی
تمرین پیاده سازی دیسپچ خطای 405
جامعه پی اچ پی ایجاد شده در ۰۴ بهمن ۱۴۰۰
   public function run()
    {
        #405 : invalid request method
        if($this->isInvalidRequest($this->request))
                $this->dispatch405();
        #------------------------------
    }
    #------------------------------
    private function isInvalidRequest(Request $request ):bool
    {
        foreach($this->routes as $route)
        {
            if(!in_array( $request->method() , $route["method"]) and $request->uri() === $route["uri"])
                    return true;
        }        
        return false;
    }
    #------------------------------
    private function dispatch405():void
    {
        header("HTTP/1.0 405 Method Not Allowed");
        die("invalid request method");
    }
    #------------------------------

مرسی

مهدی ۲۴ مرداد ۱۴۰۱، ۲۲:۵۷