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

AssetExtension.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 4.73 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\Extension;
013   
014  use Symfony\Component\Asset\Packages;
015  use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
016   
017  /**
018   * Twig extension for the Symfony Asset component.
019   *
020   * @author Fabien Potencier <fabien@symfony.com>
021   */
022  class AssetExtension extends \Twig_Extension
023  {
024      private $packages;
025      private $foundationExtension;
026   
027      /**
028       * Passing an HttpFoundationExtension instance as a second argument must not be relied on
029       * as it's only there to maintain BC with older Symfony version. It will be removed in 3.0.
030       */
031      public function __construct(Packages $packages, HttpFoundationExtension $foundationExtension = null)
032      {
033          $this->packages = $packages;
034          $this->foundationExtension = $foundationExtension;
035      }
036   
037      /**
038       * {@inheritdoc}
039       */
040      public function getFunctions()
041      {
042          return array(
043              new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')),
044              new \Twig_SimpleFunction('asset_version', array($this, 'getAssetVersion')),
045              new \Twig_SimpleFunction('assets_version', array($this, 'getAssetsVersion'), array('deprecated' => true, 'alternative' => 'asset_version')),
046          );
047      }
048   
049      /**
050       * Returns the public url/path of an asset.
051       *
052       * If the package used to generate the path is an instance of
053       * UrlPackage, you will always get a URL and not a path.
054       *
055       * @param string $path        A public path
056       * @param string $packageName The name of the asset package to use
057       *
058       * @return string The public path of the asset
059       */
060      public function getAssetUrl($path, $packageName = null, $absolute = false, $version = null)
061      {
062          // BC layer to be removed in 3.0
063          if (2 < $count = func_num_args()) {
064              @trigger_error('Generating absolute URLs with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0. Please use absolute_url() instead.', E_USER_DEPRECATED);
065              if (4 === $count) {
066                  @trigger_error('Forcing a version with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
067              }
068   
069              $args = func_get_args();
070   
071              return $this->getLegacyAssetUrl($path, $packageName, $args[2], isset($args[3]) ? $args[3] : null);
072          }
073   
074          return $this->packages->getUrl($path, $packageName);
075      }
076   
077      /**
078       * Returns the version of an asset.
079       *
080       * @param string $path        A public path
081       * @param string $packageName The name of the asset package to use
082       *
083       * @return string The asset version
084       */
085      public function getAssetVersion($path, $packageName = null)
086      {
087          return $this->packages->getVersion($path, $packageName);
088      }
089   
090      public function getAssetsVersion($packageName = null)
091      {
092          @trigger_error('The Twig assets_version() function was deprecated in 2.7 and will be removed in 3.0. Please use asset_version() instead.', E_USER_DEPRECATED);
093   
094          return $this->packages->getVersion('/', $packageName);
095      }
096   
097      private function getLegacyAssetUrl($path, $packageName = null, $absolute = false, $version = null)
098      {
099          if ($version) {
100              $package = $this->packages->getPackage($packageName);
101   
102              $v = new \ReflectionProperty('Symfony\Component\Asset\Package', 'versionStrategy');
103              $v->setAccessible(true);
104   
105              $currentVersionStrategy = $v->getValue($package);
106   
107              if (property_exists($currentVersionStrategy, 'format')) {
108                  $f = new \ReflectionProperty($currentVersionStrategy, 'format');
109                  $f->setAccessible(true);
110   
111                  $format = $f->getValue($currentVersionStrategy);
112   
113                  $v->setValue($package, new StaticVersionStrategy($version, $format));
114              } else {
115                  $v->setValue($package, new StaticVersionStrategy($version));
116              }
117          }
118   
119          try {
120              $url = $this->packages->getUrl($path, $packageName);
121          } catch (\Exception $e) {
122              if ($version) {
123                  $v->setValue($package, $currentVersionStrategy);
124              }
125   
126              throw $e;
127          }
128   
129          if ($version) {
130              $v->setValue($package, $currentVersionStrategy);
131          }
132   
133          if ($absolute) {
134              return $this->foundationExtension->generateAbsoluteUrl($url);
135          }
136   
137          return $url;
138      }
139   
140      /**
141       * Returns the name of the extension.
142       *
143       * @return string The extension name
144       */
145      public function getName()
146      {
147          return 'asset';
148      }
149  }
150