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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

AppVariable.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 4.49 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Bridge\Twig;
013   
014  use Symfony\Component\HttpFoundation\Request;
015  use Symfony\Component\HttpFoundation\RequestStack;
016  use Symfony\Component\HttpFoundation\Session\Session;
017  use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
018  use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
019   
020  /**
021   * Exposes some Symfony parameters and services as an "app" global variable.
022   *
023   * @author Fabien Potencier <fabien@symfony.com>
024   */
025  class AppVariable
026  {
027      private $tokenStorage;
028      private $requestStack;
029      private $environment;
030      private $debug;
031   
032      public function setTokenStorage(TokenStorageInterface $tokenStorage)
033      {
034          $this->tokenStorage = $tokenStorage;
035      }
036   
037      public function setRequestStack(RequestStack $requestStack)
038      {
039          $this->requestStack = $requestStack;
040      }
041   
042      public function setEnvironment($environment)
043      {
044          $this->environment = $environment;
045      }
046   
047      public function setDebug($debug)
048      {
049          $this->debug = (bool) $debug;
050      }
051   
052      /**
053       * Returns the current token.
054       *
055       * @return TokenInterface|null
056       *
057       * @throws \RuntimeException When the TokenStorage is not available
058       */
059      public function getToken()
060      {
061          if (null === $tokenStorage = $this->tokenStorage) {
062              throw new \RuntimeException('The "app.token" variable is not available.');
063          }
064   
065          return $tokenStorage->getToken();
066      }
067   
068      /**
069       * Returns the current user.
070       *
071       * @return object|null
072       *
073       * @see TokenInterface::getUser()
074       */
075      public function getUser()
076      {
077          if (null === $tokenStorage = $this->tokenStorage) {
078              throw new \RuntimeException('The "app.user" variable is not available.');
079          }
080   
081          if (!$token = $tokenStorage->getToken()) {
082              return null;
083          }
084   
085          $user = $token->getUser();
086   
087          return \is_object($user) ? $user : null;
088      }
089   
090      /**
091       * Returns the current request.
092       *
093       * @return Request|null The HTTP request object
094       */
095      public function getRequest()
096      {
097          if (null === $this->requestStack) {
098              throw new \RuntimeException('The "app.request" variable is not available.');
099          }
100   
101          return $this->requestStack->getCurrentRequest();
102      }
103   
104      /**
105       * Returns the current session.
106       *
107       * @return Session|null The session
108       */
109      public function getSession()
110      {
111          if (null === $this->requestStack) {
112              throw new \RuntimeException('The "app.session" variable is not available.');
113          }
114   
115          return ($request = $this->getRequest()) ? $request->getSession() : null;
116      }
117   
118      /**
119       * Returns the current app environment.
120       *
121       * @return string The current environment string (e.g 'dev')
122       */
123      public function getEnvironment()
124      {
125          if (null === $this->environment) {
126              throw new \RuntimeException('The "app.environment" variable is not available.');
127          }
128   
129          return $this->environment;
130      }
131   
132      /**
133       * Returns the current app debug mode.
134       *
135       * @return bool The current debug mode
136       */
137      public function getDebug()
138      {
139          if (null === $this->debug) {
140              throw new \RuntimeException('The "app.debug" variable is not available.');
141          }
142   
143          return $this->debug;
144      }
145   
146      /**
147       * Returns some or all the existing flash messages:
148       *  * getFlashes() returns all the flash messages
149       *  * getFlashes('notice') returns a simple array with flash messages of that type
150       *  * getFlashes(['notice', 'error']) returns a nested array of type => messages.
151       *
152       * @return array
153       */
154      public function getFlashes($types = null)
155      {
156          try {
157              $session = $this->getSession();
158              if (null === $session) {
159                  return [];
160              }
161          } catch (\RuntimeException $e) {
162              return [];
163          }
164   
165          if (null === $types || '' === $types || [] === $types) {
166              return $session->getFlashBag()->all();
167          }
168   
169          if (\is_string($types)) {
170              return $session->getFlashBag()->get($types);
171          }
172   
173          $result = [];
174          foreach ($types as $type) {
175              $result[$type] = $session->getFlashBag()->get($type);
176          }
177   
178          return $result;
179      }
180  }
181