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 |
WebLinkExtension.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 Fig\Link\GenericLinkProvider;
015 use Fig\Link\Link;
016 use Symfony\Component\HttpFoundation\RequestStack;
017 use Twig\Extension\AbstractExtension;
018 use Twig\TwigFunction;
019
020 /**
021 * Twig extension for the Symfony WebLink component.
022 *
023 * @author Kévin Dunglas <dunglas@gmail.com>
024 */
025 class WebLinkExtension extends AbstractExtension
026 {
027 private $requestStack;
028
029 public function __construct(RequestStack $requestStack)
030 {
031 $this->requestStack = $requestStack;
032 }
033
034 /**
035 * {@inheritdoc}
036 */
037 public function getFunctions()
038 {
039 return [
040 new TwigFunction('link', [$this, 'link']),
041 new TwigFunction('preload', [$this, 'preload']),
042 new TwigFunction('dns_prefetch', [$this, 'dnsPrefetch']),
043 new TwigFunction('preconnect', [$this, 'preconnect']),
044 new TwigFunction('prefetch', [$this, 'prefetch']),
045 new TwigFunction('prerender', [$this, 'prerender']),
046 ];
047 }
048
049 /**
050 * Adds a "Link" HTTP header.
051 *
052 * @param string $uri The relation URI
053 * @param string $rel The relation type (e.g. "preload", "prefetch", "prerender" or "dns-prefetch")
054 * @param array $attributes The attributes of this link (e.g. "['as' => true]", "['pr' => 0.5]")
055 *
056 * @return string The relation URI
057 */
058 public function link($uri, $rel, array $attributes = [])
059 {
060 if (!$request = $this->requestStack->getMasterRequest()) {
061 return $uri;
062 }
063
064 $link = new Link($rel, $uri);
065 foreach ($attributes as $key => $value) {
066 $link = $link->withAttribute($key, $value);
067 }
068
069 $linkProvider = $request->attributes->get('_links', new GenericLinkProvider());
070 $request->attributes->set('_links', $linkProvider->withLink($link));
071
072 return $uri;
073 }
074
075 /**
076 * Preloads a resource.
077 *
078 * @param string $uri A public path
079 * @param array $attributes The attributes of this link (e.g. "['as' => true]", "['crossorigin' => 'use-credentials']")
080 *
081 * @return string The path of the asset
082 */
083 public function preload($uri, array $attributes = [])
084 {
085 return $this->link($uri, 'preload', $attributes);
086 }
087
088 /**
089 * Resolves a resource origin as early as possible.
090 *
091 * @param string $uri A public path
092 * @param array $attributes The attributes of this link (e.g. "['as' => true]", "['pr' => 0.5]")
093 *
094 * @return string The path of the asset
095 */
096 public function dnsPrefetch($uri, array $attributes = [])
097 {
098 return $this->link($uri, 'dns-prefetch', $attributes);
099 }
100
101 /**
102 * Initiates a early connection to a resource (DNS resolution, TCP handshake, TLS negotiation).
103 *
104 * @param string $uri A public path
105 * @param array $attributes The attributes of this link (e.g. "['as' => true]", "['pr' => 0.5]")
106 *
107 * @return string The path of the asset
108 */
109 public function preconnect($uri, array $attributes = [])
110 {
111 return $this->link($uri, 'preconnect', $attributes);
112 }
113
114 /**
115 * Indicates to the client that it should prefetch this resource.
116 *
117 * @param string $uri A public path
118 * @param array $attributes The attributes of this link (e.g. "['as' => true]", "['pr' => 0.5]")
119 *
120 * @return string The path of the asset
121 */
122 public function prefetch($uri, array $attributes = [])
123 {
124 return $this->link($uri, 'prefetch', $attributes);
125 }
126
127 /**
128 * Indicates to the client that it should prerender this resource .
129 *
130 * @param string $uri A public path
131 * @param array $attributes The attributes of this link (e.g. "['as' => true]", "['pr' => 0.5]")
132 *
133 * @return string The path of the asset
134 */
135 public function prerender($uri, array $attributes = [])
136 {
137 return $this->link($uri, 'prerender', $attributes);
138 }
139 }
140