Skip to content

Commit 0d6cfe9

Browse files
[TwigBridge] Add encore_entry_*_tags() to UndefinedCallableHandler, as no-op
1 parent 218a1ad commit 0d6cfe9

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

UndefinedCallableHandler.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Bundle\FullStack;
1515
use Twig\Error\SyntaxError;
16+
use Twig\TwigFilter;
17+
use Twig\TwigFunction;
1618

1719
/**
1820
* @internal
@@ -30,6 +32,8 @@ class UndefinedCallableHandler
3032
'asset' => 'asset',
3133
'asset_version' => 'asset',
3234
'dump' => 'debug-bundle',
35+
'encore_entry_link_tags' => 'webpack-encore-bundle',
36+
'encore_entry_script_tags' => 'webpack-encore-bundle',
3337
'expression' => 'expression-language',
3438
'form_widget' => 'form',
3539
'form_errors' => 'form',
@@ -64,34 +68,40 @@ class UndefinedCallableHandler
6468
'workflow' => 'enable "framework.workflows"',
6569
];
6670

67-
public static function onUndefinedFilter(string $name): bool
71+
/**
72+
* @return TwigFilter|false
73+
*/
74+
public static function onUndefinedFilter(string $name)
6875
{
6976
if (!isset(self::FILTER_COMPONENTS[$name])) {
7077
return false;
7178
}
7279

73-
self::onUndefined($name, 'filter', self::FILTER_COMPONENTS[$name]);
74-
75-
return true;
80+
throw new SyntaxError(self::onUndefined($name, 'filter', self::FILTER_COMPONENTS[$name]));
7681
}
7782

78-
public static function onUndefinedFunction(string $name): bool
83+
/**
84+
* @return TwigFunction|false
85+
*/
86+
public static function onUndefinedFunction(string $name)
7987
{
8088
if (!isset(self::FUNCTION_COMPONENTS[$name])) {
8189
return false;
8290
}
8391

84-
self::onUndefined($name, 'function', self::FUNCTION_COMPONENTS[$name]);
92+
if ('webpack-encore-bundle' === self::FUNCTION_COMPONENTS[$name]) {
93+
return new TwigFunction($name, static function () { return ''; });
94+
}
8595

86-
return true;
96+
throw new SyntaxError(self::onUndefined($name, 'function', self::FUNCTION_COMPONENTS[$name]));
8797
}
8898

89-
private static function onUndefined(string $name, string $type, string $component)
99+
private static function onUndefined(string $name, string $type, string $component): string
90100
{
91101
if (class_exists(FullStack::class) && isset(self::FULL_STACK_ENABLE[$component])) {
92-
throw new SyntaxError(sprintf('Did you forget to %s? Unknown %s "%s".', self::FULL_STACK_ENABLE[$component], $type, $name));
102+
return sprintf('Did you forget to %s? Unknown %s "%s".', self::FULL_STACK_ENABLE[$component], $type, $name);
93103
}
94104

95-
throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown %s "%s".', $component, $type, $name));
105+
return sprintf('Did you forget to run "composer require symfony/%s"? Unknown %s "%s".', $component, $type, $name);
96106
}
97107
}

0 commit comments

Comments
 (0)