Created
February 11, 2016 00:16
-
-
Save gondo/1ec08a4d471e4f5e8c0b to your computer and use it in GitHub Desktop.
DB router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/AppBundle/EventListener/RequestListener.php | |
namespace AppBundle\EventListener; | |
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; | |
class RequestListener | |
{ | |
public function onKernelRequest(GetResponseEvent $event) | |
{ | |
// priklad: /vyrobce/produkt | |
$url = $event->getRequest()->getPathInfo(); | |
$urlParts = explode('/', $url); | |
$action = $urlParts[2]; | |
switch ($urlParts[1]) { | |
case 'vyrobce': | |
$controller = 'AppBundle\VyrobceController::' . $action . 'Action'; | |
break; | |
default: | |
$controller = 'Default'; | |
} | |
$request->attributes->set('_controller', $controller); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/config/services.yml | |
services: | |
app.request_listener: | |
class: AppBundle\EventListener\RequestListener | |
tags: | |
- { name: kernel.event_listener, event: kernel.request, priority: 33 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment