pog

http://stackoverflow.com/questions/24949055/default-value-fo

pog
Jul 19th, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. # routing.yml
  2.  
  3. app:
  4.     resource: @AppBundle/Controller/
  5.     type:     annotation
  6.     prefix:   /{_locale}
  7.     host:     "{domain}.example.com"
  8.     requirements:
  9.         _locale: "%available_locales%"
  10.         domain: "[a-z0-9]+"
  11.  
  12. # services.yml
  13.  
  14. services:
  15.     listener.pathparameters:
  16.         class: AppBundle\EventListener\PathParameters
  17.         arguments: [ @service_container ]
  18.         tags:
  19.             - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
  20.  
  21. # AppBundle\EventListener\PathParameters
  22.  
  23. <?php
  24.  
  25. namespace AppBundle\EventListener;
  26.  
  27. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  28. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  29. use Symfony\Component\HttpFoundation\Cookie;
  30. use Symfony\Component\DependencyInjection\ContainerInterface;
  31.  
  32. class PathParameters
  33. {
  34.     protected $container;
  35.  
  36.     public function __construct(ContainerInterface $container) // this is @service_container
  37.     {
  38.         $this->container = $container;
  39.     }
  40.  
  41.     public function onKernelRequest(GetResponseEvent $event)
  42.     {
  43.         $request   = $event->getRequest();
  44.         $this->container->get('router.request_context')->setParameter('domain', $request->attributes->get('domain'));
  45.     }
  46. }
Add Comment
Please, Sign In to add comment