TwigNodeProvider.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Bridge\Twig\Tests\NodeVisitor;
  11. use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
  12. use Symfony\Bridge\Twig\Node\TransNode;
  13. use Twig\Node\BodyNode;
  14. use Twig\Node\Expression\ArrayExpression;
  15. use Twig\Node\Expression\ConstantExpression;
  16. use Twig\Node\Expression\FilterExpression;
  17. use Twig\Node\ModuleNode;
  18. use Twig\Node\Node;
  19. use Twig\Source;
  20. class TwigNodeProvider
  21. {
  22. public static function getModule($content)
  23. {
  24. return new ModuleNode(
  25. new ConstantExpression($content, 0),
  26. null,
  27. new ArrayExpression(array(), 0),
  28. new ArrayExpression(array(), 0),
  29. new ArrayExpression(array(), 0),
  30. null,
  31. new Source('', '')
  32. );
  33. }
  34. public static function getTransFilter($message, $domain = null, $arguments = null)
  35. {
  36. if (!$arguments) {
  37. $arguments = $domain ? array(
  38. new ArrayExpression(array(), 0),
  39. new ConstantExpression($domain, 0),
  40. ) : array();
  41. }
  42. return new FilterExpression(
  43. new ConstantExpression($message, 0),
  44. new ConstantExpression('trans', 0),
  45. new Node($arguments),
  46. 0
  47. );
  48. }
  49. public static function getTransChoiceFilter($message, $domain = null, $arguments = null)
  50. {
  51. if (!$arguments) {
  52. $arguments = $domain ? array(
  53. new ConstantExpression(0, 0),
  54. new ArrayExpression(array(), 0),
  55. new ConstantExpression($domain, 0),
  56. ) : array();
  57. }
  58. return new FilterExpression(
  59. new ConstantExpression($message, 0),
  60. new ConstantExpression('transchoice', 0),
  61. new Node($arguments),
  62. 0
  63. );
  64. }
  65. public static function getTransTag($message, $domain = null)
  66. {
  67. return new TransNode(
  68. new BodyNode(array(), array('data' => $message)),
  69. $domain ? new ConstantExpression($domain, 0) : null
  70. );
  71. }
  72. public static function getTransDefaultDomainTag($domain)
  73. {
  74. return new TransDefaultDomainNode(
  75. new ConstantExpression($domain, 0)
  76. );
  77. }
  78. }