This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/HttpKernel
2012-07-13 12:14:13 +02:00
..
Bundle [HttpKernel] tweaked a phpdoc 2012-07-10 16:40:07 +02:00
CacheClearer fixed CS 2012-07-09 14:54:20 +02:00
CacheWarmer fixed CS 2012-07-09 14:54:20 +02:00
Config fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
Controller fixed CS 2012-07-09 14:54:20 +02:00
DataCollector [HttpKernel] removed obsolete code (the status code is already taken care of in FlattenExceptiondirectly) 2012-07-13 09:19:21 +02:00
Debug [HttpKernel] fixed HTTP exception headers in ExceptionHandler 2012-07-13 12:14:13 +02:00
DependencyInjection fixed CS 2012-07-09 14:54:20 +02:00
Event Fixing email 2012-05-26 09:48:33 +02:00
EventListener [HttpKernel] avoid hidding exceptions set in exception listeners (see the Security ExceptionListener for some examples) 2012-07-13 11:25:52 +02:00
Exception [HttpKernel] moved some mis-placed logic to FlattenException 2012-07-13 09:48:10 +02:00
HttpCache fixed CS 2012-07-09 14:54:20 +02:00
Log fixed CS 2012-07-09 14:54:20 +02:00
Profiler fixed CS 2012-07-09 14:54:20 +02:00
Tests [HttpKernel] fixed HTTP exception headers in ExceptionHandler 2012-07-13 12:14:13 +02:00
.gitignore [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
CHANGELOG.md made the charset overridable (closes #2072) 2012-07-03 10:28:30 +02:00
Client.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
composer.json updated minimum PHP version to 5.3.3 2012-05-07 10:29:11 +02:00
HttpKernel.php ensured that an exception is always converted to an error response (and that we keep the HTTP status code and headers) 2012-07-13 11:55:51 +02:00
HttpKernelInterface.php fixed CS 2012-07-09 14:54:20 +02:00
Kernel.php Allow Kernel::$name to be overridden by subclasses 2012-07-11 16:13:02 +10:00
KernelEvents.php Fixing email 2012-05-26 09:48:33 +02:00
KernelInterface.php fixed CS 2012-07-09 14:54:20 +02:00
LICENSE Updated LICENSE files copyright 2012-02-22 10:10:37 +01:00
phpunit.xml.dist [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
README.md merged branch willdurand/fix-components (PR #4155) 2012-05-01 17:59:34 +02:00
TerminableInterface.php fixed CS 2012-07-09 14:54:20 +02:00

HttpKernel Component

HttpKernel provides the building blocks to create flexible and fast HTTP-based frameworks.

HttpKernelInterface is the core interface of the Symfony2 full-stack framework:

interface HttpKernelInterface
{
    /**
     * Handles a Request to convert it to a Response.
     *
     * @param  Request $request A Request instance
     *
     * @return Response A Response instance
     */
    function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
}

It takes a Request as an input and should return a Response as an output. Using this interface makes your code compatible with all frameworks using the Symfony2 components. And this will give you many cool features for free.

Creating a framework based on the Symfony2 components is really easy. Here is a very simple, but fully-featured framework based on the Symfony2 components:

$routes = new RouteCollection();
$routes->add('hello', new Route('/hello', array('_controller' =>
    function (Request $request) {
        return new Response(sprintf("Hello %s", $request->get('name')));
    }
)));

$request = Request::createFromGlobals();

$context = new RequestContext();
$context->fromRequest($request);

$matcher = new UrlMatcher($routes, $context);

$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber(new RouterListener($matcher));

$resolver = new ControllerResolver();

$kernel = new HttpKernel($dispatcher, $resolver);

$kernel->handle($request)->send();

This is all you need to create a flexible framework with the Symfony2 components.

Want to add an HTTP reverse proxy and benefit from HTTP caching and Edge Side Includes?

$kernel = new HttpKernel($dispatcher, $resolver);

$kernel = new HttpCache($kernel, new Store(__DIR__.'/cache'));

Want to functional test this small framework?

$client = new Client($kernel);
$crawler = $client->request('GET', '/hello/Fabien');

$this->assertEquals('Fabien', $crawler->filter('p > span')->text());

Want nice error pages instead of ugly PHP exceptions?

$dispatcher->addSubscriber(new ExceptionListener(function (Request $request) {
    $msg = 'Something went wrong! ('.$request->get('exception')->getMessage().')';

    return new Response($msg, 500);
}));

And that's why the simple looking HttpKernelInterface is so powerful. It gives you access to a lot of cool features, ready to be used out of the box, with no efforts.

Resources

You can run the unit tests with the following command:

phpunit

If you also want to run the unit tests that depend on other Symfony Components, install dev dependencies before running PHPUnit:

php composer.phar install --dev