Skip to content

Instantly share code, notes, and snippets.

@rodrigoSyscop
Created March 10, 2018 17:33
Show Gist options
  • Save rodrigoSyscop/1727f88185ba34998fc30eb1b2cf720c to your computer and use it in GitHub Desktop.
Save rodrigoSyscop/1727f88185ba34998fc30eb1b2cf720c 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;
function render_template($request)
{
extract($request->attributes->all(), EXTR_SKIP);
ob_start();
include sprintf(__DIR__.'/../src/pages/%s.php', $_route);
return new Response(ob_get_clean());
}
$request = Request::createFromGlobals();
$routes = include __DIR__.'/../src/app.php';
$context = new Routing\RequestContext();
$context->fromRequest($request);
$matcher = new Routing\Matcher\UrlMatcher($routes, $context);
try {
$request->attributes->add($matcher->match($request->getPathInfo()));
$response = call_user_func($request->attributes->get('_controller'), $request);
} catch (Routing\Exception\ResourceNotFoundException $exception) {
$response = new Response('Not Found', 404);
} catch (Exception $exception) {
$response = new Response('An error occurred', 500);
}
$response->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment