Example #1
0
 /**
  * 路由参数有效性检查
  * @access private
  * @param array     $option 路由参数
  * @param Request   $request Request对象
  * @return bool
  */
 private static function checkOption($option, $request)
 {
     // 请求类型检测
     if (isset($option['method']) && is_string($option['method']) && false === stripos($option['method'], $request->method()) || !empty($option['ajax']) && !$request->isAjax() || !empty($option['pjax']) && !$request->isPjax() || isset($option['ext']) && false === stripos($option['ext'], $request->ext()) || isset($option['deny_ext']) && false !== stripos($option['deny_ext'], $request->ext()) || isset($option['domain']) && !in_array($option['domain'], [$_SERVER['HTTP_HOST'], self::$subDomain]) || !empty($option['https']) && !$request->isSsl() || !empty($option['before_behavior']) && false === Hook::exec($option['before_behavior']) || !empty($option['callback']) && is_callable($option['callback']) && false === call_user_func($option['callback'])) {
         return false;
     }
     return true;
 }
Example #2
0
 public function testmethod()
 {
     $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'DELETE';
     $request = new Request();
     $this->assertEquals('DELETE', $request->method());
     $this->assertEquals('GET', $request->method(true));
     Config::set('var_method', '_method');
     $_POST['_method'] = 'POST';
     $request = new Request();
     $this->assertEquals('POST', $request->method());
     $this->assertEquals('GET', $request->method(true));
     $this->assertTrue($request->isPost());
     $this->assertFalse($request->isGet());
     $this->assertFalse($request->isPut());
     $this->assertFalse($request->isDelete());
     $this->assertFalse($request->isHead());
     $this->assertFalse($request->isPatch());
     $this->assertFalse($request->isOptions());
 }