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
Fabien Potencier 785e82f814 Merge branch '2.3' into 2.4
* 2.3:
  Revert PHPUnit version, revert APC configuration
  removed APC on the CLI for Travis as it does not work well with PHPUnit and Composer anyway
  [Security] Replace exception mocks with actual exception instances.
  Remove an unused argument.
  Use `Filesystem::chmod` instead of `chmod` when dumping file
  [Form] Added test for disabling buttons
  [Form] Added check for parent disabled status in Button form elements
  Fixes URL validator to accept single part urls
  tweaked Travis configuration to get more tests running
  fixed float comparison in unit tests for HHVM
  upgraded PHPUnit to version 4 for better HHVM support
  [Process] fixed HHVM usage on the CLI
  Fix class names in ApcUniversalClassLoader tests.
  fixed the profiler when an uncalled listener throws an exception when instantiated
  fixed CS
  Added test case for 4c6a2d15095c13b2a35751b2b2712b183be489c4
  Fixed bug in ChoiceType triggering a warning when not using utf-8
  fixed CS
  Avoid levenshtein comparison when using ContainerBuilder.

Conflicts:
	src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
	src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php
2014-04-03 07:23:50 +02:00
..
Bundle Merge branch '2.3' 2013-11-23 22:17:02 +01:00
CacheClearer fixed CS 2012-07-09 14:54:20 +02:00
CacheWarmer unify constructor initialization style throughout symfony 2013-11-11 19:40:07 +01:00
Config [HttpKernel] tweaked previous merge 2013-04-07 17:51:54 +02:00
Controller Merge branch '2.3' into 2.4 2014-03-27 15:53:17 +01:00
DataCollector Merge branch '2.4' 2014-03-26 12:51:10 +01:00
Debug fixed the profiler when an uncalled listener throws an exception when instantiated 2014-03-28 12:42:49 +01:00
DependencyInjection Merge branch '2.3' into 2.4 2014-01-05 03:10:50 +01:00
Event Merge branch '2.3' 2013-09-19 11:47:34 +02:00
EventListener Merge branch '2.4' 2014-03-03 13:53:01 +01:00
Exception Add UnprocessableEntityHttpException to HttpKernel Exceptions 2014-03-26 19:03:23 +01:00
Fragment allow null value in fragment handler 2014-01-20 07:30:15 +01:00
HttpCache Merge branch '2.3' into 2.4 2014-04-03 07:23:50 +02:00
Log Fixed the NullLogger to implement the HttpKernel interface again 2013-01-30 20:59:27 +01:00
Profiler Merge branch '2.3' into 2.4 2014-03-04 08:36:00 +01:00
Tests Merge branch '2.4' 2014-03-27 15:53:24 +01:00
.gitignore Fix gitignore 2014-03-04 18:06:29 +01:00
CHANGELOG.md [EventDispatcher][HttpKernel] Move RegisterListenersPass from HttpKernel to EventDispatcher. 2013-12-18 18:16:40 +01:00
Client.php Merge branch '2.3' into 2.4 2014-01-01 09:14:50 +01:00
composer.json updated version to 2.5 2013-11-24 21:17:07 +01:00
HttpKernel.php moved RequestStack to HttpFoundation and removed RequestContext 2013-09-08 07:38:03 +02:00
HttpKernelInterface.php fixed CS 2012-07-09 14:54:20 +02:00
Kernel.php Merge branch '2.4' 2014-03-03 13:53:01 +01:00
KernelEvents.php [HttpKernel] renamed the kernel finished event 2013-09-07 21:43:50 +02:00
KernelInterface.php Clean KernelInterface docblocks 2014-03-24 19:00:42 +01:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05: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 Replace sha1 and md5 hashing with sha256 algorithm 2013-08-31 13:25:41 +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:

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