|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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; |
| 13 | + |
| 14 | +use Twig\Error\SyntaxError; |
| 15 | + |
| 16 | +/** |
| 17 | + * @internal |
| 18 | + */ |
| 19 | +class UndefinedCallableHandler |
| 20 | +{ |
| 21 | + private static $filterComponents = array( |
| 22 | + 'humanize' => 'form', |
| 23 | + 'trans' => 'translation', |
| 24 | + 'transchoice' => 'translation', |
| 25 | + 'yaml_encode' => 'yaml', |
| 26 | + 'yaml_dump' => 'yaml', |
| 27 | + ); |
| 28 | + |
| 29 | + private static $functionComponents = array( |
| 30 | + 'asset' => 'asset', |
| 31 | + 'asset_version' => 'asset', |
| 32 | + 'dump' => 'debug-bundle', |
| 33 | + 'expression' => 'expression-language', |
| 34 | + 'form_widget' => 'form', |
| 35 | + 'form_errors' => 'form', |
| 36 | + 'form_label' => 'form', |
| 37 | + 'form_row' => 'form', |
| 38 | + 'form_rest' => 'form', |
| 39 | + 'form' => 'form', |
| 40 | + 'form_start' => 'form', |
| 41 | + 'form_end' => 'form', |
| 42 | + 'csrf_token' => 'form', |
| 43 | + 'logout_url' => 'security-http', |
| 44 | + 'logout_path' => 'security-http', |
| 45 | + 'is_granted' => 'security-core', |
| 46 | + 'link' => 'web-link', |
| 47 | + 'preload' => 'web-link', |
| 48 | + 'dns_prefetch' => 'web-link', |
| 49 | + 'preconnect' => 'web-link', |
| 50 | + 'prefetch' => 'web-link', |
| 51 | + 'prerender' => 'web-link', |
| 52 | + 'workflow_can' => 'workflow', |
| 53 | + 'workflow_transitions' => 'workflow', |
| 54 | + 'workflow_has_marked_place' => 'workflow', |
| 55 | + 'workflow_marked_places' => 'workflow', |
| 56 | + ); |
| 57 | + |
| 58 | + public static function onUndefinedFilter($name) |
| 59 | + { |
| 60 | + if (!isset(self::$filterComponents[$name])) { |
| 61 | + return false; |
| 62 | + } |
| 63 | + |
| 64 | + // Twig will append the source context to the message, so that it will end up being like "[...] Unknown filter "%s" in foo.html.twig on line 123." |
| 65 | + throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown filter "%s".', $name, self::$filterComponents[$name])); |
| 66 | + } |
| 67 | + |
| 68 | + public static function onUndefinedFunction($name) |
| 69 | + { |
| 70 | + if (!isset(self::$functionComponents[$name])) { |
| 71 | + return false; |
| 72 | + } |
| 73 | + |
| 74 | + throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown function "%s".', $name, self::$functionComponents[$name])); |
| 75 | + } |
| 76 | +} |
0 commit comments