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 1c783f6038 Merge branch '2.2'
* 2.2: (22 commits)
  [Process] Fix regression introduced in #6620 / 880da01c49, fixes #7082
  [HttpKernel] added a unit for the previous commit (closes #7025)
  [HttpFoundation] fixed, overwritten CONTENT_TYPE
  [BrowserKit] fixed test added in the previous merge (refs #7059)
  [FrameworkBundle] tweaked reference dumper command (see #7093)
  Remove unnecessary comment and change test name
  [Config] tweaked dumper to indent multi-line info
  [HttpKernel] added some tests for previous merge
  Fix REMOTE_ADDR for cached subrequests
  [FrameworkBundle] CSRF should be on by default
  [WebProfilerBundle] removed dependency on FrameworkBundle (closes #6949)
  [HttpKernel] added error display suppression when using the ErrorHandler (if not, errors are displayed twice, refs #6254)
  [HttpFoundation] tweaked previous merge
  [HttpFoundation] Added getter for httpMethodParameterOverride state
  Create validators.lv.xlf
  [Process] Warn user with a useful message when tmpfile() failed
  [BrowserKit] added a test to make sure HTTP authentication is preserved when submitting a form
  Remove array type hint from GetResponseForControllerResultEvent::setControllerResult()
  bumped Symfony version to 2.2.0-DEV
  Revert "merged branch povilas/issue_6101 (PR #6708)"
  ...
2013-02-18 22:28:20 +01:00
..
Bundle Fixed most of the docblocks/unused namespaces 2012-12-19 08:09:49 +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 fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
Controller renamed some classes and Twig functions to more descriptive names (refs #6871) 2013-02-01 15:17:20 +01:00
DataCollector Use REQUEST_TIME_FLOAT if available. 2013-02-05 10:58:14 +01:00
Debug [HttpKernel] added error display suppression when using the ErrorHandler (if not, errors are displayed twice, refs #6254) 2013-02-15 08:54:09 +01:00
DependencyInjection moved the container aware HTTP kernel to the HttpKernel component 2013-01-10 09:21:32 +01:00
Event Remove array type hint from GetResponseForControllerResultEvent::setControllerResult() 2013-02-13 02:35:51 +01:00
EventListener exception listener, allow easier overloading of the default behavior 2013-02-08 12:43:40 +01:00
Exception Fixed most of the docblocks/unused namespaces 2012-12-19 08:09:49 +01:00
Fragment added a proper setter for the templating servicein HInclude 2013-02-10 12:34:10 +01:00
HttpCache Merge branch '2.1' into 2.2 2013-02-17 14:00:38 +01:00
Log Fixed the NullLogger to implement the HttpKernel interface again 2013-01-30 20:59:27 +01:00
Profiler Merge branch '2.1' into 2.2 2013-02-07 12:58:45 +01:00
Tests Merge branch '2.2' 2013-02-18 22:28:20 +01:00
.gitignore make it possible for bundles extensions to prepend settings into the application configuration of any Bundle 2012-12-07 10:45:48 +01:00
CHANGELOG.md renamed some classes and Twig functions to more descriptive names (refs #6871) 2013-02-01 15:17:20 +01:00
Client.php added Universal* classes in the list of deprecated classes for 3.0 2013-02-08 17:10:00 +01:00
composer.json changed dependencies to allow all 2.3 versions of the components (closes #6983) 2013-02-11 11:13:11 +01:00
HttpKernel.php Fugbix typo 2013-01-31 09:00:54 +01:00
HttpKernelInterface.php fixed CS 2012-07-09 14:54:20 +02:00
Kernel.php bumped Symfony version to 2.2.0-DEV 2013-02-11 16:24:43 +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 made usage of Composer autoloader for subtree-split unit tests 2012-11-09 14:10:06 +01: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 --dev
$ phpunit