Skip to content

Instantly share code, notes, and snippets.

@rodrigoSyscop
Created March 3, 2018 14:12
Show Gist options
  • Save rodrigoSyscop/e0f9d0cc33a79928753ff1400c8900f3 to your computer and use it in GitHub Desktop.
Save rodrigoSyscop/e0f9d0cc33a79928753ff1400c8900f3 to your computer and use it in GitHub Desktop.
framework/web/front.php
<?php //framework/web/front.php
require_once __DIR__.'/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing;
$request = Request::createFromGlobals();
$routes = include __DIR__.'/../src/app.php';
$context = new Routing\RequestContext();
$context->fromRequest($request);
$matcher = new Routing\Matcher\UrlMatcher($routes, $context);
try {
extract($matcher->match($request->getPathInfo()), EXTR_SKIP);
ob_start();
include sprintf(__DIR__.'/../src/pages/%s.php', $_route);
$response = new Response(ob_get_clean());
} catch (Routing\Exception\ResourceNotFoundException $exception) {
$response = new Response('Not Found', 404);
} catch (Exception $exception) {
$response = new Response('An error ocurred', 500);
}
$response->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment