Created
February 7, 2013 02:40
-
-
Save thsutton/4727973 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__.'/vendor/autoload.php'; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\Routing\Route; | |
use Symfony\Component\Routing\RouteCollection; | |
use Symfony\Component\Routing\Matcher\UrlMatcher; | |
use Symfony\Component\Routing\RequestContext; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\HttpKernel\HttpKernel; | |
use Symfony\Component\HttpKernel\Controller\ControllerResolver; | |
use Symfony\Component\EventDispatcher\EventDispatcher; | |
use Symfony\Component\HttpKernel\Debug\ExceptionHandler; | |
use Symfony\Component\HttpKernel\EventListener\ExceptionListener; | |
use Symfony\Component\HttpKernel\EventListener\RouterListener; | |
new ControllerResolver(); | |
$routes = new RouteCollection(); | |
$routes->add( | |
'say', | |
new Route('/say/{message}/{name}', | |
array( | |
'message' => 'hello', | |
'name' => 'world', | |
'_controller' => | |
function(Request $request){ | |
Twig_Autoloader::register(); | |
$loader = new Twig_Loader_Filesystem(__DIR__); | |
$twig = new Twig_Environment($loader); | |
return new Response( | |
$twig->render('index.html.twig', array( | |
'message' => $request->get('message'), | |
'name' => $request->get('name') | |
)) | |
); | |
} | |
) | |
) | |
); | |
$request = Request::createFromGlobals(); | |
$dispatcher = new EventDispatcher(); | |
$urlMatcher = new UrlMatcher($routes, new RequestContext()); | |
$dispatcher->addSubscriber(new RouterListener($urlMatcher)); | |
$exceptionHandler = function($exception) { | |
$handler = new ExceptionHandler(); | |
return $handler->createResponse($exception); | |
}; | |
$dispatcher->addSubscriber(new ExceptionListener($exceptionHandler)); | |
$kernel = new HttpKernel($dispatcher, new ControllerResolver()); | |
$kernel->handle($request)->send(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"symfony/http-foundation": "2.1.*", | |
"symfony/http-kernel": "2.1.*", | |
"symfony/routing": "2.1.*", | |
"twig/twig": "1.*" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'layout.html.twig' %} | |
{% block title 'A message for ' ~ name %} | |
{% block content %} | |
<h1>{{ message }} {{ name }}</h1> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>{% block title '' %}</title> | |
</head> | |
<body> | |
{% block content '' %} | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment