getMethod() public method

This overrides the parent functionality to ensure the method is never empty; if no method is present, it returns 'GET'.
public getMethod ( ) : string
return string
Exemplo n.º 1
0
 public function __invoke(Go $message)
 {
     $actions = $this->actions;
     $dispatcher = \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r) use($actions) {
         foreach ($actions as $action) {
             if ($action->getMatcher() instanceof Route == false) {
                 continue;
             }
             $route = $action->getMatcher();
             $r->addRoute($route->method, $route->uriTemplate, function ($variables = []) use($action) {
                 // TODO: Extract (post) variables from request and insert into action some way easy to consume
                 // URI Variables = parameter
                 // Get Variables = parameter
                 // POST Variables = entity object added to parameters
                 $action->handle($variables);
             });
         }
     });
     $uri = (string) $this->request->getUri()->getPath();
     $method = $this->request->getMethod();
     $routeInfo = $dispatcher->dispatch($method, $uri);
     switch ($routeInfo[0]) {
         case \FastRoute\Dispatcher::NOT_FOUND:
             // TODO: Use a more specialized exception
             throw new \Exception('No action could be found to deal with uri "' . $uri . '" and method "' . $method . '"');
         case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
             $allowedMethods = $routeInfo[1];
             // TODO: Use a more specialized exception
             throw new \Exception('The method "' . $method . '" is not allowed with uri "' . $uri . '". The following are allowed ' . 'methods: ' . implode($allowedMethods));
         case \FastRoute\Dispatcher::FOUND:
             list(, $handler, $vars) = $routeInfo;
             $handler($vars);
             break;
     }
 }
Exemplo n.º 2
0
 public function testUsesProvidedConstructorArguments()
 {
     $server = ['foo' => 'bar', 'baz' => 'bat'];
     $server['server'] = true;
     $files = ['files' => new UploadedFile('php://temp', 0, 0)];
     $uri = new Uri('http://example.com');
     $method = 'POST';
     $headers = ['host' => ['example.com']];
     $request = new ServerRequest($server, $files, $uri, $method, 'php://memory', $headers);
     $this->assertEquals($server, $request->getServerParams());
     $this->assertEquals($files, $request->getUploadedFiles());
     $this->assertSame($uri, $request->getUri());
     $this->assertEquals($method, $request->getMethod());
     $this->assertEquals($headers, $request->getHeaders());
     $body = $request->getBody();
     $r = new ReflectionProperty($body, 'stream');
     $r->setAccessible(true);
     $stream = $r->getValue($body);
     $this->assertEquals('php://memory', $stream);
 }