<?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(), 200);
}

$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 $e) {
    $response = new Response('Not found', 404);
}catch(Exception $e){
    $response = new Response($e->getMessage(), 500);
}

$response->send();
<?php

require_once __DIR__."/../vendor/autoload.php";

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing;
use Symfony\Component\HttpKernel;
use Scarlett;

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(), 200);
}

$request = Request::createFromGlobals();
$routes = include __DIR__."/../src/app.php";

$context = new Routing\RequestContext();
$context->fromRequest($request);
$matcher = new Routing\Matcher\UrlMatcher($routes, $context);
$resolver = new HttpKernel\Controller\ControllerResolver();

$scarlett = new Scarlett\Framework($matcher, $resolver);
$response = $scarlett->handle($request);

$response->send();
Refactor code to use HttpKernel and a new Framework class
Refactor code to use HttpKernel and a new Framework class
