[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/symfony/twig-bridge/Extension/ -> AssetExtension.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Bridge\Twig\Extension;
  13  
  14  use Symfony\Component\Asset\Packages;
  15  use Twig\Extension\AbstractExtension;
  16  use Twig\TwigFunction;
  17  
  18  /**
  19   * Twig extension for the Symfony Asset component.
  20   *
  21   * @author Fabien Potencier <fabien@symfony.com>
  22   */
  23  class AssetExtension extends AbstractExtension
  24  {
  25      private $packages;
  26  
  27      public function __construct(Packages $packages)
  28      {
  29          $this->packages = $packages;
  30      }
  31  
  32      /**
  33       * {@inheritdoc}
  34       */
  35      public function getFunctions()
  36      {
  37          return [
  38              new TwigFunction('asset', [$this, 'getAssetUrl']),
  39              new TwigFunction('asset_version', [$this, 'getAssetVersion']),
  40          ];
  41      }
  42  
  43      /**
  44       * Returns the public url/path of an asset.
  45       *
  46       * If the package used to generate the path is an instance of
  47       * UrlPackage, you will always get a URL and not a path.
  48       *
  49       * @param string $path        A public path
  50       * @param string $packageName The name of the asset package to use
  51       *
  52       * @return string The public path of the asset
  53       */
  54      public function getAssetUrl($path, $packageName = null)
  55      {
  56          return $this->packages->getUrl($path, $packageName);
  57      }
  58  
  59      /**
  60       * Returns the version of an asset.
  61       *
  62       * @param string $path        A public path
  63       * @param string $packageName The name of the asset package to use
  64       *
  65       * @return string The asset version
  66       */
  67      public function getAssetVersion($path, $packageName = null)
  68      {
  69          return $this->packages->getVersion($path, $packageName);
  70      }
  71  
  72      /**
  73       * Returns the name of the extension.
  74       *
  75       * @return string The extension name
  76       */
  77      public function getName()
  78      {
  79          return 'asset';
  80      }
  81  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1