EclipseGc

router.inc

Feb 14th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2.  
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing;
  6. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  7. use Drupal\Core\DrupalContainer;
  8.  
  9. /**
  10.  * Execute the page callback associated with given request.
  11.  *
  12.  * @param Request $request
  13.  *   The Symfony Request object used to determine what will be executed.
  14.  * @return Response
  15.  *   A Symfony Response object describing the response to deliver to the client.
  16.  */
  17. function router_execute_request(Request $request) {
  18.  
  19.   try {
  20.     $parameters = new ParameterBag();
  21.     $parameters->set('request', $request);
  22.    
  23.     $container = new DrupalContainer($parameters);
  24.     $request->attributes->add($container->get('matcher')->match($request->getPathInfo()));
  25.     return $container->get('kernel')->handle($request);
  26.   }
  27.   catch (Routing\Exception\ResourceNotFoundException $e) {
  28.     $response = new Response('Not Found', 404);
  29.   }
  30.   //catch (Exception $e) {
  31.   //  $response = new Response('An error occurred', 500);
  32.   //}
  33.  
  34.   return $response;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment