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-09-28 10:25:05 -07: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 Merge branch '2.0' into 2.1 2012-09-21 08:34:46 +02:00
Debug Fixed Phpdoc 2012-07-28 16:07:17 +00:00
DependencyInjection fixed CS 2012-07-09 14:54:20 +02:00
Event Fixed typos 2012-07-28 22:02:29 +00:00
EventListener added a missing comment 2012-07-18 10:24:35 +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 Added Base64 encoding, decoding to MongoDBProfilerStorage 2012-09-28 10:25:05 -07:00
Tests Added Base64 encoding, decoding to MongoDBProfilerStorage 2012-09-28 10:25:05 -07: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 replaced self.version by 2.1.* in composer.json files 2012-09-10 12:53:42 +02:00
HttpKernel.php [HttpKernel] added a way to override the default response status code when handling an exception (closes #5043) 2012-07-31 10:32:57 +02:00
HttpKernelInterface.php fixed CS 2012-07-09 14:54:20 +02:00
Kernel.php bumped Symfony version to 2.1.3-DEV 2012-09-20 10:29:15 +02:00
KernelEvents.php Fixed typos 2012-07-28 22:02:29 +00: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