Example #1
0
 /**
  * Sets all fields on this request object to the globals from PHP
  * 
  * NOTE: Requests are intended to be immutable - please use this only to construct new requests
  * 
  * @return  void
  */
 protected function createFromGlobals()
 {
     if (php_sapi_name() === 'cli') {
         throw new InvalidStateException('Requests can not be instantiated from globals in CLI mode');
     }
     $method = HttpMethod::memberByKey($_SERVER['REQUEST_METHOD'], false);
     $uri = strtok($_SERVER['REQUEST_URI'], '?');
     $host = $_SERVER['HTTP_HOST'];
     $headers = getallheaders();
     $this->create($method, $uri, $host, $headers, $_COOKIE, $_GET, $_POST);
 }
Example #2
0
 public function testRoutingRequest()
 {
     $request = new Request(HttpMethod::POST(), '/test', 'example.com', [], [], [], ['test' => 'test']);
     $called = false;
     $this->router->post('', '/test', function (Request $request) use(&$called) {
         $this->assertEquals('test', $request->input->get('test'));
         $called = true;
     });
     $this->router->routeRequestToAction($request);
     $this->assertTrue($called);
 }
Example #3
0
 public function testIsJson()
 {
     $this->assertFalse($this->request->is_json);
     $request = new ExampleRequest(HttpMethod::POST(), '/test', 'example.com', ['Accept' => 'application/json']);
     $this->assertTrue($request->is_json);
 }
Example #4
0
 public function delete($alias, $route, callable $action)
 {
     $this->addRoute(HttpMethod::DELETE(), $alias, $route, $action);
 }
Example #5
0
 public function testAllMethodsExist()
 {
     $this->assertEmpty(array_diff(['OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT'], array_keys(HttpMethod::members())));
 }