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
2014-11-28 16:59:01 +01:00
..
Bundle New php library structure made easier 2014-09-24 12:42:02 +02:00
CacheClearer made {@inheritdoc} annotations consistent across the board 2014-04-16 09:04:20 +02:00
CacheWarmer Merge branch '2.3' into 2.4 2014-07-15 16:07:10 +02:00
Config [Config] fix filelocator with empty name 2014-10-13 20:50:59 +02:00
Controller feature #12022 [HttpKernel] Extract method to instantiate controller in ControllerResolver (danharper) 2014-09-25 08:41:43 +02:00
DataCollector [HttpKernel] fix parse error in DumpDataCollector 2014-11-18 12:05:34 +01:00
Debug Remove aligned '=>' and '=' 2014-10-26 08:30:58 +01:00
DependencyInjection Merge branch '2.4' 2014-04-16 10:08:40 +02:00
Event fixed types in phpdocs 2014-04-16 12:34:42 +02:00
EventListener [RFC] [DebugBundle] [HttpKernel] Avoid using container as dependency for DumpListener 2014-11-27 17:54:39 +01:00
Exception Merge branch '2.4' 2014-04-16 12:36:21 +02:00
Fragment Merge branch '2.5' into 2.6 2014-11-20 14:24:23 +01:00
HttpCache Merge branch '2.5' 2014-10-26 08:46:28 +01:00
Log fixed types in phpdocs 2014-04-16 12:30:19 +02:00
Profiler Merge branch '2.3' into 2.5 2014-10-26 08:41:27 +01:00
Tests [RFC] [DebugBundle] [HttpKernel] Avoid using container as dependency for DumpListener 2014-11-27 17:54:39 +01:00
.gitignore Fix gitignore 2014-03-04 18:06:29 +01:00
CHANGELOG.md #11652 [HttpKernel] Remove unused method Kernel::isClassInActiveBundle 2014-09-08 21:56:05 +02:00
Client.php Merge branch '2.3' into 2.4 2014-05-21 17:50:42 +02:00
composer.json fixed composer.json 2014-10-04 08:12:37 +02:00
HttpKernel.php [HttpKernel] Change exception message in case no controller found 2014-08-30 09:41:24 +02:00
HttpKernelInterface.php made phpdoc types consistent with those defined in Hack 2014-04-15 07:41:45 +02:00
Kernel.php updated VERSION for 2.6.0 2014-11-28 16:59:01 +01:00
KernelEvents.php Merge branch '2.3' into 2.5 2014-11-16 18:28:00 +01:00
KernelInterface.php #11652 [HttpKernel] Remove unused method Kernel::isClassInActiveBundle 2014-09-08 21:56:05 +02:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05:00
phpunit.xml.dist removed defaults from PHPUnit configuration 2014-07-07 12:13:42 +02:00
README.md Rename Symfony2 to Symfony 2014-11-24 15:09:11 +01:00
TerminableInterface.php fixed CS 2012-07-09 14:54:20 +02:00
UriSigner.php Merge branch '2.3' into 2.4 2014-04-16 12:34:31 +02:00

HttpKernel Component

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

HttpKernelInterface is the core interface of the Symfony 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 Symfony components. And this will give you many cool features for free.

Creating a framework based on the Symfony components is really easy. Here is a very simple, but fully-featured framework based on the Symfony 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 Symfony 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