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
Nicolas Grekas 7185d50649 Merge branch '2.6' into 2.7
* 2.6: (24 commits)
  [Form] fixed a maxlength overring on a guessing
  [Debug] Show only unique class candidates
  [SecurityBundle] Firewall providers building - code cleaning
  [Filesystem] symlink use RealPath instead LinkTarget
  [DependencyInjection] Remove duplicate  declaration in PhpDumper
  terminals are not interactive on Travis
  Revert "[DependencyInjection] backport perf optim"
  [WebProfiler] Tweaked ajax requests toolbar css reset
  [WebProfilerBundle] replaced pattern to path attribute in routes definitions.
  fix phpdoc's alignment
  Fix missing addExpressionLanguageProvider (used by service container to add expression providers)
  Fixed the AuthenticationProviderInterface alignment
  Fixed the proxy-manager version constraint
  Fix missing space in label_attr
  fix DumpDataCollectorTest after CS changes
  avoid risky tests
  Fixed typo in SecurityContext PHPDoc
  [FrameworkBundle][Template name] avoid  error message for the shortcut notation.
  [DependencyInjection] perf optim: call dirname() at most 5x
  [DependencyInjection] backport perf optim
  ...
2014-12-12 17:23: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.5 2014-12-02 21:15:53 +01:00
Config [Config] fix filelocator with empty name 2014-10-13 20:50:59 +02:00
Controller Docblock fixes 2014-11-30 13:33:44 +00:00
DataCollector Merge branch '2.5' into 2.6 2014-12-05 13:00:15 +01:00
Debug Docblock fixes 2014-11-30 13:33:44 +00:00
DependencyInjection [Hackday] [2.7] Add a deprecation note about RegisterListenersPass 2014-11-29 15:25:32 +01:00
Event CS fixes 2014-12-04 20:26:11 +00:00
EventListener [2.6] CS Fixes And Removed An Unused Import 2014-12-07 19:23:39 +01:00
Exception Merge branch '2.6' into 2.7 2014-12-08 09:43:57 +01:00
Fragment Merge branch '2.5' into 2.6 2014-12-02 21:19:20 +01:00
HttpCache [2.6] CS Fixes And Removed An Unused Import 2014-12-07 19:23:39 +01:00
Log Merge branch '2.6' into 2.7 2014-12-02 21:19:50 +01:00
Profiler Merge branch '2.3' into 2.5 2014-12-02 21:15:53 +01:00
Tests Merge branch '2.5' into 2.6 2014-12-12 17:21:40 +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 updated version to 2.7 2014-11-10 19:00:54 +01:00
HttpKernel.php Merge branch '2.5' into 2.6 2014-12-02 21:19:20 +01:00
HttpKernelInterface.php Docblock fixes 2014-11-30 13:33:44 +00:00
Kernel.php [HttpKernel] Add deprecation log for Kernel::isClassInActiveBundle() 2014-12-07 19:58:47 +01:00
KernelEvents.php Merge branch '2.3' into 2.5 2014-11-16 18:28:00 +01:00
KernelInterface.php Merge branch '2.5' into 2.6 2014-12-02 21:19:20 +01:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05:00
phpunit.xml.dist Adjust error_reporting to allow deprecation messages for 3.0 2014-11-29 13:40:43 +01:00
README.md Docblock fixes 2014-11-30 13:33:44 +00:00
TerminableInterface.php fixed CS 2012-07-09 14:54:20 +02:00
UriSigner.php Merge branch '2.3' into 2.5 2014-12-02 21:15:53 +01: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