From f4b71ed5be463fabde44b3dcc6e4f778ccde6a64 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 12 May 2021 23:03:14 +0200 Subject: [PATCH] [TwigBridge] Add `encore_entry_*_tags()` to UndefinedCallableHandler, as no-op --- .../Bridge/Twig/UndefinedCallableHandler.php | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php b/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php index 73b6fd7d80cf0..608bbaa8e30ad 100644 --- a/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php +++ b/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php @@ -13,6 +13,8 @@ use Symfony\Bundle\FullStack; use Twig\Error\SyntaxError; +use Twig\TwigFilter; +use Twig\TwigFunction; /** * @internal @@ -30,6 +32,8 @@ class UndefinedCallableHandler 'asset' => 'asset', 'asset_version' => 'asset', 'dump' => 'debug-bundle', + 'encore_entry_link_tags' => 'webpack-encore-bundle', + 'encore_entry_script_tags' => 'webpack-encore-bundle', 'expression' => 'expression-language', 'form_widget' => 'form', 'form_errors' => 'form', @@ -64,34 +68,40 @@ class UndefinedCallableHandler 'workflow' => 'enable "framework.workflows"', ]; - public static function onUndefinedFilter(string $name): bool + /** + * @return TwigFilter|false + */ + public static function onUndefinedFilter(string $name) { if (!isset(self::FILTER_COMPONENTS[$name])) { return false; } - self::onUndefined($name, 'filter', self::FILTER_COMPONENTS[$name]); - - return true; + throw new SyntaxError(self::onUndefined($name, 'filter', self::FILTER_COMPONENTS[$name])); } - public static function onUndefinedFunction(string $name): bool + /** + * @return TwigFunction|false + */ + public static function onUndefinedFunction(string $name) { if (!isset(self::FUNCTION_COMPONENTS[$name])) { return false; } - self::onUndefined($name, 'function', self::FUNCTION_COMPONENTS[$name]); + if ('webpack-encore-bundle' === self::FUNCTION_COMPONENTS[$name]) { + return new TwigFunction($name, static function () { return ''; }); + } - return true; + throw new SyntaxError(self::onUndefined($name, 'function', self::FUNCTION_COMPONENTS[$name])); } - private static function onUndefined(string $name, string $type, string $component) + private static function onUndefined(string $name, string $type, string $component): string { if (class_exists(FullStack::class) && isset(self::FULL_STACK_ENABLE[$component])) { - throw new SyntaxError(sprintf('Did you forget to %s? Unknown %s "%s".', self::FULL_STACK_ENABLE[$component], $type, $name)); + return sprintf('Did you forget to %s? Unknown %s "%s".', self::FULL_STACK_ENABLE[$component], $type, $name); } - throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown %s "%s".', $component, $type, $name)); + return sprintf('Did you forget to run "composer require symfony/%s"? Unknown %s "%s".', $component, $type, $name); } }