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
2013-12-12 11:08:12 -05:00
..
Bundle CS fix 2013-11-17 14:39:12 +01:00
CacheClearer fixed CS 2012-07-09 14:54:20 +02:00
CacheWarmer fixed CS 2012-07-09 14:54:20 +02:00
Config [HttpKernel] tweaked previous merge 2013-04-07 17:51:54 +02:00
Controller [HttpKernel] allowed any callable to be returned by ControllerResolver::createController 2013-04-20 22:13:18 +02:00
DataCollector [HttpKernel] fixed memory limit display in MemoryDataCollector 2013-10-28 15:46:04 +01:00
Debug allow TraceableEventDispatcher to reuse event instance in nested events 2013-12-12 11:08:12 -05:00
DependencyInjection Merge branch '2.2' into 2.3 2013-10-09 22:51:36 +02:00
Event Fix some annotates 2013-09-19 11:36:05 +02:00
EventListener Revert "merged branch Tobion/flattenexception (PR #9111)" 2013-09-30 11:54:26 +02:00
Exception [Debug] added the component (closes #6828, closes #6834, closes #7330) 2013-04-07 18:19:05 +02:00
Fragment Merge branch '2.2' into 2.3 2013-09-19 11:45:20 +02:00
HttpCache fixed CS 2013-10-04 10:27:42 +02:00
Log Fixed the NullLogger to implement the HttpKernel interface again 2013-01-30 20:59:27 +01:00
Profiler Merge branch '2.2' into 2.3 2013-10-30 09:28:22 +01:00
Tests allow TraceableEventDispatcher to reuse event instance in nested events 2013-12-12 11:08:12 -05:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md Pass exceptions from the ExceptionListener to Monolog 2013-05-10 11:42:12 +02:00
Client.php Merge branch '2.2' into 2.3 2013-09-29 21:41:41 +02:00
composer.json fixed typo 2013-08-02 23:24:57 +02:00
HttpKernel.php fixed CS 2013-07-01 14:24:43 +02:00
HttpKernelInterface.php fixed CS 2012-07-09 14:54:20 +02:00
Kernel.php minor #9678 [HttpKernel] use static late binding when dumping out container (tgabi333) 2013-12-05 08:46:04 +01:00
KernelEvents.php Fixed typos 2012-07-28 22:02:29 +00:00
KernelInterface.php CS Fixes - Replaced "array of type" by "Type[]" in PHPDoc block 2012-11-19 13:58:52 +01:00
LICENSE updated license year 2013-01-04 17:59:43 +01:00
phpunit.xml.dist made usage of Composer autoloader for subtree-split unit tests 2012-11-09 14:10:06 +01:00
README.md updated the composer install command to reflect changes in Composer 2013-09-18 09:27:26 +02:00
TerminableInterface.php fixed CS 2012-07-09 14:54:20 +02:00
UriSigner.php tweaked previous commit 2013-02-01 22:56:52 +01: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:

$ cd path/to/Symfony/Component/HttpKernel/
$ composer.phar install
$ phpunit