vendor/symfony/webpack-encore-bundle/src/Twig/EntryFilesTwigExtension.php line 58

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony WebpackEncoreBundle package.
  4.  * (c) Fabien Potencier <fabien@symfony.com>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Symfony\WebpackEncoreBundle\Twig;
  9. use Psr\Container\ContainerInterface;
  10. use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
  11. use Symfony\WebpackEncoreBundle\Asset\TagRenderer;
  12. use Twig\Extension\AbstractExtension;
  13. use Twig\TwigFunction;
  14. final class EntryFilesTwigExtension extends AbstractExtension
  15. {
  16.     private $container;
  17.     public function __construct(ContainerInterface $container)
  18.     {
  19.         $this->container $container;
  20.     }
  21.     public function getFunctions()
  22.     {
  23.         return [
  24.             new TwigFunction('encore_entry_js_files', [$this'getWebpackJsFiles']),
  25.             new TwigFunction('encore_entry_css_files', [$this'getWebpackCssFiles']),
  26.             new TwigFunction('encore_entry_script_tags', [$this'renderWebpackScriptTags'], ['is_safe' => ['html']]),
  27.             new TwigFunction('encore_entry_link_tags', [$this'renderWebpackLinkTags'], ['is_safe' => ['html']]),
  28.         ];
  29.     }
  30.     public function getWebpackJsFiles(string $entryNamestring $entrypointName '_default'): array
  31.     {
  32.         return $this->getEntrypointLookup($entrypointName)
  33.             ->getJavaScriptFiles($entryName);
  34.     }
  35.     public function getWebpackCssFiles(string $entryNamestring $entrypointName '_default'): array
  36.     {
  37.         return $this->getEntrypointLookup($entrypointName)
  38.             ->getCssFiles($entryName);
  39.     }
  40.     public function renderWebpackScriptTags(string $entryNamestring $packageName nullstring $entrypointName '_default'): string
  41.     {
  42.         return $this->getTagRenderer()
  43.             ->renderWebpackScriptTags($entryName$packageName$entrypointName);
  44.     }
  45.     public function renderWebpackLinkTags(string $entryNamestring $packageName nullstring $entrypointName '_default'): string
  46.     {
  47.         return $this->getTagRenderer()
  48.             ->renderWebpackLinkTags($entryName$packageName$entrypointName);
  49.     }
  50.     private function getEntrypointLookup(string $entrypointName): EntrypointLookupInterface
  51.     {
  52.         return $this->container->get('webpack_encore.entrypoint_lookup_collection')
  53.             ->getEntrypointLookup($entrypointName);
  54.     }
  55.     private function getTagRenderer(): TagRenderer
  56.     {
  57.         return $this->container->get('webpack_encore.tag_renderer');
  58.     }
  59. }