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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
HttpFoundationExtension.php
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\Extension;
013
014 use Symfony\Component\HttpFoundation\RequestStack;
015 use Symfony\Component\HttpFoundation\Request;
016 use Symfony\Component\Routing\RequestContext;
017
018 /**
019 * Twig extension for the Symfony HttpFoundation component.
020 *
021 * @author Fabien Potencier <fabien@symfony.com>
022 */
023 class HttpFoundationExtension extends \Twig_Extension
024 {
025 private $requestStack;
026 private $requestContext;
027
028 public function __construct(RequestStack $requestStack, RequestContext $requestContext = null)
029 {
030 $this->requestStack = $requestStack;
031 $this->requestContext = $requestContext;
032 }
033
034 /**
035 * {@inheritdoc}
036 */
037 public function getFunctions()
038 {
039 return array(
040 new \Twig_SimpleFunction('absolute_url', array($this, 'generateAbsoluteUrl')),
041 new \Twig_SimpleFunction('relative_path', array($this, 'generateRelativePath')),
042 );
043 }
044
045 /**
046 * Returns the absolute URL for the given absolute or relative path.
047 *
048 * This method returns the path unchanged if no request is available.
049 *
050 * @param string $path The path
051 *
052 * @return string The absolute URL
053 *
054 * @see Request::getUriForPath()
055 */
056 public function generateAbsoluteUrl($path)
057 {
058 if (false !== strpos($path, '://') || '//' === substr($path, 0, 2)) {
059 return $path;
060 }
061
062 if (!$request = $this->requestStack->getMasterRequest()) {
063 if (null !== $this->requestContext && '' !== $host = $this->requestContext->getHost()) {
064 $scheme = $this->requestContext->getScheme();
065 $port = '';
066
067 if ('http' === $scheme && 80 != $this->requestContext->getHttpPort()) {
068 $port = ':'.$this->requestContext->getHttpPort();
069 } elseif ('https' === $scheme && 443 != $this->requestContext->getHttpsPort()) {
070 $port = ':'.$this->requestContext->getHttpsPort();
071 }
072
073 if ('/' !== $path[0]) {
074 $path = rtrim($this->requestContext->getBaseUrl(), '/').'/'.$path;
075 }
076
077 return $scheme.'://'.$host.$port.$path;
078 }
079
080 return $path;
081 }
082
083 if (!$path || '/' !== $path[0]) {
084 $prefix = $request->getPathInfo();
085 $last = strlen($prefix) - 1;
086 if ($last !== $pos = strrpos($prefix, '/')) {
087 $prefix = substr($prefix, 0, $pos).'/';
088 }
089
090 return $request->getUriForPath($prefix.$path);
091 }
092
093 return $request->getSchemeAndHttpHost().$path;
094 }
095
096 /**
097 * Returns a relative path based on the current Request.
098 *
099 * This method returns the path unchanged if no request is available.
100 *
101 * @param string $path The path
102 *
103 * @return string The relative path
104 *
105 * @see Request::getRelativeUriForPath()
106 */
107 public function generateRelativePath($path)
108 {
109 if (false !== strpos($path, '://') || '//' === substr($path, 0, 2)) {
110 return $path;
111 }
112
113 if (!$request = $this->requestStack->getMasterRequest()) {
114 return $path;
115 }
116
117 return $request->getRelativeUriForPath($path);
118 }
119
120 /**
121 * Returns the name of the extension.
122 *
123 * @return string The extension name
124 */
125 public function getName()
126 {
127 return 'request';
128 }
129 }
130