MissingExtensionSuggestor.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Twig\Extra\TwigExtraBundle;
  11. use Twig\Error\SyntaxError;
  12. final class MissingExtensionSuggestor
  13. {
  14. public function suggestFilter(string $name): bool
  15. {
  16. if ($filter = Extensions::getFilter($name)) {
  17. throw new SyntaxError(sprintf('The "%s" filter is part of the %s, which is not installed/enabled; try running "composer require %s".', $name, $filter[0], $filter[1]));
  18. }
  19. return false;
  20. }
  21. public function suggestFunction(string $name): bool
  22. {
  23. if ($function = Extensions::getFunction($name)) {
  24. throw new SyntaxError(sprintf('The "%s" function is part of the %s, which is not installed/enabled; try running "composer require %s".', $name, $function[0], $function[1]));
  25. }
  26. return false;
  27. }
  28. public function suggestTag(string $name): bool
  29. {
  30. if ($function = Extensions::getTag($name)) {
  31. throw new SyntaxError(sprintf('The "%s" tag is part of the %s, which is not installed/enabled; try running "composer require %s".', $name, $function[0], $function[1]));
  32. }
  33. return false;
  34. }
  35. }