Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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: 09.10.2024, 12:54 - Dateigröße: 4.41 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\SecurityContext;
019  use Symfony\Component\DependencyInjection\ContainerInterface;
020   
021  /**
022   * Exposes some Symfony parameters and services as an "app" global variable.
023   *
024   * @author Fabien Potencier <fabien@symfony.com>
025   */
026  class AppVariable
027  {
028      private $container;
029      private $tokenStorage;
030      private $requestStack;
031      private $environment;
032      private $debug;
033   
034      /**
035       * @deprecated since version 2.7, to be removed in 3.0.
036       */
037      public function setContainer(ContainerInterface $container)
038      {
039          $this->container = $container;
040      }
041   
042      public function setTokenStorage(TokenStorageInterface $tokenStorage)
043      {
044          $this->tokenStorage = $tokenStorage;
045      }
046   
047      public function setRequestStack(RequestStack $requestStack)
048      {
049          $this->requestStack = $requestStack;
050      }
051   
052      public function setEnvironment($environment)
053      {
054          $this->environment = $environment;
055      }
056   
057      public function setDebug($debug)
058      {
059          $this->debug = (bool) $debug;
060      }
061   
062      /**
063       * Returns the security context service.
064       *
065       * @deprecated since version 2.6, to be removed in 3.0.
066       *
067       * @return SecurityContext|null The security context
068       */
069      public function getSecurity()
070      {
071          @trigger_error('The "app.security" variable is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED);
072   
073          if (null === $this->container) {
074              throw new \RuntimeException('The "app.security" variable is not available.');
075          }
076   
077          if ($this->container->has('security.context')) {
078              return $this->container->get('security.context');
079          }
080      }
081   
082      /**
083       * Returns the current user.
084       *
085       * @return mixed
086       *
087       * @see TokenInterface::getUser()
088       */
089      public function getUser()
090      {
091          if (null === $this->tokenStorage) {
092              if (null === $this->container) {
093                  throw new \RuntimeException('The "app.user" variable is not available.');
094              } elseif (!$this->container->has('security.context')) {
095                  return;
096              }
097   
098              $this->tokenStorage = $this->container->get('security.context');
099          }
100   
101          if (!$token = $this->tokenStorage->getToken()) {
102              return;
103          }
104   
105          $user = $token->getUser();
106          if (is_object($user)) {
107              return $user;
108          }
109      }
110   
111      /**
112       * Returns the current request.
113       *
114       * @return Request|null The HTTP request object
115       */
116      public function getRequest()
117      {
118          if (null === $this->requestStack) {
119              if (null === $this->container) {
120                  throw new \RuntimeException('The "app.request" variable is not available.');
121              }
122   
123              $this->requestStack = $this->container->get('request_stack');
124          }
125   
126          return $this->requestStack->getCurrentRequest();
127      }
128   
129      /**
130       * Returns the current session.
131       *
132       * @return Session|null The session
133       */
134      public function getSession()
135      {
136          if (null === $this->requestStack && null === $this->container) {
137              throw new \RuntimeException('The "app.session" variable is not available.');
138          }
139   
140          if ($request = $this->getRequest()) {
141              return $request->getSession();
142          }
143      }
144   
145      /**
146       * Returns the current app environment.
147       *
148       * @return string The current environment string (e.g 'dev')
149       */
150      public function getEnvironment()
151      {
152          if (null === $this->environment) {
153              throw new \RuntimeException('The "app.environment" variable is not available.');
154          }
155   
156          return $this->environment;
157      }
158   
159      /**
160       * Returns the current app debug mode.
161       *
162       * @return bool The current debug mode
163       */
164      public function getDebug()
165      {
166          if (null === $this->debug) {
167              throw new \RuntimeException('The "app.debug" variable is not available.');
168          }
169   
170          return $this->debug;
171      }
172  }
173