Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # routing.yml
- app:
- resource: @AppBundle/Controller/
- type: annotation
- prefix: /{_locale}
- host: "{domain}.example.com"
- requirements:
- _locale: "%available_locales%"
- domain: "[a-z0-9]+"
- # services.yml
- services:
- listener.pathparameters:
- class: AppBundle\EventListener\PathParameters
- arguments: [ @service_container ]
- tags:
- - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
- # AppBundle\EventListener\PathParameters
- <?php
- namespace AppBundle\EventListener;
- use Symfony\Component\HttpKernel\Event\GetResponseEvent;
- use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
- use Symfony\Component\HttpFoundation\Cookie;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class PathParameters
- {
- protected $container;
- public function __construct(ContainerInterface $container) // this is @service_container
- {
- $this->container = $container;
- }
- public function onKernelRequest(GetResponseEvent $event)
- {
- $request = $event->getRequest();
- $this->container->get('router.request_context')->setParameter('domain', $request->attributes->get('domain'));
- }
- }
Add Comment
Please, Sign In to add comment