/** * @var string */ private $html; public function __construct(Twig_Environment $twig) { $this->twig = $twig; } public function handleGet(\Symfony\Component\HttpFoundation\Request $request) { $this->html = $this->twig->render('home.twig'); } public function __toString() { return $this->html; } } $twig = new Twig_Environment(new Twig_Loader_Filesystem('./templates')); $rl = new \RestArc\ResourceLocator(); $rl->addResource('/home/', ['text/html'], function () use($twig) { return new Homepage($twig); }); try { $response = \RestArc\Http\ResponseFactory::createFromResource($rl->handle(\Symfony\Component\HttpFoundation\Request::createFromGlobals())); } catch (\RestArc\Http\Exception\AbstractException $e) { $response = \RestArc\Http\ResponseFactory::createFromException($e); } catch (\Exception $e) { $response = \Symfony\Component\HttpFoundation\Response::create($e->getMessage(), \Symfony\Component\HttpFoundation\Response::HTTP_INTERNAL_SERVER_ERROR); } finally { $response->send(); }
public function testMethodNotAllowedResponse() { try { $this->rl->handle(Request::create('/foo', 'POST')); } catch (AbstractException $e) { $this->assertEquals(Response::HTTP_METHOD_NOT_ALLOWED, ResponseFactory::createFromException($e)->getStatusCode()); } }