Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
LocaleListener.php
01 <?php
02
03 /*
04 * This file is part of the Symfony package.
05 *
06 * (c) Fabien Potencier <fabien@symfony.com>
07 *
08 * For the full copyright and license information, please view the LICENSE
09 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\HttpKernel\EventListener;
13
14 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15 use Symfony\Component\HttpFoundation\Request;
16 use Symfony\Component\HttpFoundation\RequestStack;
17 use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
18 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
19 use Symfony\Component\HttpKernel\KernelEvents;
20 use Symfony\Component\Routing\RequestContextAwareInterface;
21
22 /**
23 * Initializes the locale based on the current request.
24 *
25 * @author Fabien Potencier <fabien@symfony.com>
26 */
27 class LocaleListener implements EventSubscriberInterface
28 {
29 private $router;
30 private $defaultLocale;
31 private $requestStack;
32
33 /**
34 * @param RequestStack $requestStack A RequestStack instance
35 * @param string $defaultLocale The default locale
36 * @param RequestContextAwareInterface|null $router The router
37 */
38 public function __construct(RequestStack $requestStack, $defaultLocale = 'en', RequestContextAwareInterface $router = null)
39 {
40 $this->defaultLocale = $defaultLocale;
41 $this->requestStack = $requestStack;
42 $this->router = $router;
43 }
44
45 public function onKernelRequest(GetResponseEvent $event)
46 {
47 $request = $event->getRequest();
48 $request->setDefaultLocale($this->defaultLocale);
49
50 $this->setLocale($request);
51 $this->setRouterContext($request);
52 }
53
54 public function onKernelFinishRequest(FinishRequestEvent $event)
55 {
56 if (null !== $parentRequest = $this->requestStack->getParentRequest()) {
57 $this->setRouterContext($parentRequest);
58 }
59 }
60
61 private function setLocale(Request $request)
62 {
63 if ($locale = $request->attributes->get('_locale')) {
64 $request->setLocale($locale);
65 }
66 }
67
68 private function setRouterContext(Request $request)
69 {
70 if (null !== $this->router) {
71 $this->router->getContext()->setParameter('_locale', $request->getLocale());
72 }
73 }
74
75 public static function getSubscribedEvents()
76 {
77 return [
78 // must be registered after the Router to have access to the _locale
79 KernelEvents::REQUEST => [['onKernelRequest', 16]],
80 KernelEvents::FINISH_REQUEST => [['onKernelFinishRequest', 0]],
81 ];
82 }
83 }
84