EclipseGc

DrupalPimpleContainer.php

Feb 3rd, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Drupal\Core\DependencyInjection;
  4.  
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\RequestContext;
  7. use Drupal\Core\DrupalKernel;
  8. use Drupal\Core\Response\DrupalResponse;
  9. use Drupal\Core\Routes\DrupalRoutes;
  10.  
  11. class DrupalPimpleContainer extends \Pimple {
  12.   public function __construct() {
  13.     $container = $this;
  14.  
  15.     $this['request'] = $this->share(
  16.       function () {
  17.         return Request::createFromGlobals();
  18.       }
  19.     );
  20.  
  21.     $this['context'] = $this->share(
  22.       function ($container) {
  23.         return new RequestContext($container['request']);
  24.       }
  25.     );
  26.  
  27.     $this['router'] = $this->share(
  28.       function () {
  29.         $router = new DrupalRoutes();
  30.         return $router->getRoutes();
  31.       }
  32.     );
  33.  
  34.     $this['response'] = $this->share(
  35.       function ($container) {
  36.         return new DrupalResponse($container['context'], $container['router']);
  37.       }
  38.     );
  39.  
  40.     $this['kernel'] = $this->share(
  41.       function ($container) {
  42.         $kernel = new DrupalKernel($container['response']);
  43.         return $kernel->handle($container['request']);
  44.       }
  45.     );
  46.   }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment