Beispiel #1
0
 public function dispatch(Request $request, Context $context)
 {
     $handler = $context->getHandler();
     if (!isset($this->handlers[$handler])) {
         throw new Exception();
     }
     return $context($this->handlers[$handler], $request);
 }
 function it_dispatches_with_declared_action(ControllerFactoryInterface $factory, Context $context, ControllerInterface $controller, Response $response)
 {
     $request = Request::create('/', 'OPTIONS');
     $context->getHandler()->willReturn('test');
     $context->getVariables()->willReturn(['foo']);
     $factory->build('test')->willReturn($controller);
     $controller->options($request, ['foo'])->willReturn($response);
     $this->dispatch($request, $context)->shouldReturn($response);
 }
Beispiel #3
0
 public function dispatch(Request $request, Context $context)
 {
     $handler = $context->getHandler();
     list($handler, $action) = $this->extractComponents($handler, $request);
     $controller = $this->getFactory()->build($handler);
     $variables = $context->getVariables();
     $method = $request->getMethod();
     if (!method_exists($controller, $method)) {
         throw new BadMethodCallException("Method {$method} not found on handler {$handler}");
     }
     return call_user_func([$controller, strtolower($method)], $request, $variables);
 }