Responsive Menu - Version 3.1.25

Version Description

(14th Dec 2019) = * Fix: Sub Menus -> Text Alignment Option does not work * Fix: Trigger Icon Position * Fix: Trigger Icon Border CSS code * Fix: Menu Text goes under Trigger Icon

Download this release

Release Info

Developer expresstech
Plugin Icon 128x128 Responsive Menu
Version 3.1.25
Comparing to
See all releases

Code changes from version 3.1.24 to 3.1.25

Files changed (271) hide show
  1. public/css/app.css.twig +48 -4
  2. public/img/banner.jpg +0 -0
  3. public/img/banner.png +0 -0
  4. readme.txt +11 -5
  5. responsive-menu.php +33 -4
  6. vendor/composer/autoload_files.php +10 -0
  7. vendor/symfony/polyfill-ctype/Ctype.php +227 -0
  8. vendor/symfony/polyfill-ctype/LICENSE +19 -0
  9. vendor/symfony/polyfill-ctype/README.md +12 -0
  10. vendor/symfony/polyfill-ctype/bootstrap.php +26 -0
  11. vendor/symfony/polyfill-ctype/composer.json +34 -0
  12. vendor/twig/twig/.gitignore +5 -0
  13. vendor/twig/twig/doc/filters/filter.rst +58 -0
  14. vendor/twig/twig/doc/filters/map.rst +38 -0
  15. vendor/twig/twig/doc/filters/reduce.rst +33 -0
  16. vendor/twig/twig/doc/filters/spaceless.rst +65 -0
  17. vendor/twig/twig/doc/tags/apply.rst +23 -0
  18. vendor/twig/twig/doc/tags/deprecated.rst +30 -0
  19. vendor/twig/twig/drupal_test.sh +51 -0
  20. vendor/twig/twig/ext/twig/.gitignore +30 -0
  21. vendor/twig/twig/lib/Twig/Node/Deprecated.php +11 -0
  22. vendor/twig/twig/lib/Twig/Profiler/Dumper/Base.php +11 -0
  23. vendor/twig/twig/lib/Twig/TokenParser/Deprecated.php +11 -0
  24. vendor/twig/twig/src/Cache/CacheInterface.php +60 -0
  25. vendor/twig/twig/src/Cache/FilesystemCache.php +93 -0
  26. vendor/twig/twig/src/Cache/NullCache.php +42 -0
  27. vendor/twig/twig/src/Compiler.php +288 -0
  28. vendor/twig/twig/src/Environment.php +1638 -0
  29. vendor/twig/twig/src/Error/Error.php +325 -0
  30. vendor/twig/twig/src/Error/LoaderError.php +23 -0
  31. vendor/twig/twig/src/Error/RuntimeError.php +24 -0
  32. vendor/twig/twig/src/Error/SyntaxError.php +57 -0
  33. vendor/twig/twig/src/ExpressionParser.php +834 -0
  34. vendor/twig/twig/src/Extension/AbstractExtension.php +72 -0
  35. vendor/twig/twig/src/Extension/CoreExtension.php +1724 -0
  36. vendor/twig/twig/src/Extension/DebugExtension.php +76 -0
  37. vendor/twig/twig/src/Extension/EscaperExtension.php +120 -0
  38. vendor/twig/twig/src/Extension/ExtensionInterface.php +101 -0
  39. vendor/twig/twig/src/Extension/GlobalsInterface.php +26 -0
  40. vendor/twig/twig/src/Extension/InitRuntimeInterface.php +26 -0
  41. vendor/twig/twig/src/Extension/OptimizerExtension.php +39 -0
  42. vendor/twig/twig/src/Extension/ProfilerExtension.php +53 -0
  43. vendor/twig/twig/src/Extension/RuntimeExtensionInterface.php +19 -0
  44. vendor/twig/twig/src/Extension/SandboxExtension.php +109 -0
  45. vendor/twig/twig/src/Extension/StagingExtension.php +117 -0
  46. vendor/twig/twig/src/Extension/StringLoaderExtension.php +54 -0
  47. vendor/twig/twig/src/FileExtensionEscapingStrategy.php +62 -0
  48. vendor/twig/twig/src/Lexer.php +534 -0
  49. vendor/twig/twig/src/Loader/ArrayLoader.php +102 -0
  50. vendor/twig/twig/src/Loader/ChainLoader.php +164 -0
  51. vendor/twig/twig/src/Loader/ExistsLoaderInterface.php +33 -0
  52. vendor/twig/twig/src/Loader/FilesystemLoader.php +323 -0
  53. vendor/twig/twig/src/Loader/LoaderInterface.php +61 -0
  54. vendor/twig/twig/src/Loader/SourceContextLoaderInterface.php +38 -0
  55. vendor/twig/twig/src/Markup.php +41 -0
  56. vendor/twig/twig/src/Node/AutoEscapeNode.php +40 -0
  57. vendor/twig/twig/src/Node/BlockNode.php +45 -0
  58. vendor/twig/twig/src/Node/BlockReferenceNode.php +38 -0
  59. vendor/twig/twig/src/Node/BodyNode.php +23 -0
  60. vendor/twig/twig/src/Node/CheckSecurityNode.php +85 -0
  61. vendor/twig/twig/src/Node/CheckToStringNode.php +42 -0
  62. vendor/twig/twig/src/Node/DeprecatedNode.php +55 -0
  63. vendor/twig/twig/src/Node/DoNode.php +40 -0
  64. vendor/twig/twig/src/Node/EmbedNode.php +52 -0
  65. vendor/twig/twig/src/Node/Expression/AbstractExpression.php +26 -0
  66. vendor/twig/twig/src/Node/Expression/ArrayExpression.php +88 -0
  67. vendor/twig/twig/src/Node/Expression/ArrowFunctionExpression.php +64 -0
  68. vendor/twig/twig/src/Node/Expression/AssignNameExpression.php +29 -0
  69. vendor/twig/twig/src/Node/Expression/Binary/AbstractBinary.php +43 -0
  70. vendor/twig/twig/src/Node/Expression/Binary/AddBinary.php +25 -0
  71. vendor/twig/twig/src/Node/Expression/Binary/AndBinary.php +25 -0
  72. vendor/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php +25 -0
  73. vendor/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php +25 -0
  74. vendor/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php +25 -0
  75. vendor/twig/twig/src/Node/Expression/Binary/ConcatBinary.php +25 -0
  76. vendor/twig/twig/src/Node/Expression/Binary/DivBinary.php +25 -0
  77. vendor/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php +37 -0
  78. vendor/twig/twig/src/Node/Expression/Binary/EqualBinary.php +24 -0
  79. vendor/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php +31 -0
  80. vendor/twig/twig/src/Node/Expression/Binary/GreaterBinary.php +24 -0
  81. vendor/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php +24 -0
  82. vendor/twig/twig/src/Node/Expression/Binary/InBinary.php +35 -0
  83. vendor/twig/twig/src/Node/Expression/Binary/LessBinary.php +24 -0
  84. vendor/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php +24 -0
  85. vendor/twig/twig/src/Node/Expression/Binary/MatchesBinary.php +35 -0
  86. vendor/twig/twig/src/Node/Expression/Binary/ModBinary.php +25 -0
  87. vendor/twig/twig/src/Node/Expression/Binary/MulBinary.php +25 -0
  88. vendor/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php +24 -0
  89. vendor/twig/twig/src/Node/Expression/Binary/NotInBinary.php +35 -0
  90. vendor/twig/twig/src/Node/Expression/Binary/OrBinary.php +25 -0
  91. vendor/twig/twig/src/Node/Expression/Binary/PowerBinary.php +39 -0
  92. vendor/twig/twig/src/Node/Expression/Binary/RangeBinary.php +35 -0
  93. vendor/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php +37 -0
  94. vendor/twig/twig/src/Node/Expression/Binary/SubBinary.php +25 -0
  95. vendor/twig/twig/src/Node/Expression/BlockReferenceExpression.php +98 -0
  96. vendor/twig/twig/src/Node/Expression/CallExpression.php +305 -0
  97. vendor/twig/twig/src/Node/Expression/ConditionalExpression.php +38 -0
  98. vendor/twig/twig/src/Node/Expression/ConstantExpression.php +30 -0
  99. vendor/twig/twig/src/Node/Expression/Filter/DefaultFilter.php +54 -0
  100. vendor/twig/twig/src/Node/Expression/FilterExpression.php +47 -0
  101. vendor/twig/twig/src/Node/Expression/FunctionExpression.php +51 -0
  102. vendor/twig/twig/src/Node/Expression/GetAttrExpression.php +80 -0
  103. vendor/twig/twig/src/Node/Expression/InlinePrint.php +35 -0
  104. vendor/twig/twig/src/Node/Expression/MethodCallExpression.php +48 -0
  105. vendor/twig/twig/src/Node/Expression/NameExpression.php +119 -0
  106. vendor/twig/twig/src/Node/Expression/NullCoalesceExpression.php +58 -0
  107. vendor/twig/twig/src/Node/Expression/ParentExpression.php +48 -0
  108. vendor/twig/twig/src/Node/Expression/TempNameExpression.php +33 -0
  109. vendor/twig/twig/src/Node/Expression/Test/ConstantTest.php +51 -0
  110. vendor/twig/twig/src/Node/Expression/Test/DefinedTest.php +71 -0
  111. vendor/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php +38 -0
  112. vendor/twig/twig/src/Node/Expression/Test/EvenTest.php +37 -0
  113. vendor/twig/twig/src/Node/Expression/Test/NullTest.php +36 -0
  114. vendor/twig/twig/src/Node/Expression/Test/OddTest.php +37 -0
  115. vendor/twig/twig/src/Node/Expression/Test/SameasTest.php +36 -0
  116. vendor/twig/twig/src/Node/Expression/TestExpression.php +51 -0
  117. vendor/twig/twig/src/Node/Expression/Unary/AbstractUnary.php +35 -0
  118. vendor/twig/twig/src/Node/Expression/Unary/NegUnary.php +25 -0
  119. vendor/twig/twig/src/Node/Expression/Unary/NotUnary.php +25 -0
  120. vendor/twig/twig/src/Node/Expression/Unary/PosUnary.php +25 -0
  121. vendor/twig/twig/src/Node/FlushNode.php +37 -0
  122. vendor/twig/twig/src/Node/ForLoopNode.php +56 -0
  123. vendor/twig/twig/src/Node/ForNode.php +119 -0
  124. vendor/twig/twig/src/Node/IfNode.php +72 -0
  125. vendor/twig/twig/src/Node/ImportNode.php +57 -0
  126. vendor/twig/twig/src/Node/IncludeNode.php +108 -0
  127. vendor/twig/twig/src/Node/MacroNode.php +136 -0
  128. vendor/twig/twig/src/Node/ModuleNode.php +492 -0
  129. vendor/twig/twig/src/Node/Node.php +274 -0
  130. vendor/twig/twig/src/Node/NodeCaptureInterface.php +23 -0
  131. vendor/twig/twig/src/Node/NodeOutputInterface.php +23 -0
  132. vendor/twig/twig/src/Node/PrintNode.php +41 -0
  133. vendor/twig/twig/src/Node/SandboxNode.php +47 -0
  134. vendor/twig/twig/src/Node/SandboxedPrintNode.php +69 -0
  135. vendor/twig/twig/src/Node/SetNode.php +107 -0
  136. vendor/twig/twig/src/Node/SetTempNode.php +44 -0
  137. vendor/twig/twig/src/Node/SpacelessNode.php +47 -0
  138. vendor/twig/twig/src/Node/TextNode.php +40 -0
  139. vendor/twig/twig/src/Node/WithNode.php +72 -0
  140. vendor/twig/twig/src/NodeTraverser.php +89 -0
  141. vendor/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php +59 -0
  142. vendor/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php +209 -0
  143. vendor/twig/twig/src/NodeVisitor/NodeVisitorInterface.php +50 -0
  144. vendor/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php +273 -0
  145. vendor/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php +164 -0
  146. vendor/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php +137 -0
  147. vendor/twig/twig/src/Parser.php +439 -0
  148. vendor/twig/twig/src/Profiler/Dumper/BaseDumper.php +65 -0
  149. vendor/twig/twig/src/Profiler/Dumper/BlackfireDumper.php +76 -0
  150. vendor/twig/twig/src/Profiler/Dumper/HtmlDumper.php +51 -0
  151. vendor/twig/twig/src/Profiler/Dumper/TextDumper.php +39 -0
  152. vendor/twig/twig/src/Profiler/Node/EnterProfileNode.php +44 -0
  153. vendor/twig/twig/src/Profiler/Node/LeaveProfileNode.php +38 -0
  154. vendor/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php +80 -0
  155. vendor/twig/twig/src/Profiler/Profile.php +188 -0
  156. vendor/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php +41 -0
  157. vendor/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php +41 -0
  158. vendor/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php +31 -0
  159. vendor/twig/twig/src/Sandbox/SecurityError.php +25 -0
  160. vendor/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php +35 -0
  161. vendor/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php +35 -0
  162. vendor/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php +42 -0
  163. vendor/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php +42 -0
  164. vendor/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php +35 -0
  165. vendor/twig/twig/src/Sandbox/SecurityPolicy.php +129 -0
  166. vendor/twig/twig/src/Sandbox/SecurityPolicyInterface.php +28 -0
  167. vendor/twig/twig/src/Source.php +55 -0
  168. vendor/twig/twig/src/Template.php +733 -0
  169. vendor/twig/twig/src/TemplateWrapper.php +161 -0
  170. vendor/twig/twig/src/Test/IntegrationTestCase.php +257 -0
  171. vendor/twig/twig/src/Test/NodeTestCase.php +79 -0
  172. vendor/twig/twig/src/Token.php +215 -0
  173. vendor/twig/twig/src/TokenParser/AbstractTokenParser.php +34 -0
  174. vendor/twig/twig/src/TokenParser/ApplyTokenParser.php +58 -0
  175. vendor/twig/twig/src/TokenParser/AutoEscapeTokenParser.php +88 -0
  176. vendor/twig/twig/src/TokenParser/BlockTokenParser.php +80 -0
  177. vendor/twig/twig/src/TokenParser/DeprecatedTokenParser.php +44 -0
  178. vendor/twig/twig/src/TokenParser/DoTokenParser.php +39 -0
  179. vendor/twig/twig/src/TokenParser/EmbedTokenParser.php +74 -0
  180. vendor/twig/twig/src/TokenParser/ExtendsTokenParser.php +54 -0
  181. vendor/twig/twig/src/TokenParser/FilterTokenParser.php +59 -0
  182. vendor/twig/twig/src/TokenParser/FlushTokenParser.php +39 -0
  183. vendor/twig/twig/src/TokenParser/ForTokenParser.php +136 -0
  184. vendor/twig/twig/src/TokenParser/FromTokenParser.php +72 -0
  185. vendor/twig/twig/src/TokenParser/IfTokenParser.php +91 -0
  186. vendor/twig/twig/src/TokenParser/ImportTokenParser.php +45 -0
  187. vendor/twig/twig/src/TokenParser/IncludeTokenParser.php +68 -0
  188. vendor/twig/twig/src/TokenParser/MacroTokenParser.php +68 -0
  189. vendor/twig/twig/src/TokenParser/SandboxTokenParser.php +67 -0
  190. vendor/twig/twig/src/TokenParser/SetTokenParser.php +74 -0
  191. vendor/twig/twig/src/TokenParser/SpacelessTokenParser.php +53 -0
  192. vendor/twig/twig/src/TokenParser/TokenParserInterface.php +51 -0
  193. vendor/twig/twig/src/TokenParser/UseTokenParser.php +75 -0
  194. vendor/twig/twig/src/TokenParser/WithTokenParser.php +57 -0
  195. vendor/twig/twig/src/TokenStream.php +201 -0
  196. vendor/twig/twig/src/TwigFilter.php +128 -0
  197. vendor/twig/twig/src/TwigFunction.php +118 -0
  198. vendor/twig/twig/src/TwigTest.php +87 -0
  199. vendor/twig/twig/src/Util/DeprecationCollector.php +92 -0
  200. vendor/twig/twig/src/Util/TemplateDirIterator.php +30 -0
  201. vendor/twig/twig/test/Twig/Tests/Fixtures/errors/leak-output.php +31 -0
  202. vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/exception_in_extension_extends.test +12 -0
  203. vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/exception_in_extension_include.test +12 -0
  204. vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/strict_comparison_operator.test +6 -0
  205. vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/call_argument_defined_twice.test +8 -0
  206. vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/call_positional_arg_after_named_arg.test +8 -0
  207. vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/floats.test +16 -0
  208. vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/not_arrow_fn.test +8 -0
  209. vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/string_operator_as_var_assignment.test +18 -0
  210. vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_more_elements.test +23 -0
  211. vendor/twig/twig/test/Twig/Tests/Fixtures/filters/filter.test +46 -0
  212. vendor/twig/twig/test/Twig/Tests/Fixtures/filters/filter_php_55.test +23 -0
  213. vendor/twig/twig/test/Twig/Tests/Fixtures/filters/filter_php_56.test +27 -0
  214. vendor/twig/twig/test/Twig/Tests/Fixtures/filters/map.test +41 -0
  215. vendor/twig/twig/test/Twig/Tests/Fixtures/filters/reduce.test +14 -0
  216. vendor/twig/twig/test/Twig/Tests/Fixtures/filters/spaceless.test +8 -0
  217. vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/ignore_missing_exists.test +11 -0
  218. vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/include_missing_extends.test +13 -0
  219. vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include_template_from_string.test +11 -0
  220. vendor/twig/twig/test/Twig/Tests/Fixtures/functions/template_from_string_error.test +8 -0
  221. vendor/twig/twig/test/Twig/Tests/Fixtures/regression/block_names_unicity.test +19 -0
  222. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/basic.test +10 -0
  223. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/json_encode.test +8 -0
  224. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/multiple.test +10 -0
  225. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/nested.test +16 -0
  226. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/scope.test +15 -0
  227. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/with_for_tag.test +13 -0
  228. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/with_if_tag.test +29 -0
  229. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/deprecated/block.legacy.test +20 -0
  230. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/deprecated/macro.legacy.test +21 -0
  231. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/deprecated/template.legacy.test +12 -0
  232. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/scope.test +11 -0
  233. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/ignore_missing_exists.test +11 -0
  234. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/include_missing_extends.test +13 -0
  235. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_in_block.test +10 -0
  236. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_in_macro.test +10 -0
  237. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_as_template_wrapper.test +12 -0
  238. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_in_block_is_local.test +18 -0
  239. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_local_override.test +28 -0
  240. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_macro_in_a_macro.test +18 -0
  241. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_nested_blocks.test +18 -0
  242. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_nested_blocks_with_global_macro.test +18 -0
  243. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_syntax_error.test +8 -0
  244. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_and_blocks.test +36 -0
  245. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_from_string_template.test +10 -0
  246. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_in_block_is_local.test +18 -0
  247. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_local_override.test +28 -0
  248. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_macro_in_a_macro.test +18 -0
  249. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_nested_blocks.legacy.test +18 -0
  250. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_nested_blocks_with_global_macro.legacy.test +18 -0
  251. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_self_parent.test +23 -0
  252. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_syntax_error.test +10 -0
  253. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_name.test +10 -0
  254. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/array.test +16 -0
  255. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture_scope.test +10 -0
  256. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/inheritance.test +24 -0
  257. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/inheritance_overriding.test +24 -0
  258. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/mutating.test +17 -0
  259. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/use_with_parent.test +24 -0
  260. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/with/globals.test +10 -0
  261. vendor/twig/twig/test/Twig/Tests/Fixtures/tags/with/iterable.test +10 -0
  262. vendor/twig/twig/test/Twig/Tests/Fixtures/tests/defined_on_complex_expr.test +8 -0
  263. vendor/twig/twig/test/Twig/Tests/Fixtures/tests/dynamic_test.test +14 -0
  264. vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_block.test +68 -0
  265. vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_delimiter_as_strings.test +10 -0
  266. vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_left.test +32 -0
  267. vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_line_left.test +33 -0
  268. vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_line_right.test +32 -0
  269. vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_right.test +28 -0
  270. vendor/twig/twig/test/Twig/Tests/Node/DeprecatedTest.php +80 -0
  271. vendor/twig/twig/test/Twig/Tests/NodeTraverserTest.php +47 -0
public/css/app.css.twig CHANGED
@@ -149,10 +149,33 @@ button#responsive-menu-button,
149
  width: 100%;
150
  display: block;
151
  text-decoration: none;
152
- padding: 0 {{ options.menu_depth_0 }}%;
153
  position: relative;
154
  }
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  #responsive-menu-container li.responsive-menu-item a .fa {
157
  margin-right: 15px;
158
  }
@@ -512,7 +535,13 @@ button#responsive-menu-button,
512
  line-height: {{ options.submenu_arrow_height }}px;
513
  width: {{ options.submenu_arrow_width }}px;
514
  color: {{ options.menu_sub_arrow_shape_colour }};
515
- border-left: {{ options.menu_border_width }}px solid {{ options.menu_sub_arrow_border_colour }};
 
 
 
 
 
 
516
  background-color: {{ options.menu_sub_arrow_background_colour }};
517
  }
518
 
@@ -552,6 +581,7 @@ button#responsive-menu-button,
552
  font-family: {{ "'" ~ options.submenu_font ~ "'" }};
553
  {% endif %}
554
  font-size: {{ options.submenu_font_size }}px;
 
555
  }
556
 
557
  #responsive-menu-container #responsive-menu ul.responsive-menu-submenu li.responsive-menu-item a {
@@ -587,12 +617,26 @@ button#responsive-menu-button,
587
  }
588
 
589
  #responsive-menu-container #responsive-menu ul.responsive-menu-submenu li.responsive-menu-item a .responsive-menu-subarrow {
590
- {{ options.submenu_arrow_position }}: 0;
 
 
 
 
 
 
 
591
  height: {{ options.submenu_submenu_arrow_height }}px;
592
  line-height: {{ options.submenu_submenu_arrow_height }}px;
593
  width: {{ options.submenu_submenu_arrow_width }}px;
594
  color: {{ options.submenu_sub_arrow_shape_colour }};
595
- border-left: {{ options.submenu_border_width }}px solid {{ options.submenu_sub_arrow_border_colour }};
 
 
 
 
 
 
 
596
  background-color: {{ options.submenu_sub_arrow_background_colour }};
597
  }
598
 
149
  width: 100%;
150
  display: block;
151
  text-decoration: none;
152
+
153
  position: relative;
154
  }
155
 
156
+
157
+ #responsive-menu-container #responsive-menu li.responsive-menu-item a {
158
+ {% if options.menu_text_alignment == 'left' and options.arrow_position == 'left' %}
159
+ padding-left: {{options.submenu_arrow_width + 5}}px;
160
+ {% elseif options.menu_text_alignment == 'right' and options.arrow_position == 'right' %}
161
+ padding-right: {{options.submenu_arrow_width + 5}}px;
162
+ {% else %}
163
+ padding: 0 {{ options.menu_depth_0 }}%;
164
+ {% endif %}
165
+ }
166
+
167
+ #responsive-menu-container .responsive-menu-submenu li.responsive-menu-item a {
168
+ {% if options.submenu_text_alignment == 'left' and options.submenu_arrow_position == 'left' %}
169
+ padding-left: {{options.submenu_submenu_arrow_width + 5}}px !important;
170
+ padding-right:unset !important;
171
+ {% elseif options.submenu_text_alignment == 'right' and options.submenu_arrow_position == 'right' %}
172
+ padding-right: {{options.submenu_submenu_arrow_width + 5}}px !important;
173
+ padding-left:unset !important;
174
+ {% else %}
175
+ padding: 0 {{ options.menu_depth_0 }}%;
176
+ {% endif %}
177
+ }
178
+
179
  #responsive-menu-container li.responsive-menu-item a .fa {
180
  margin-right: 15px;
181
  }
535
  line-height: {{ options.submenu_arrow_height }}px;
536
  width: {{ options.submenu_arrow_width }}px;
537
  color: {{ options.menu_sub_arrow_shape_colour }};
538
+ {% if options.arrow_position == 'left' %}
539
+ border-right: {{ options.menu_border_width }}px
540
+ {% endif %}
541
+ {% if options.arrow_position == 'right' %}
542
+ border-left: {{ options.menu_border_width }}px
543
+ {% endif %}
544
+ solid {{ options.menu_sub_arrow_border_colour }};
545
  background-color: {{ options.menu_sub_arrow_background_colour }};
546
  }
547
 
581
  font-family: {{ "'" ~ options.submenu_font ~ "'" }};
582
  {% endif %}
583
  font-size: {{ options.submenu_font_size }}px;
584
+ text-align: {{ options.submenu_text_alignment }};
585
  }
586
 
587
  #responsive-menu-container #responsive-menu ul.responsive-menu-submenu li.responsive-menu-item a {
617
  }
618
 
619
  #responsive-menu-container #responsive-menu ul.responsive-menu-submenu li.responsive-menu-item a .responsive-menu-subarrow {
620
+ {% if options.submenu_arrow_position == 'left' %}
621
+ left:0;
622
+ right:unset;
623
+ {% endif %}
624
+ {% if options.submenu_arrow_position == 'right' %}
625
+ left:unset;
626
+ right:0;
627
+ {% endif %}
628
  height: {{ options.submenu_submenu_arrow_height }}px;
629
  line-height: {{ options.submenu_submenu_arrow_height }}px;
630
  width: {{ options.submenu_submenu_arrow_width }}px;
631
  color: {{ options.submenu_sub_arrow_shape_colour }};
632
+ {% if options.submenu_arrow_position == 'left' %}
633
+ border-right: {{ options.submenu_border_width }}px solid {{ options.submenu_sub_arrow_border_colour }} !important;
634
+ border-left:unset !important;
635
+ {% endif %}
636
+ {% if options.submenu_arrow_position == 'right' %}
637
+ border-left: {{ options.submenu_border_width }}px solid {{ options.submenu_sub_arrow_border_colour }} !important;
638
+ border-right:unset !important;
639
+ {% endif %}
640
  background-color: {{ options.submenu_sub_arrow_background_colour }};
641
  }
642
 
public/img/banner.jpg ADDED
Binary file
public/img/banner.png ADDED
Binary file
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
- === Responsive Menu ===
2
- Contributors: peterfeatherstone
3
- Tags: responsive, menu, navigation, mobile, hamburger
4
  Requires at least: 3.6
5
- Tested up to: 5.2.2
6
- Stable tag: 3.1.24
7
  Requires PHP: 5.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -111,6 +111,12 @@ To view our FAQ, please go to [https://responsive.menu/faq/](https://responsive.
111
 
112
  == Changelog ==
113
 
 
 
 
 
 
 
114
  = 3.1.24 (14th Aug 2019) =
115
  * Allow support for PHP 5.5 again.
116
  * Downgrade Twig back to 1.33.0 as it doesn't play nicely with other plugins.
1
+ === Responsive Menu - Create Mobile-Friendly Menu ===
2
+ Contributors: expresstech,responsivemenu
3
+ Tags: responsive, menu, navigation, mobile, hamburger, mobile menu, responsive menu
4
  Requires at least: 3.6
5
+ Tested up to: 5.3.2
6
+ Stable tag: 3.1.25
7
  Requires PHP: 5.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
111
 
112
  == Changelog ==
113
 
114
+ = 3.1.25 (14th Dec 2019) =
115
+ * Fix: Sub Menus -> Text Alignment Option does not work
116
+ * Fix: Trigger Icon Position
117
+ * Fix: Trigger Icon Border CSS code
118
+ * Fix: Menu Text goes under Trigger Icon
119
+
120
  = 3.1.24 (14th Aug 2019) =
121
  * Allow support for PHP 5.5 again.
122
  * Downgrade Twig back to 1.33.0 as it doesn't play nicely with other plugins.
responsive-menu.php CHANGED
@@ -2,14 +2,14 @@
2
 
3
  /*
4
  Plugin Name: Responsive Menu
5
- Plugin URI: https://responsive.menu
6
  Description: Highly Customisable Responsive Menu Plugin for WordPress
7
- Version: 3.1.24
8
- Author: Peter Featherstone
9
  Text Domain: responsive-menu
10
  Author URI: https://responsive.menu
11
  License: GPL2
12
- Tags: responsive, menu, responsive menu
13
  */
14
 
15
  add_action('admin_init', 'check_responsive_menu_php_version');
@@ -32,6 +32,35 @@ function responsive_menu_deactivation_text() {
32
  if(version_compare(PHP_VERSION, '5.4', '<'))
33
  return;
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  include dirname(__FILE__) . '/vendor/autoload.php';
36
  include dirname(__FILE__) . '/config/default_options.php';
37
  include dirname(__FILE__) . '/config/services.php';
2
 
3
  /*
4
  Plugin Name: Responsive Menu
5
+ Plugin URI: https://expresstech.io
6
  Description: Highly Customisable Responsive Menu Plugin for WordPress
7
+ Version: 3.1.25
8
+ Author: ExpressTech
9
  Text Domain: responsive-menu
10
  Author URI: https://responsive.menu
11
  License: GPL2
12
+ Tags: responsive, menu, responsive menu, mega menu, max mega menu, max menu
13
  */
14
 
15
  add_action('admin_init', 'check_responsive_menu_php_version');
32
  if(version_compare(PHP_VERSION, '5.4', '<'))
33
  return;
34
 
35
+ add_action( 'admin_notices', 'og_pro_deactivate_pro_version_notice');
36
+
37
+ function og_pro_deactivate_pro_version_notice() {
38
+ if(get_transient('og-admin-notice-activation-pro')) {
39
+ ?>
40
+ <div class="notice notice-error is-dismissible">
41
+ <p>Responsive Menu Pro has been deactivated<p/>
42
+
43
+ </div>
44
+ <?php
45
+ delete_transient('og-admin-notice-activation-pro');
46
+ }
47
+ }
48
+
49
+ function og_deactivate_responsive_menu_pro() {
50
+
51
+ $plugin = 'responsive-menu-pro/responsive-menu-pro.php';
52
+
53
+ if( is_plugin_active($plugin) ){
54
+ deactivate_plugins( 'responsive-menu-pro/responsive-menu-pro.php');
55
+ set_transient( 'og-admin-notice-activation-pro', true, 5 );
56
+
57
+ return;
58
+ }
59
+ }
60
+ //to check weather another plugin is acivated or not.
61
+ register_activation_hook( __FILE__, 'og_deactivate_responsive_menu_pro');
62
+
63
+
64
  include dirname(__FILE__) . '/vendor/autoload.php';
65
  include dirname(__FILE__) . '/config/default_options.php';
66
  include dirname(__FILE__) . '/config/services.php';
vendor/composer/autoload_files.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // autoload_files.php @generated by Composer
4
+
5
+ $vendorDir = dirname(dirname(__FILE__));
6
+ $baseDir = dirname($vendorDir);
7
+
8
+ return array(
9
+ '320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
10
+ );
vendor/symfony/polyfill-ctype/Ctype.php ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
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\Polyfill\Ctype;
13
+
14
+ /**
15
+ * Ctype implementation through regex.
16
+ *
17
+ * @internal
18
+ *
19
+ * @author Gert de Pagter <BackEndTea@gmail.com>
20
+ */
21
+ final class Ctype
22
+ {
23
+ /**
24
+ * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.
25
+ *
26
+ * @see https://php.net/ctype-alnum
27
+ *
28
+ * @param string|int $text
29
+ *
30
+ * @return bool
31
+ */
32
+ public static function ctype_alnum($text)
33
+ {
34
+ $text = self::convert_int_to_char_for_ctype($text);
35
+
36
+ return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
37
+ }
38
+
39
+ /**
40
+ * Returns TRUE if every character in text is a letter, FALSE otherwise.
41
+ *
42
+ * @see https://php.net/ctype-alpha
43
+ *
44
+ * @param string|int $text
45
+ *
46
+ * @return bool
47
+ */
48
+ public static function ctype_alpha($text)
49
+ {
50
+ $text = self::convert_int_to_char_for_ctype($text);
51
+
52
+ return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text);
53
+ }
54
+
55
+ /**
56
+ * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise.
57
+ *
58
+ * @see https://php.net/ctype-cntrl
59
+ *
60
+ * @param string|int $text
61
+ *
62
+ * @return bool
63
+ */
64
+ public static function ctype_cntrl($text)
65
+ {
66
+ $text = self::convert_int_to_char_for_ctype($text);
67
+
68
+ return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text);
69
+ }
70
+
71
+ /**
72
+ * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
73
+ *
74
+ * @see https://php.net/ctype-digit
75
+ *
76
+ * @param string|int $text
77
+ *
78
+ * @return bool
79
+ */
80
+ public static function ctype_digit($text)
81
+ {
82
+ $text = self::convert_int_to_char_for_ctype($text);
83
+
84
+ return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
85
+ }
86
+
87
+ /**
88
+ * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise.
89
+ *
90
+ * @see https://php.net/ctype-graph
91
+ *
92
+ * @param string|int $text
93
+ *
94
+ * @return bool
95
+ */
96
+ public static function ctype_graph($text)
97
+ {
98
+ $text = self::convert_int_to_char_for_ctype($text);
99
+
100
+ return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text);
101
+ }
102
+
103
+ /**
104
+ * Returns TRUE if every character in text is a lowercase letter.
105
+ *
106
+ * @see https://php.net/ctype-lower
107
+ *
108
+ * @param string|int $text
109
+ *
110
+ * @return bool
111
+ */
112
+ public static function ctype_lower($text)
113
+ {
114
+ $text = self::convert_int_to_char_for_ctype($text);
115
+
116
+ return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
117
+ }
118
+
119
+ /**
120
+ * Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all.
121
+ *
122
+ * @see https://php.net/ctype-print
123
+ *
124
+ * @param string|int $text
125
+ *
126
+ * @return bool
127
+ */
128
+ public static function ctype_print($text)
129
+ {
130
+ $text = self::convert_int_to_char_for_ctype($text);
131
+
132
+ return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text);
133
+ }
134
+
135
+ /**
136
+ * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.
137
+ *
138
+ * @see https://php.net/ctype-punct
139
+ *
140
+ * @param string|int $text
141
+ *
142
+ * @return bool
143
+ */
144
+ public static function ctype_punct($text)
145
+ {
146
+ $text = self::convert_int_to_char_for_ctype($text);
147
+
148
+ return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text);
149
+ }
150
+
151
+ /**
152
+ * Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.
153
+ *
154
+ * @see https://php.net/ctype-space
155
+ *
156
+ * @param string|int $text
157
+ *
158
+ * @return bool
159
+ */
160
+ public static function ctype_space($text)
161
+ {
162
+ $text = self::convert_int_to_char_for_ctype($text);
163
+
164
+ return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text);
165
+ }
166
+
167
+ /**
168
+ * Returns TRUE if every character in text is an uppercase letter.
169
+ *
170
+ * @see https://php.net/ctype-upper
171
+ *
172
+ * @param string|int $text
173
+ *
174
+ * @return bool
175
+ */
176
+ public static function ctype_upper($text)
177
+ {
178
+ $text = self::convert_int_to_char_for_ctype($text);
179
+
180
+ return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text);
181
+ }
182
+
183
+ /**
184
+ * Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise.
185
+ *
186
+ * @see https://php.net/ctype-xdigit
187
+ *
188
+ * @param string|int $text
189
+ *
190
+ * @return bool
191
+ */
192
+ public static function ctype_xdigit($text)
193
+ {
194
+ $text = self::convert_int_to_char_for_ctype($text);
195
+
196
+ return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text);
197
+ }
198
+
199
+ /**
200
+ * Converts integers to their char versions according to normal ctype behaviour, if needed.
201
+ *
202
+ * If an integer between -128 and 255 inclusive is provided,
203
+ * it is interpreted as the ASCII value of a single character
204
+ * (negative values have 256 added in order to allow characters in the Extended ASCII range).
205
+ * Any other integer is interpreted as a string containing the decimal digits of the integer.
206
+ *
207
+ * @param string|int $int
208
+ *
209
+ * @return mixed
210
+ */
211
+ private static function convert_int_to_char_for_ctype($int)
212
+ {
213
+ if (!\is_int($int)) {
214
+ return $int;
215
+ }
216
+
217
+ if ($int < -128 || $int > 255) {
218
+ return (string) $int;
219
+ }
220
+
221
+ if ($int < 0) {
222
+ $int += 256;
223
+ }
224
+
225
+ return \chr($int);
226
+ }
227
+ }
vendor/symfony/polyfill-ctype/LICENSE ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2018-2019 Fabien Potencier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is furnished
8
+ to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
vendor/symfony/polyfill-ctype/README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Symfony Polyfill / Ctype
2
+ ========================
3
+
4
+ This component provides `ctype_*` functions to users who run php versions without the ctype extension.
5
+
6
+ More information can be found in the
7
+ [main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md).
8
+
9
+ License
10
+ =======
11
+
12
+ This library is released under the [MIT license](LICENSE).
vendor/symfony/polyfill-ctype/bootstrap.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
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
+ use Symfony\Polyfill\Ctype as p;
13
+
14
+ if (!function_exists('ctype_alnum')) {
15
+ function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); }
16
+ function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); }
17
+ function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); }
18
+ function ctype_digit($text) { return p\Ctype::ctype_digit($text); }
19
+ function ctype_graph($text) { return p\Ctype::ctype_graph($text); }
20
+ function ctype_lower($text) { return p\Ctype::ctype_lower($text); }
21
+ function ctype_print($text) { return p\Ctype::ctype_print($text); }
22
+ function ctype_punct($text) { return p\Ctype::ctype_punct($text); }
23
+ function ctype_space($text) { return p\Ctype::ctype_space($text); }
24
+ function ctype_upper($text) { return p\Ctype::ctype_upper($text); }
25
+ function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); }
26
+ }
vendor/symfony/polyfill-ctype/composer.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "symfony/polyfill-ctype",
3
+ "type": "library",
4
+ "description": "Symfony polyfill for ctype functions",
5
+ "keywords": ["polyfill", "compatibility", "portable", "ctype"],
6
+ "homepage": "https://symfony.com",
7
+ "license": "MIT",
8
+ "authors": [
9
+ {
10
+ "name": "Gert de Pagter",
11
+ "email": "BackEndTea@gmail.com"
12
+ },
13
+ {
14
+ "name": "Symfony Community",
15
+ "homepage": "https://symfony.com/contributors"
16
+ }
17
+ ],
18
+ "require": {
19
+ "php": ">=5.3.3"
20
+ },
21
+ "autoload": {
22
+ "psr-4": { "Symfony\\Polyfill\\Ctype\\": "" },
23
+ "files": [ "bootstrap.php" ]
24
+ },
25
+ "suggest": {
26
+ "ext-ctype": "For best performance"
27
+ },
28
+ "minimum-stability": "dev",
29
+ "extra": {
30
+ "branch-alias": {
31
+ "dev-master": "1.12-dev"
32
+ }
33
+ }
34
+ }
vendor/twig/twig/.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ /build
2
+ /composer.lock
3
+ /ext/twig/autom4te.cache/
4
+ /phpunit.xml
5
+ /vendor
vendor/twig/twig/doc/filters/filter.rst ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ``filter``
2
+ =========
3
+
4
+ .. versionadded:: 1.41
5
+ The ``filter`` filter was added in Twig 1.41 and 2.10.
6
+
7
+ The ``filter`` filter filters elements of a sequence or a mapping using an arrow
8
+ function. The arrow function receives the value of the sequence or mapping:
9
+
10
+ .. code-block:: twig
11
+
12
+ {% set sizes = [34, 36, 38, 40, 42] %}
13
+
14
+ {{ sizes|filter(v => v > 38)|join(', ') }}
15
+ {# output 40, 42 #}
16
+
17
+ Combined with the ``for`` tag, it allows to filter the items to iterate over:
18
+
19
+ .. code-block:: twig
20
+
21
+ {% for v in sizes|filter(v => v > 38) -%}
22
+ {{ v }}
23
+ {% endfor %}
24
+ {# output 40 42 #}
25
+
26
+ It also works with mappings:
27
+
28
+ .. code-block:: twig
29
+
30
+ {% set sizes = {
31
+ xs: 34,
32
+ s: 36,
33
+ m: 38,
34
+ l: 40,
35
+ xl: 42,
36
+ } %}
37
+
38
+ {% for k, v in sizes|filter(v => v > 38) -%}
39
+ {{ k }} = {{ v }}
40
+ {% endfor %}
41
+ {# output l = 40 xl = 42 #}
42
+
43
+ The arrow function also receives the key as a second argument:
44
+
45
+ .. code-block:: twig
46
+
47
+ {% for k, v in sizes|filter((v, k) => v > 38 and k != "xl") -%}
48
+ {{ k }} = {{ v }}
49
+ {% endfor %}
50
+ {# output l = 40 #}
51
+
52
+ Note that the arrow function has access to the current context.
53
+
54
+ Arguments
55
+ ---------
56
+
57
+ * ``array``: The sequence or mapping
58
+ * ``arrow``: The arrow function
vendor/twig/twig/doc/filters/map.rst ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ``map``
2
+ =======
3
+
4
+ .. versionadded:: 1.41
5
+ The ``map`` filter was added in Twig 1.41 and 2.10.
6
+
7
+ The ``map`` filter applies an arrow function to the elements of a sequence or a
8
+ mapping. The arrow function receives the value of the sequence or mapping:
9
+
10
+ .. code-block:: twig
11
+
12
+ {% set people = [
13
+ {first: "Bob", last: "Smith"},
14
+ {first: "Alice", last: "Dupond"},
15
+ ] %}
16
+
17
+ {{ people|map(p => "#{p.first} #{p.last}")|join(', ') }}
18
+ {# outputs Bob Smith, Alice Dupond #}
19
+
20
+ The arrow function also receives the key as a second argument:
21
+
22
+ .. code-block:: twig
23
+
24
+ {% set people = {
25
+ "Bob": "Smith",
26
+ "Alice": "Dupond",
27
+ } %}
28
+
29
+ {{ people|map((first, last) => "#{first} #{last}")|join(', ') }}
30
+ {# outputs Bob Smith, Alice Dupond #}
31
+
32
+ Note that the arrow function has access to the current context.
33
+
34
+ Arguments
35
+ ---------
36
+
37
+ * ``array``: The sequence or mapping
38
+ * ``arrow``: The arrow function
vendor/twig/twig/doc/filters/reduce.rst ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ``reduce``
2
+ =========
3
+
4
+ .. versionadded:: 1.41
5
+ The ``reduce`` filter was added in Twig 1.41 and 2.10.
6
+
7
+ The ``reduce`` filter iteratively reduces a sequence or a mapping to a single
8
+ value using an arrow function, so as to reduce it to a single value. The arrow
9
+ function receives the return value of the previous iteration and the current
10
+ value of the sequence or mapping:
11
+
12
+ .. code-block:: twig
13
+
14
+ {% set numbers = [1, 2, 3] %}
15
+
16
+ {{ numbers|reduce((carry, v) => carry + v) }}
17
+ {# output 6 #}
18
+
19
+ The ``reduce`` filter takes an ``initial`` value as a second argument:
20
+
21
+ .. code-block:: twig
22
+
23
+ {{ numbers|reduce((carry, v) => carry + v, 10) }}
24
+ {# output 16 #}
25
+
26
+ Note that the arrow function has access to the current context.
27
+
28
+ Arguments
29
+ ---------
30
+
31
+ * ``array``: The sequence or mapping
32
+ * ``arrow``: The arrow function
33
+ * ``initial``: The initial value
vendor/twig/twig/doc/filters/spaceless.rst ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ``spaceless``
2
+ =============
3
+
4
+ .. versionadded:: 1.38
5
+
6
+ The ``spaceless`` filter was added in Twig 1.38.
7
+
8
+ Use the ``spaceless`` filter to remove whitespace *between HTML tags*, not
9
+ whitespace within HTML tags or whitespace in plain text:
10
+
11
+ .. code-block:: twig
12
+
13
+ {{
14
+ "<div>
15
+ <strong>foo</strong>
16
+ </div>
17
+ "|spaceless }}
18
+
19
+ {# output will be <div><strong>foo</strong></div> #}
20
+
21
+ You can combine ``spaceless`` with the ``apply`` tag to apply the transformation
22
+ on large amounts of HTML:
23
+
24
+ .. code-block:: twig
25
+
26
+ {% apply spaceless %}
27
+ <div>
28
+ <strong>foo</strong>
29
+ </div>
30
+ {% endapply %}
31
+
32
+ {# output will be <div><strong>foo</strong></div> #}
33
+
34
+ .. note::
35
+
36
+ The ``apply`` tag was introduced in Twig 1.40; use the ``filter`` tag with
37
+ previous versions.
38
+
39
+ This tag is not meant to "optimize" the size of the generated HTML content but
40
+ merely to avoid extra whitespace between HTML tags to avoid browser rendering
41
+ quirks under some circumstances.
42
+
43
+ .. caution::
44
+
45
+ As the filter uses a regular expression behind the scenes, its performance
46
+ is directly related to the text size you are working on (remember that
47
+ filters are executed at runtime).
48
+
49
+ .. tip::
50
+
51
+ If you want to optimize the size of the generated HTML content, gzip
52
+ compress the output instead.
53
+
54
+ .. tip::
55
+
56
+ If you want to create a tag that actually removes all extra whitespace in
57
+ an HTML string, be warned that this is not as easy as it seems to be
58
+ (think of ``textarea`` or ``pre`` tags for instance). Using a third-party
59
+ library like Tidy is probably a better idea.
60
+
61
+ .. tip::
62
+
63
+ For more information on whitespace control, read the
64
+ :ref:`dedicated section <templates-whitespace-control>` of the documentation and learn how
65
+ you can also use the whitespace control modifier on your tags.
vendor/twig/twig/doc/tags/apply.rst ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ``apply``
2
+ =========
3
+
4
+ .. versionadded:: 1.40
5
+ The ``apply`` tag was added in Twig 1.40.
6
+
7
+ The ``apply`` tag allows you to apply Twig filters on a block of template data:
8
+
9
+ .. code-block:: twig
10
+
11
+ {% apply upper %}
12
+ This text becomes uppercase
13
+ {% endapply %}
14
+
15
+ You can also chain filters and pass arguments to them:
16
+
17
+ .. code-block:: twig
18
+
19
+ {% apply lower|escape('html') %}
20
+ <strong>SOME TEXT</strong>
21
+ {% endapply %}
22
+
23
+ {# outputs "&lt;strong&gt;some text&lt;/strong&gt;" #}
vendor/twig/twig/doc/tags/deprecated.rst ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ``deprecated``
2
+ ==============
3
+
4
+ .. versionadded:: 1.36 and 2.6
5
+ The ``deprecated`` tag was added in Twig 1.36 and 2.6.
6
+
7
+ Twig generates a deprecation notice (via a call to the ``trigger_error()``
8
+ PHP function) where the ``deprecated`` tag is used in a template:
9
+
10
+ .. code-block:: twig
11
+
12
+ {# base.twig #}
13
+ {% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' %}
14
+ {% extends 'layout.twig' %}
15
+
16
+ Also you can deprecate a block in the following way:
17
+
18
+ .. code-block:: twig
19
+
20
+ {% block hey %}
21
+ {% deprecated 'The "hey" block is deprecated, use "greet" instead.' %}
22
+ {{ block('greet') }}
23
+ {% endblock %}
24
+
25
+ {% block greet %}
26
+ Hey you!
27
+ {% endblock %}
28
+
29
+ Note that by default, the deprecation notices are silenced and never displayed nor logged.
30
+ See :ref:`deprecation-notices` to learn how to handle them.
vendor/twig/twig/drupal_test.sh ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ REPO=`pwd`
7
+ cd /tmp
8
+ rm -rf drupal-twig-test
9
+ composer create-project --no-interaction drupal-composer/drupal-project:8.x-dev drupal-twig-test
10
+ cd drupal-twig-test
11
+ (cd vendor/twig && rm -rf twig && ln -sf $REPO twig)
12
+ echo '$config["system.logging"]["error_level"] = "verbose";' >> web/sites/default/settings.php
13
+ php ./web/core/scripts/drupal install --no-interaction demo_umami > output
14
+ perl -p -i -e 's/^([A-Za-z]+)\: (.+)$/export DRUPAL_\1=\2/' output
15
+ source output
16
+
17
+ wget https://get.symfony.com/cli/installer -O - | bash
18
+ export PATH="$HOME/.symfony/bin:$PATH"
19
+ symfony server:start -d --no-tls
20
+ ENDPOINT=`symfony server:status -no-ansi | sed -E 's/^.+ http/http/'`
21
+
22
+ curl -OLsS https://get.blackfire.io/blackfire-player.phar
23
+ chmod +x blackfire-player.phar
24
+ cat > drupal-tests.bkf <<EOF
25
+ name "Drupal tests"
26
+
27
+ scenario
28
+ name "homepage"
29
+ set name "admin"
30
+ set pass "pass"
31
+
32
+ visit url('/')
33
+ expect status_code() == 200
34
+ click link('Articles')
35
+ expect status_code() == 200
36
+ click link('Dairy-free and delicious milk chocolate')
37
+ expect body() matches "/Dairy\-free milk chocolate is made in largely the same way as regular chocolate/"
38
+ expect status_code() == 200
39
+ click link('Log in')
40
+ expect status_code() == 200
41
+ submit button("Log in")
42
+ param name name
43
+ param pass pass
44
+ expect status_code() == 303
45
+ follow
46
+ expect status_code() == 200
47
+ click link('Structure')
48
+ expect status_code() == 200
49
+ EOF
50
+ ./blackfire-player.phar run drupal-tests.bkf --endpoint=$ENDPOINT --variable name=$DRUPAL_Username --variable pass=$DRUPAL_Password
51
+ symfony server:stop
vendor/twig/twig/ext/twig/.gitignore ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.sw*
2
+ .deps
3
+ Makefile
4
+ Makefile.fragments
5
+ Makefile.global
6
+ Makefile.objects
7
+ acinclude.m4
8
+ aclocal.m4
9
+ build/
10
+ config.cache
11
+ config.guess
12
+ config.h
13
+ config.h.in
14
+ config.log
15
+ config.nice
16
+ config.status
17
+ config.sub
18
+ configure
19
+ configure.in
20
+ install-sh
21
+ libtool
22
+ ltmain.sh
23
+ missing
24
+ mkinstalldirs
25
+ run-tests.php
26
+ twig.loT
27
+ .libs/
28
+ modules/
29
+ twig.la
30
+ twig.lo
vendor/twig/twig/lib/Twig/Node/Deprecated.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Twig\Node\DeprecatedNode;
4
+
5
+ class_exists('Twig\Node\DeprecatedNode');
6
+
7
+ if (\false) {
8
+ class Twig_Node_Deprecated extends DeprecatedNode
9
+ {
10
+ }
11
+ }
vendor/twig/twig/lib/Twig/Profiler/Dumper/Base.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Twig\Profiler\Dumper\BaseDumper;
4
+
5
+ class_exists('Twig\Profiler\Dumper\BaseDumper');
6
+
7
+ if (\false) {
8
+ class Twig_Profiler_Dumper_Base extends BaseDumper
9
+ {
10
+ }
11
+ }
vendor/twig/twig/lib/Twig/TokenParser/Deprecated.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Twig\TokenParser\DeprecatedTokenParser;
4
+
5
+ class_exists('Twig\TokenParser\DeprecatedTokenParser');
6
+
7
+ if (\false) {
8
+ class Twig_TokenParser_Deprecated extends DeprecatedTokenParser
9
+ {
10
+ }
11
+ }
vendor/twig/twig/src/Cache/CacheInterface.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Cache;
13
+
14
+ /**
15
+ * Interface implemented by cache classes.
16
+ *
17
+ * It is highly recommended to always store templates on the filesystem to
18
+ * benefit from the PHP opcode cache. This interface is mostly useful if you
19
+ * need to implement a custom strategy for storing templates on the filesystem.
20
+ *
21
+ * @author Andrew Tch <andrew@noop.lv>
22
+ */
23
+ interface CacheInterface
24
+ {
25
+ /**
26
+ * Generates a cache key for the given template class name.
27
+ *
28
+ * @param string $name The template name
29
+ * @param string $className The template class name
30
+ *
31
+ * @return string
32
+ */
33
+ public function generateKey($name, $className);
34
+
35
+ /**
36
+ * Writes the compiled template to cache.
37
+ *
38
+ * @param string $key The cache key
39
+ * @param string $content The template representation as a PHP class
40
+ */
41
+ public function write($key, $content);
42
+
43
+ /**
44
+ * Loads a template from the cache.
45
+ *
46
+ * @param string $key The cache key
47
+ */
48
+ public function load($key);
49
+
50
+ /**
51
+ * Returns the modification timestamp of a key.
52
+ *
53
+ * @param string $key The cache key
54
+ *
55
+ * @return int
56
+ */
57
+ public function getTimestamp($key);
58
+ }
59
+
60
+ class_alias('Twig\Cache\CacheInterface', 'Twig_CacheInterface');
vendor/twig/twig/src/Cache/FilesystemCache.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Cache;
13
+
14
+ /**
15
+ * Implements a cache on the filesystem.
16
+ *
17
+ * @author Andrew Tch <andrew@noop.lv>
18
+ */
19
+ class FilesystemCache implements CacheInterface
20
+ {
21
+ const FORCE_BYTECODE_INVALIDATION = 1;
22
+
23
+ private $directory;
24
+ private $options;
25
+
26
+ /**
27
+ * @param string $directory The root cache directory
28
+ * @param int $options A set of options
29
+ */
30
+ public function __construct($directory, $options = 0)
31
+ {
32
+ $this->directory = rtrim($directory, '\/').'/';
33
+ $this->options = $options;
34
+ }
35
+
36
+ public function generateKey($name, $className)
37
+ {
38
+ $hash = hash('sha256', $className);
39
+
40
+ return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php';
41
+ }
42
+
43
+ public function load($key)
44
+ {
45
+ if (file_exists($key)) {
46
+ @include_once $key;
47
+ }
48
+ }
49
+
50
+ public function write($key, $content)
51
+ {
52
+ $dir = \dirname($key);
53
+ if (!is_dir($dir)) {
54
+ if (false === @mkdir($dir, 0777, true)) {
55
+ clearstatcache(true, $dir);
56
+ if (!is_dir($dir)) {
57
+ throw new \RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
58
+ }
59
+ }
60
+ } elseif (!is_writable($dir)) {
61
+ throw new \RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
62
+ }
63
+
64
+ $tmpFile = tempnam($dir, basename($key));
65
+ if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) {
66
+ @chmod($key, 0666 & ~umask());
67
+
68
+ if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
69
+ // Compile cached file into bytecode cache
70
+ if (\function_exists('opcache_invalidate')) {
71
+ opcache_invalidate($key, true);
72
+ } elseif (\function_exists('apc_compile_file')) {
73
+ apc_compile_file($key);
74
+ }
75
+ }
76
+
77
+ return;
78
+ }
79
+
80
+ throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $key));
81
+ }
82
+
83
+ public function getTimestamp($key)
84
+ {
85
+ if (!file_exists($key)) {
86
+ return 0;
87
+ }
88
+
89
+ return (int) @filemtime($key);
90
+ }
91
+ }
92
+
93
+ class_alias('Twig\Cache\FilesystemCache', 'Twig_Cache_Filesystem');
vendor/twig/twig/src/Cache/NullCache.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Cache;
13
+
14
+ /**
15
+ * Implements a no-cache strategy.
16
+ *
17
+ * @final
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ class NullCache implements CacheInterface
22
+ {
23
+ public function generateKey($name, $className)
24
+ {
25
+ return '';
26
+ }
27
+
28
+ public function write($key, $content)
29
+ {
30
+ }
31
+
32
+ public function load($key)
33
+ {
34
+ }
35
+
36
+ public function getTimestamp($key)
37
+ {
38
+ return 0;
39
+ }
40
+ }
41
+
42
+ class_alias('Twig\Cache\NullCache', 'Twig_Cache_Null');
vendor/twig/twig/src/Compiler.php ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig;
14
+
15
+ use Twig\Node\ModuleNode;
16
+
17
+ /**
18
+ * Compiles a node to PHP code.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class Compiler implements \Twig_CompilerInterface
23
+ {
24
+ protected $lastLine;
25
+ protected $source;
26
+ protected $indentation;
27
+ protected $env;
28
+ protected $debugInfo = [];
29
+ protected $sourceOffset;
30
+ protected $sourceLine;
31
+ protected $filename;
32
+ private $varNameSalt = 0;
33
+
34
+ public function __construct(Environment $env)
35
+ {
36
+ $this->env = $env;
37
+ }
38
+
39
+ /**
40
+ * @deprecated since 1.25 (to be removed in 2.0)
41
+ */
42
+ public function getFilename()
43
+ {
44
+ @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
45
+
46
+ return $this->filename;
47
+ }
48
+
49
+ /**
50
+ * Returns the environment instance related to this compiler.
51
+ *
52
+ * @return Environment
53
+ */
54
+ public function getEnvironment()
55
+ {
56
+ return $this->env;
57
+ }
58
+
59
+ /**
60
+ * Gets the current PHP code after compilation.
61
+ *
62
+ * @return string The PHP code
63
+ */
64
+ public function getSource()
65
+ {
66
+ return $this->source;
67
+ }
68
+
69
+ /**
70
+ * Compiles a node.
71
+ *
72
+ * @param int $indentation The current indentation
73
+ *
74
+ * @return $this
75
+ */
76
+ public function compile(\Twig_NodeInterface $node, $indentation = 0)
77
+ {
78
+ $this->lastLine = null;
79
+ $this->source = '';
80
+ $this->debugInfo = [];
81
+ $this->sourceOffset = 0;
82
+ // source code starts at 1 (as we then increment it when we encounter new lines)
83
+ $this->sourceLine = 1;
84
+ $this->indentation = $indentation;
85
+ $this->varNameSalt = 0;
86
+
87
+ if ($node instanceof ModuleNode) {
88
+ // to be removed in 2.0
89
+ $this->filename = $node->getTemplateName();
90
+ }
91
+
92
+ $node->compile($this);
93
+
94
+ return $this;
95
+ }
96
+
97
+ public function subcompile(\Twig_NodeInterface $node, $raw = true)
98
+ {
99
+ if (false === $raw) {
100
+ $this->source .= str_repeat(' ', $this->indentation * 4);
101
+ }
102
+
103
+ $node->compile($this);
104
+
105
+ return $this;
106
+ }
107
+
108
+ /**
109
+ * Adds a raw string to the compiled code.
110
+ *
111
+ * @param string $string The string
112
+ *
113
+ * @return $this
114
+ */
115
+ public function raw($string)
116
+ {
117
+ $this->source .= $string;
118
+
119
+ return $this;
120
+ }
121
+
122
+ /**
123
+ * Writes a string to the compiled code by adding indentation.
124
+ *
125
+ * @return $this
126
+ */
127
+ public function write()
128
+ {
129
+ $strings = \func_get_args();
130
+ foreach ($strings as $string) {
131
+ $this->source .= str_repeat(' ', $this->indentation * 4).$string;
132
+ }
133
+
134
+ return $this;
135
+ }
136
+
137
+ /**
138
+ * Appends an indentation to the current PHP code after compilation.
139
+ *
140
+ * @return $this
141
+ *
142
+ * @deprecated since 1.27 (to be removed in 2.0).
143
+ */
144
+ public function addIndentation()
145
+ {
146
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', E_USER_DEPRECATED);
147
+
148
+ $this->source .= str_repeat(' ', $this->indentation * 4);
149
+
150
+ return $this;
151
+ }
152
+
153
+ /**
154
+ * Adds a quoted string to the compiled code.
155
+ *
156
+ * @param string $value The string
157
+ *
158
+ * @return $this
159
+ */
160
+ public function string($value)
161
+ {
162
+ $this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\"));
163
+
164
+ return $this;
165
+ }
166
+
167
+ /**
168
+ * Returns a PHP representation of a given value.
169
+ *
170
+ * @param mixed $value The value to convert
171
+ *
172
+ * @return $this
173
+ */
174
+ public function repr($value)
175
+ {
176
+ if (\is_int($value) || \is_float($value)) {
177
+ if (false !== $locale = setlocale(LC_NUMERIC, '0')) {
178
+ setlocale(LC_NUMERIC, 'C');
179
+ }
180
+
181
+ $this->raw(var_export($value, true));
182
+
183
+ if (false !== $locale) {
184
+ setlocale(LC_NUMERIC, $locale);
185
+ }
186
+ } elseif (null === $value) {
187
+ $this->raw('null');
188
+ } elseif (\is_bool($value)) {
189
+ $this->raw($value ? 'true' : 'false');
190
+ } elseif (\is_array($value)) {
191
+ $this->raw('[');
192
+ $first = true;
193
+ foreach ($value as $key => $v) {
194
+ if (!$first) {
195
+ $this->raw(', ');
196
+ }
197
+ $first = false;
198
+ $this->repr($key);
199
+ $this->raw(' => ');
200
+ $this->repr($v);
201
+ }
202
+ $this->raw(']');
203
+ } else {
204
+ $this->string($value);
205
+ }
206
+
207
+ return $this;
208
+ }
209
+
210
+ /**
211
+ * Adds debugging information.
212
+ *
213
+ * @return $this
214
+ */
215
+ public function addDebugInfo(\Twig_NodeInterface $node)
216
+ {
217
+ if ($node->getTemplateLine() != $this->lastLine) {
218
+ $this->write(sprintf("// line %d\n", $node->getTemplateLine()));
219
+
220
+ // when mbstring.func_overload is set to 2
221
+ // mb_substr_count() replaces substr_count()
222
+ // but they have different signatures!
223
+ if (((int) ini_get('mbstring.func_overload')) & 2) {
224
+ @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED);
225
+
226
+ // this is much slower than the "right" version
227
+ $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n");
228
+ } else {
229
+ $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
230
+ }
231
+ $this->sourceOffset = \strlen($this->source);
232
+ $this->debugInfo[$this->sourceLine] = $node->getTemplateLine();
233
+
234
+ $this->lastLine = $node->getTemplateLine();
235
+ }
236
+
237
+ return $this;
238
+ }
239
+
240
+ public function getDebugInfo()
241
+ {
242
+ ksort($this->debugInfo);
243
+
244
+ return $this->debugInfo;
245
+ }
246
+
247
+ /**
248
+ * Indents the generated code.
249
+ *
250
+ * @param int $step The number of indentation to add
251
+ *
252
+ * @return $this
253
+ */
254
+ public function indent($step = 1)
255
+ {
256
+ $this->indentation += $step;
257
+
258
+ return $this;
259
+ }
260
+
261
+ /**
262
+ * Outdents the generated code.
263
+ *
264
+ * @param int $step The number of indentation to remove
265
+ *
266
+ * @return $this
267
+ *
268
+ * @throws \LogicException When trying to outdent too much so the indentation would become negative
269
+ */
270
+ public function outdent($step = 1)
271
+ {
272
+ // can't outdent by more steps than the current indentation level
273
+ if ($this->indentation < $step) {
274
+ throw new \LogicException('Unable to call outdent() as the indentation would become negative.');
275
+ }
276
+
277
+ $this->indentation -= $step;
278
+
279
+ return $this;
280
+ }
281
+
282
+ public function getVarName()
283
+ {
284
+ return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->varNameSalt++));
285
+ }
286
+ }
287
+
288
+ class_alias('Twig\Compiler', 'Twig_Compiler');
vendor/twig/twig/src/Environment.php ADDED
@@ -0,0 +1,1638 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig;
13
+
14
+ use Twig\Cache\CacheInterface;
15
+ use Twig\Cache\FilesystemCache;
16
+ use Twig\Cache\NullCache;
17
+ use Twig\Error\Error;
18
+ use Twig\Error\LoaderError;
19
+ use Twig\Error\RuntimeError;
20
+ use Twig\Error\SyntaxError;
21
+ use Twig\Extension\CoreExtension;
22
+ use Twig\Extension\EscaperExtension;
23
+ use Twig\Extension\ExtensionInterface;
24
+ use Twig\Extension\GlobalsInterface;
25
+ use Twig\Extension\InitRuntimeInterface;
26
+ use Twig\Extension\OptimizerExtension;
27
+ use Twig\Extension\StagingExtension;
28
+ use Twig\Loader\ArrayLoader;
29
+ use Twig\Loader\ChainLoader;
30
+ use Twig\Loader\LoaderInterface;
31
+ use Twig\Loader\SourceContextLoaderInterface;
32
+ use Twig\Node\ModuleNode;
33
+ use Twig\NodeVisitor\NodeVisitorInterface;
34
+ use Twig\RuntimeLoader\RuntimeLoaderInterface;
35
+ use Twig\TokenParser\TokenParserInterface;
36
+
37
+ /**
38
+ * Stores the Twig configuration.
39
+ *
40
+ * @author Fabien Potencier <fabien@symfony.com>
41
+ */
42
+ class Environment
43
+ {
44
+ const VERSION = '1.42.2';
45
+ const VERSION_ID = 14202;
46
+ const MAJOR_VERSION = 1;
47
+ const MINOR_VERSION = 42;
48
+ const RELEASE_VERSION = 2;
49
+ const EXTRA_VERSION = '';
50
+
51
+ protected $charset;
52
+ protected $loader;
53
+ protected $debug;
54
+ protected $autoReload;
55
+ protected $cache;
56
+ protected $lexer;
57
+ protected $parser;
58
+ protected $compiler;
59
+ protected $baseTemplateClass;
60
+ protected $extensions;
61
+ protected $parsers;
62
+ protected $visitors;
63
+ protected $filters;
64
+ protected $tests;
65
+ protected $functions;
66
+ protected $globals;
67
+ protected $runtimeInitialized = false;
68
+ protected $extensionInitialized = false;
69
+ protected $loadedTemplates;
70
+ protected $strictVariables;
71
+ protected $unaryOperators;
72
+ protected $binaryOperators;
73
+ protected $templateClassPrefix = '__TwigTemplate_';
74
+ protected $functionCallbacks = [];
75
+ protected $filterCallbacks = [];
76
+ protected $staging;
77
+
78
+ private $originalCache;
79
+ private $bcWriteCacheFile = false;
80
+ private $bcGetCacheFilename = false;
81
+ private $lastModifiedExtension = 0;
82
+ private $extensionsByClass = [];
83
+ private $runtimeLoaders = [];
84
+ private $runtimes = [];
85
+ private $optionsHash;
86
+
87
+ /**
88
+ * Constructor.
89
+ *
90
+ * Available options:
91
+ *
92
+ * * debug: When set to true, it automatically set "auto_reload" to true as
93
+ * well (default to false).
94
+ *
95
+ * * charset: The charset used by the templates (default to UTF-8).
96
+ *
97
+ * * base_template_class: The base template class to use for generated
98
+ * templates (default to \Twig\Template).
99
+ *
100
+ * * cache: An absolute path where to store the compiled templates,
101
+ * a \Twig\Cache\CacheInterface implementation,
102
+ * or false to disable compilation cache (default).
103
+ *
104
+ * * auto_reload: Whether to reload the template if the original source changed.
105
+ * If you don't provide the auto_reload option, it will be
106
+ * determined automatically based on the debug value.
107
+ *
108
+ * * strict_variables: Whether to ignore invalid variables in templates
109
+ * (default to false).
110
+ *
111
+ * * autoescape: Whether to enable auto-escaping (default to html):
112
+ * * false: disable auto-escaping
113
+ * * true: equivalent to html
114
+ * * html, js: set the autoescaping to one of the supported strategies
115
+ * * name: set the autoescaping strategy based on the template name extension
116
+ * * PHP callback: a PHP callback that returns an escaping strategy based on the template "name"
117
+ *
118
+ * * optimizations: A flag that indicates which optimizations to apply
119
+ * (default to -1 which means that all optimizations are enabled;
120
+ * set it to 0 to disable).
121
+ */
122
+ public function __construct(LoaderInterface $loader = null, $options = [])
123
+ {
124
+ if (null !== $loader) {
125
+ $this->setLoader($loader);
126
+ } else {
127
+ @trigger_error('Not passing a "Twig\Lodaer\LoaderInterface" as the first constructor argument of "Twig\Environment" is deprecated since version 1.21.', E_USER_DEPRECATED);
128
+ }
129
+
130
+ $options = array_merge([
131
+ 'debug' => false,
132
+ 'charset' => 'UTF-8',
133
+ 'base_template_class' => '\Twig\Template',
134
+ 'strict_variables' => false,
135
+ 'autoescape' => 'html',
136
+ 'cache' => false,
137
+ 'auto_reload' => null,
138
+ 'optimizations' => -1,
139
+ ], $options);
140
+
141
+ $this->debug = (bool) $options['debug'];
142
+ $this->charset = strtoupper($options['charset']);
143
+ $this->baseTemplateClass = $options['base_template_class'];
144
+ $this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload'];
145
+ $this->strictVariables = (bool) $options['strict_variables'];
146
+ $this->setCache($options['cache']);
147
+
148
+ $this->addExtension(new CoreExtension());
149
+ $this->addExtension(new EscaperExtension($options['autoescape']));
150
+ $this->addExtension(new OptimizerExtension($options['optimizations']));
151
+ $this->staging = new StagingExtension();
152
+
153
+ // For BC
154
+ if (\is_string($this->originalCache)) {
155
+ $r = new \ReflectionMethod($this, 'writeCacheFile');
156
+ if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
157
+ @trigger_error('The Twig\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED);
158
+
159
+ $this->bcWriteCacheFile = true;
160
+ }
161
+
162
+ $r = new \ReflectionMethod($this, 'getCacheFilename');
163
+ if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
164
+ @trigger_error('The Twig\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED);
165
+
166
+ $this->bcGetCacheFilename = true;
167
+ }
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Gets the base template class for compiled templates.
173
+ *
174
+ * @return string The base template class name
175
+ */
176
+ public function getBaseTemplateClass()
177
+ {
178
+ return $this->baseTemplateClass;
179
+ }
180
+
181
+ /**
182
+ * Sets the base template class for compiled templates.
183
+ *
184
+ * @param string $class The base template class name
185
+ */
186
+ public function setBaseTemplateClass($class)
187
+ {
188
+ $this->baseTemplateClass = $class;
189
+ $this->updateOptionsHash();
190
+ }
191
+
192
+ /**
193
+ * Enables debugging mode.
194
+ */
195
+ public function enableDebug()
196
+ {
197
+ $this->debug = true;
198
+ $this->updateOptionsHash();
199
+ }
200
+
201
+ /**
202
+ * Disables debugging mode.
203
+ */
204
+ public function disableDebug()
205
+ {
206
+ $this->debug = false;
207
+ $this->updateOptionsHash();
208
+ }
209
+
210
+ /**
211
+ * Checks if debug mode is enabled.
212
+ *
213
+ * @return bool true if debug mode is enabled, false otherwise
214
+ */
215
+ public function isDebug()
216
+ {
217
+ return $this->debug;
218
+ }
219
+
220
+ /**
221
+ * Enables the auto_reload option.
222
+ */
223
+ public function enableAutoReload()
224
+ {
225
+ $this->autoReload = true;
226
+ }
227
+
228
+ /**
229
+ * Disables the auto_reload option.
230
+ */
231
+ public function disableAutoReload()
232
+ {
233
+ $this->autoReload = false;
234
+ }
235
+
236
+ /**
237
+ * Checks if the auto_reload option is enabled.
238
+ *
239
+ * @return bool true if auto_reload is enabled, false otherwise
240
+ */
241
+ public function isAutoReload()
242
+ {
243
+ return $this->autoReload;
244
+ }
245
+
246
+ /**
247
+ * Enables the strict_variables option.
248
+ */
249
+ public function enableStrictVariables()
250
+ {
251
+ $this->strictVariables = true;
252
+ $this->updateOptionsHash();
253
+ }
254
+
255
+ /**
256
+ * Disables the strict_variables option.
257
+ */
258
+ public function disableStrictVariables()
259
+ {
260
+ $this->strictVariables = false;
261
+ $this->updateOptionsHash();
262
+ }
263
+
264
+ /**
265
+ * Checks if the strict_variables option is enabled.
266
+ *
267
+ * @return bool true if strict_variables is enabled, false otherwise
268
+ */
269
+ public function isStrictVariables()
270
+ {
271
+ return $this->strictVariables;
272
+ }
273
+
274
+ /**
275
+ * Gets the current cache implementation.
276
+ *
277
+ * @param bool $original Whether to return the original cache option or the real cache instance
278
+ *
279
+ * @return CacheInterface|string|false A Twig\Cache\CacheInterface implementation,
280
+ * an absolute path to the compiled templates,
281
+ * or false to disable cache
282
+ */
283
+ public function getCache($original = true)
284
+ {
285
+ return $original ? $this->originalCache : $this->cache;
286
+ }
287
+
288
+ /**
289
+ * Sets the current cache implementation.
290
+ *
291
+ * @param CacheInterface|string|false $cache A Twig\Cache\CacheInterface implementation,
292
+ * an absolute path to the compiled templates,
293
+ * or false to disable cache
294
+ */
295
+ public function setCache($cache)
296
+ {
297
+ if (\is_string($cache)) {
298
+ $this->originalCache = $cache;
299
+ $this->cache = new FilesystemCache($cache);
300
+ } elseif (false === $cache) {
301
+ $this->originalCache = $cache;
302
+ $this->cache = new NullCache();
303
+ } elseif (null === $cache) {
304
+ @trigger_error('Using "null" as the cache strategy is deprecated since version 1.23 and will be removed in Twig 2.0.', E_USER_DEPRECATED);
305
+ $this->originalCache = false;
306
+ $this->cache = new NullCache();
307
+ } elseif ($cache instanceof CacheInterface) {
308
+ $this->originalCache = $this->cache = $cache;
309
+ } else {
310
+ throw new \LogicException(sprintf('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.'));
311
+ }
312
+ }
313
+
314
+ /**
315
+ * Gets the cache filename for a given template.
316
+ *
317
+ * @param string $name The template name
318
+ *
319
+ * @return string|false The cache file name or false when caching is disabled
320
+ *
321
+ * @deprecated since 1.22 (to be removed in 2.0)
322
+ */
323
+ public function getCacheFilename($name)
324
+ {
325
+ @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
326
+
327
+ $key = $this->cache->generateKey($name, $this->getTemplateClass($name));
328
+
329
+ return !$key ? false : $key;
330
+ }
331
+
332
+ /**
333
+ * Gets the template class associated with the given string.
334
+ *
335
+ * The generated template class is based on the following parameters:
336
+ *
337
+ * * The cache key for the given template;
338
+ * * The currently enabled extensions;
339
+ * * Whether the Twig C extension is available or not;
340
+ * * PHP version;
341
+ * * Twig version;
342
+ * * Options with what environment was created.
343
+ *
344
+ * @param string $name The name for which to calculate the template class name
345
+ * @param int|null $index The index if it is an embedded template
346
+ *
347
+ * @return string The template class name
348
+ */
349
+ public function getTemplateClass($name, $index = null)
350
+ {
351
+ $key = $this->getLoader()->getCacheKey($name).$this->optionsHash;
352
+
353
+ return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '___'.$index);
354
+ }
355
+
356
+ /**
357
+ * Gets the template class prefix.
358
+ *
359
+ * @return string The template class prefix
360
+ *
361
+ * @deprecated since 1.22 (to be removed in 2.0)
362
+ */
363
+ public function getTemplateClassPrefix()
364
+ {
365
+ @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
366
+
367
+ return $this->templateClassPrefix;
368
+ }
369
+
370
+ /**
371
+ * Renders a template.
372
+ *
373
+ * @param string|TemplateWrapper $name The template name
374
+ * @param array $context An array of parameters to pass to the template
375
+ *
376
+ * @return string The rendered template
377
+ *
378
+ * @throws LoaderError When the template cannot be found
379
+ * @throws SyntaxError When an error occurred during compilation
380
+ * @throws RuntimeError When an error occurred during rendering
381
+ */
382
+ public function render($name, array $context = [])
383
+ {
384
+ return $this->load($name)->render($context);
385
+ }
386
+
387
+ /**
388
+ * Displays a template.
389
+ *
390
+ * @param string|TemplateWrapper $name The template name
391
+ * @param array $context An array of parameters to pass to the template
392
+ *
393
+ * @throws LoaderError When the template cannot be found
394
+ * @throws SyntaxError When an error occurred during compilation
395
+ * @throws RuntimeError When an error occurred during rendering
396
+ */
397
+ public function display($name, array $context = [])
398
+ {
399
+ $this->load($name)->display($context);
400
+ }
401
+
402
+ /**
403
+ * Loads a template.
404
+ *
405
+ * @param string|TemplateWrapper|\Twig\Template $name The template name
406
+ *
407
+ * @throws LoaderError When the template cannot be found
408
+ * @throws RuntimeError When a previously generated cache is corrupted
409
+ * @throws SyntaxError When an error occurred during compilation
410
+ *
411
+ * @return TemplateWrapper
412
+ */
413
+ public function load($name)
414
+ {
415
+ if ($name instanceof TemplateWrapper) {
416
+ return $name;
417
+ }
418
+
419
+ if ($name instanceof Template) {
420
+ return new TemplateWrapper($this, $name);
421
+ }
422
+
423
+ return new TemplateWrapper($this, $this->loadTemplate($name));
424
+ }
425
+
426
+ /**
427
+ * Loads a template internal representation.
428
+ *
429
+ * This method is for internal use only and should never be called
430
+ * directly.
431
+ *
432
+ * @param string $name The template name
433
+ * @param int $index The index if it is an embedded template
434
+ *
435
+ * @return \Twig_TemplateInterface A template instance representing the given template name
436
+ *
437
+ * @throws LoaderError When the template cannot be found
438
+ * @throws RuntimeError When a previously generated cache is corrupted
439
+ * @throws SyntaxError When an error occurred during compilation
440
+ *
441
+ * @internal
442
+ */
443
+ public function loadTemplate($name, $index = null)
444
+ {
445
+ return $this->loadClass($this->getTemplateClass($name), $name, $index);
446
+ }
447
+
448
+ /**
449
+ * @internal
450
+ */
451
+ public function loadClass($cls, $name, $index = null)
452
+ {
453
+ $mainCls = $cls;
454
+ if (null !== $index) {
455
+ $cls .= '___'.$index;
456
+ }
457
+
458
+ if (isset($this->loadedTemplates[$cls])) {
459
+ return $this->loadedTemplates[$cls];
460
+ }
461
+
462
+ if (!class_exists($cls, false)) {
463
+ if ($this->bcGetCacheFilename) {
464
+ $key = $this->getCacheFilename($name);
465
+ } else {
466
+ $key = $this->cache->generateKey($name, $mainCls);
467
+ }
468
+
469
+ if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) {
470
+ $this->cache->load($key);
471
+ }
472
+
473
+ $source = null;
474
+ if (!class_exists($cls, false)) {
475
+ $loader = $this->getLoader();
476
+ if (!$loader instanceof SourceContextLoaderInterface) {
477
+ $source = new Source($loader->getSource($name), $name);
478
+ } else {
479
+ $source = $loader->getSourceContext($name);
480
+ }
481
+
482
+ $content = $this->compileSource($source);
483
+
484
+ if ($this->bcWriteCacheFile) {
485
+ $this->writeCacheFile($key, $content);
486
+ } else {
487
+ $this->cache->write($key, $content);
488
+ $this->cache->load($key);
489
+ }
490
+
491
+ if (!class_exists($mainCls, false)) {
492
+ /* Last line of defense if either $this->bcWriteCacheFile was used,
493
+ * $this->cache is implemented as a no-op or we have a race condition
494
+ * where the cache was cleared between the above calls to write to and load from
495
+ * the cache.
496
+ */
497
+ eval('?>'.$content);
498
+ }
499
+ }
500
+
501
+ if (!class_exists($cls, false)) {
502
+ throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.', $name, $index), -1, $source);
503
+ }
504
+ }
505
+
506
+ if (!$this->runtimeInitialized) {
507
+ $this->initRuntime();
508
+ }
509
+
510
+ return $this->loadedTemplates[$cls] = new $cls($this);
511
+ }
512
+
513
+ /**
514
+ * Creates a template from source.
515
+ *
516
+ * This method should not be used as a generic way to load templates.
517
+ *
518
+ * @param string $template The template name
519
+ * @param string $name An optional name of the template to be used in error messages
520
+ *
521
+ * @return TemplateWrapper A template instance representing the given template name
522
+ *
523
+ * @throws LoaderError When the template cannot be found
524
+ * @throws SyntaxError When an error occurred during compilation
525
+ */
526
+ public function createTemplate($template, $name = null)
527
+ {
528
+ $hash = hash('sha256', $template, false);
529
+ if (null !== $name) {
530
+ $name = sprintf('%s (string template %s)', $name, $hash);
531
+ } else {
532
+ $name = sprintf('__string_template__%s', $hash);
533
+ }
534
+
535
+ $loader = new ChainLoader([
536
+ new ArrayLoader([$name => $template]),
537
+ $current = $this->getLoader(),
538
+ ]);
539
+
540
+ $this->setLoader($loader);
541
+ try {
542
+ $template = new TemplateWrapper($this, $this->loadTemplate($name));
543
+ } catch (\Exception $e) {
544
+ $this->setLoader($current);
545
+
546
+ throw $e;
547
+ } catch (\Throwable $e) {
548
+ $this->setLoader($current);
549
+
550
+ throw $e;
551
+ }
552
+ $this->setLoader($current);
553
+
554
+ return $template;
555
+ }
556
+
557
+ /**
558
+ * Returns true if the template is still fresh.
559
+ *
560
+ * Besides checking the loader for freshness information,
561
+ * this method also checks if the enabled extensions have
562
+ * not changed.
563
+ *
564
+ * @param string $name The template name
565
+ * @param int $time The last modification time of the cached template
566
+ *
567
+ * @return bool true if the template is fresh, false otherwise
568
+ */
569
+ public function isTemplateFresh($name, $time)
570
+ {
571
+ if (0 === $this->lastModifiedExtension) {
572
+ foreach ($this->extensions as $extension) {
573
+ $r = new \ReflectionObject($extension);
574
+ if (file_exists($r->getFileName()) && ($extensionTime = filemtime($r->getFileName())) > $this->lastModifiedExtension) {
575
+ $this->lastModifiedExtension = $extensionTime;
576
+ }
577
+ }
578
+ }
579
+
580
+ return $this->lastModifiedExtension <= $time && $this->getLoader()->isFresh($name, $time);
581
+ }
582
+
583
+ /**
584
+ * Tries to load a template consecutively from an array.
585
+ *
586
+ * Similar to load() but it also accepts instances of \Twig\Template and
587
+ * \Twig\TemplateWrapper, and an array of templates where each is tried to be loaded.
588
+ *
589
+ * @param string|Template|\Twig\TemplateWrapper|array $names A template or an array of templates to try consecutively
590
+ *
591
+ * @return TemplateWrapper|Template
592
+ *
593
+ * @throws LoaderError When none of the templates can be found
594
+ * @throws SyntaxError When an error occurred during compilation
595
+ */
596
+ public function resolveTemplate($names)
597
+ {
598
+ if (!\is_array($names)) {
599
+ $names = [$names];
600
+ }
601
+
602
+ foreach ($names as $name) {
603
+ if ($name instanceof Template) {
604
+ return $name;
605
+ }
606
+ if ($name instanceof TemplateWrapper) {
607
+ return $name;
608
+ }
609
+
610
+ try {
611
+ return $this->loadTemplate($name);
612
+ } catch (LoaderError $e) {
613
+ if (1 === \count($names)) {
614
+ throw $e;
615
+ }
616
+ }
617
+ }
618
+
619
+ throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names)));
620
+ }
621
+
622
+ /**
623
+ * Clears the internal template cache.
624
+ *
625
+ * @deprecated since 1.18.3 (to be removed in 2.0)
626
+ */
627
+ public function clearTemplateCache()
628
+ {
629
+ @trigger_error(sprintf('The %s method is deprecated since version 1.18.3 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
630
+
631
+ $this->loadedTemplates = [];
632
+ }
633
+
634
+ /**
635
+ * Clears the template cache files on the filesystem.
636
+ *
637
+ * @deprecated since 1.22 (to be removed in 2.0)
638
+ */
639
+ public function clearCacheFiles()
640
+ {
641
+ @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
642
+
643
+ if (\is_string($this->originalCache)) {
644
+ foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->originalCache), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
645
+ if ($file->isFile()) {
646
+ @unlink($file->getPathname());
647
+ }
648
+ }
649
+ }
650
+ }
651
+
652
+ /**
653
+ * Gets the Lexer instance.
654
+ *
655
+ * @return \Twig_LexerInterface
656
+ *
657
+ * @deprecated since 1.25 (to be removed in 2.0)
658
+ */
659
+ public function getLexer()
660
+ {
661
+ @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
662
+
663
+ if (null === $this->lexer) {
664
+ $this->lexer = new Lexer($this);
665
+ }
666
+
667
+ return $this->lexer;
668
+ }
669
+
670
+ public function setLexer(\Twig_LexerInterface $lexer)
671
+ {
672
+ $this->lexer = $lexer;
673
+ }
674
+
675
+ /**
676
+ * Tokenizes a source code.
677
+ *
678
+ * @param string|Source $source The template source code
679
+ * @param string $name The template name (deprecated)
680
+ *
681
+ * @return TokenStream
682
+ *
683
+ * @throws SyntaxError When the code is syntactically wrong
684
+ */
685
+ public function tokenize($source, $name = null)
686
+ {
687
+ if (!$source instanceof Source) {
688
+ @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED);
689
+ $source = new Source($source, $name);
690
+ }
691
+
692
+ if (null === $this->lexer) {
693
+ $this->lexer = new Lexer($this);
694
+ }
695
+
696
+ return $this->lexer->tokenize($source);
697
+ }
698
+
699
+ /**
700
+ * Gets the Parser instance.
701
+ *
702
+ * @return \Twig_ParserInterface
703
+ *
704
+ * @deprecated since 1.25 (to be removed in 2.0)
705
+ */
706
+ public function getParser()
707
+ {
708
+ @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
709
+
710
+ if (null === $this->parser) {
711
+ $this->parser = new Parser($this);
712
+ }
713
+
714
+ return $this->parser;
715
+ }
716
+
717
+ public function setParser(\Twig_ParserInterface $parser)
718
+ {
719
+ $this->parser = $parser;
720
+ }
721
+
722
+ /**
723
+ * Converts a token stream to a node tree.
724
+ *
725
+ * @return ModuleNode
726
+ *
727
+ * @throws SyntaxError When the token stream is syntactically or semantically wrong
728
+ */
729
+ public function parse(TokenStream $stream)
730
+ {
731
+ if (null === $this->parser) {
732
+ $this->parser = new Parser($this);
733
+ }
734
+
735
+ return $this->parser->parse($stream);
736
+ }
737
+
738
+ /**
739
+ * Gets the Compiler instance.
740
+ *
741
+ * @return \Twig_CompilerInterface
742
+ *
743
+ * @deprecated since 1.25 (to be removed in 2.0)
744
+ */
745
+ public function getCompiler()
746
+ {
747
+ @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
748
+
749
+ if (null === $this->compiler) {
750
+ $this->compiler = new Compiler($this);
751
+ }
752
+
753
+ return $this->compiler;
754
+ }
755
+
756
+ public function setCompiler(\Twig_CompilerInterface $compiler)
757
+ {
758
+ $this->compiler = $compiler;
759
+ }
760
+
761
+ /**
762
+ * Compiles a node and returns the PHP code.
763
+ *
764
+ * @return string The compiled PHP source code
765
+ */
766
+ public function compile(\Twig_NodeInterface $node)
767
+ {
768
+ if (null === $this->compiler) {
769
+ $this->compiler = new Compiler($this);
770
+ }
771
+
772
+ return $this->compiler->compile($node)->getSource();
773
+ }
774
+
775
+ /**
776
+ * Compiles a template source code.
777
+ *
778
+ * @param string|Source $source The template source code
779
+ * @param string $name The template name (deprecated)
780
+ *
781
+ * @return string The compiled PHP source code
782
+ *
783
+ * @throws SyntaxError When there was an error during tokenizing, parsing or compiling
784
+ */
785
+ public function compileSource($source, $name = null)
786
+ {
787
+ if (!$source instanceof Source) {
788
+ @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED);
789
+ $source = new Source($source, $name);
790
+ }
791
+
792
+ try {
793
+ return $this->compile($this->parse($this->tokenize($source)));
794
+ } catch (Error $e) {
795
+ $e->setSourceContext($source);
796
+ throw $e;
797
+ } catch (\Exception $e) {
798
+ throw new SyntaxError(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e);
799
+ }
800
+ }
801
+
802
+ public function setLoader(LoaderInterface $loader)
803
+ {
804
+ if (!$loader instanceof SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) {
805
+ @trigger_error(sprintf('Twig loader "%s" should implement Twig\Loader\SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED);
806
+ }
807
+
808
+ $this->loader = $loader;
809
+ }
810
+
811
+ /**
812
+ * Gets the Loader instance.
813
+ *
814
+ * @return LoaderInterface
815
+ */
816
+ public function getLoader()
817
+ {
818
+ if (null === $this->loader) {
819
+ throw new \LogicException('You must set a loader first.');
820
+ }
821
+
822
+ return $this->loader;
823
+ }
824
+
825
+ /**
826
+ * Sets the default template charset.
827
+ *
828
+ * @param string $charset The default charset
829
+ */
830
+ public function setCharset($charset)
831
+ {
832
+ $this->charset = strtoupper($charset);
833
+ }
834
+
835
+ /**
836
+ * Gets the default template charset.
837
+ *
838
+ * @return string The default charset
839
+ */
840
+ public function getCharset()
841
+ {
842
+ return $this->charset;
843
+ }
844
+
845
+ /**
846
+ * Initializes the runtime environment.
847
+ *
848
+ * @deprecated since 1.23 (to be removed in 2.0)
849
+ */
850
+ public function initRuntime()
851
+ {
852
+ $this->runtimeInitialized = true;
853
+
854
+ foreach ($this->getExtensions() as $name => $extension) {
855
+ if (!$extension instanceof InitRuntimeInterface) {
856
+ $m = new \ReflectionMethod($extension, 'initRuntime');
857
+
858
+ $parentClass = $m->getDeclaringClass()->getName();
859
+ if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) {
860
+ @trigger_error(sprintf('Defining the initRuntime() method in the "%s" extension is deprecated since version 1.23. Use the `needs_environment` option to get the \Twig_Environment instance in filters, functions, or tests; or explicitly implement Twig\Extension\InitRuntimeInterface if needed (not recommended).', $name), E_USER_DEPRECATED);
861
+ }
862
+ }
863
+
864
+ $extension->initRuntime($this);
865
+ }
866
+ }
867
+
868
+ /**
869
+ * Returns true if the given extension is registered.
870
+ *
871
+ * @param string $class The extension class name
872
+ *
873
+ * @return bool Whether the extension is registered or not
874
+ */
875
+ public function hasExtension($class)
876
+ {
877
+ $class = ltrim($class, '\\');
878
+ if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) {
879
+ // For BC/FC with namespaced aliases
880
+ $class = new \ReflectionClass($class);
881
+ $class = $class->name;
882
+ }
883
+
884
+ if (isset($this->extensions[$class])) {
885
+ if ($class !== \get_class($this->extensions[$class])) {
886
+ @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
887
+ }
888
+
889
+ return true;
890
+ }
891
+
892
+ return isset($this->extensionsByClass[$class]);
893
+ }
894
+
895
+ /**
896
+ * Adds a runtime loader.
897
+ */
898
+ public function addRuntimeLoader(RuntimeLoaderInterface $loader)
899
+ {
900
+ $this->runtimeLoaders[] = $loader;
901
+ }
902
+
903
+ /**
904
+ * Gets an extension by class name.
905
+ *
906
+ * @param string $class The extension class name
907
+ *
908
+ * @return ExtensionInterface
909
+ */
910
+ public function getExtension($class)
911
+ {
912
+ $class = ltrim($class, '\\');
913
+ if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) {
914
+ // For BC/FC with namespaced aliases
915
+ $class = new \ReflectionClass($class);
916
+ $class = $class->name;
917
+ }
918
+
919
+ if (isset($this->extensions[$class])) {
920
+ if ($class !== \get_class($this->extensions[$class])) {
921
+ @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
922
+ }
923
+
924
+ return $this->extensions[$class];
925
+ }
926
+
927
+ if (!isset($this->extensionsByClass[$class])) {
928
+ throw new RuntimeError(sprintf('The "%s" extension is not enabled.', $class));
929
+ }
930
+
931
+ return $this->extensionsByClass[$class];
932
+ }
933
+
934
+ /**
935
+ * Returns the runtime implementation of a Twig element (filter/function/test).
936
+ *
937
+ * @param string $class A runtime class name
938
+ *
939
+ * @return object The runtime implementation
940
+ *
941
+ * @throws RuntimeError When the template cannot be found
942
+ */
943
+ public function getRuntime($class)
944
+ {
945
+ if (isset($this->runtimes[$class])) {
946
+ return $this->runtimes[$class];
947
+ }
948
+
949
+ foreach ($this->runtimeLoaders as $loader) {
950
+ if (null !== $runtime = $loader->load($class)) {
951
+ return $this->runtimes[$class] = $runtime;
952
+ }
953
+ }
954
+
955
+ throw new RuntimeError(sprintf('Unable to load the "%s" runtime.', $class));
956
+ }
957
+
958
+ public function addExtension(ExtensionInterface $extension)
959
+ {
960
+ if ($this->extensionInitialized) {
961
+ throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName()));
962
+ }
963
+
964
+ $class = \get_class($extension);
965
+ if ($class !== $extension->getName()) {
966
+ if (isset($this->extensions[$extension->getName()])) {
967
+ unset($this->extensions[$extension->getName()], $this->extensionsByClass[$class]);
968
+ @trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated since version 1.23 and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $extension->getName()), E_USER_DEPRECATED);
969
+ }
970
+ }
971
+
972
+ $this->lastModifiedExtension = 0;
973
+ $this->extensionsByClass[$class] = $extension;
974
+ $this->extensions[$extension->getName()] = $extension;
975
+ $this->updateOptionsHash();
976
+ }
977
+
978
+ /**
979
+ * Removes an extension by name.
980
+ *
981
+ * This method is deprecated and you should not use it.
982
+ *
983
+ * @param string $name The extension name
984
+ *
985
+ * @deprecated since 1.12 (to be removed in 2.0)
986
+ */
987
+ public function removeExtension($name)
988
+ {
989
+ @trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
990
+
991
+ if ($this->extensionInitialized) {
992
+ throw new \LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name));
993
+ }
994
+
995
+ $class = ltrim($name, '\\');
996
+ if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) {
997
+ // For BC/FC with namespaced aliases
998
+ $class = new \ReflectionClass($class);
999
+ $class = $class->name;
1000
+ }
1001
+
1002
+ if (isset($this->extensions[$class])) {
1003
+ if ($class !== \get_class($this->extensions[$class])) {
1004
+ @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
1005
+ }
1006
+
1007
+ unset($this->extensions[$class]);
1008
+ }
1009
+
1010
+ unset($this->extensions[$class]);
1011
+ $this->updateOptionsHash();
1012
+ }
1013
+
1014
+ /**
1015
+ * Registers an array of extensions.
1016
+ *
1017
+ * @param array $extensions An array of extensions
1018
+ */
1019
+ public function setExtensions(array $extensions)
1020
+ {
1021
+ foreach ($extensions as $extension) {
1022
+ $this->addExtension($extension);
1023
+ }
1024
+ }
1025
+
1026
+ /**
1027
+ * Returns all registered extensions.
1028
+ *
1029
+ * @return ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on)
1030
+ */
1031
+ public function getExtensions()
1032
+ {
1033
+ return $this->extensions;
1034
+ }
1035
+
1036
+ public function addTokenParser(TokenParserInterface $parser)
1037
+ {
1038
+ if ($this->extensionInitialized) {
1039
+ throw new \LogicException('Unable to add a token parser as extensions have already been initialized.');
1040
+ }
1041
+
1042
+ $this->staging->addTokenParser($parser);
1043
+ }
1044
+
1045
+ /**
1046
+ * Gets the registered Token Parsers.
1047
+ *
1048
+ * @return \Twig_TokenParserBrokerInterface
1049
+ *
1050
+ * @internal
1051
+ */
1052
+ public function getTokenParsers()
1053
+ {
1054
+ if (!$this->extensionInitialized) {
1055
+ $this->initExtensions();
1056
+ }
1057
+
1058
+ return $this->parsers;
1059
+ }
1060
+
1061
+ /**
1062
+ * Gets registered tags.
1063
+ *
1064
+ * Be warned that this method cannot return tags defined by \Twig_TokenParserBrokerInterface classes.
1065
+ *
1066
+ * @return TokenParserInterface[]
1067
+ *
1068
+ * @internal
1069
+ */
1070
+ public function getTags()
1071
+ {
1072
+ $tags = [];
1073
+ foreach ($this->getTokenParsers()->getParsers() as $parser) {
1074
+ if ($parser instanceof TokenParserInterface) {
1075
+ $tags[$parser->getTag()] = $parser;
1076
+ }
1077
+ }
1078
+
1079
+ return $tags;
1080
+ }
1081
+
1082
+ public function addNodeVisitor(NodeVisitorInterface $visitor)
1083
+ {
1084
+ if ($this->extensionInitialized) {
1085
+ throw new \LogicException('Unable to add a node visitor as extensions have already been initialized.');
1086
+ }
1087
+
1088
+ $this->staging->addNodeVisitor($visitor);
1089
+ }
1090
+
1091
+ /**
1092
+ * Gets the registered Node Visitors.
1093
+ *
1094
+ * @return NodeVisitorInterface[]
1095
+ *
1096
+ * @internal
1097
+ */
1098
+ public function getNodeVisitors()
1099
+ {
1100
+ if (!$this->extensionInitialized) {
1101
+ $this->initExtensions();
1102
+ }
1103
+
1104
+ return $this->visitors;
1105
+ }
1106
+
1107
+ /**
1108
+ * Registers a Filter.
1109
+ *
1110
+ * @param string|TwigFilter $name The filter name or a \Twig_SimpleFilter instance
1111
+ * @param \Twig_FilterInterface|TwigFilter $filter
1112
+ */
1113
+ public function addFilter($name, $filter = null)
1114
+ {
1115
+ if (!$name instanceof TwigFilter && !($filter instanceof TwigFilter || $filter instanceof \Twig_FilterInterface)) {
1116
+ throw new \LogicException('A filter must be an instance of \Twig_FilterInterface or \Twig_SimpleFilter.');
1117
+ }
1118
+
1119
+ if ($name instanceof TwigFilter) {
1120
+ $filter = $name;
1121
+ $name = $filter->getName();
1122
+ } else {
1123
+ @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".', __METHOD__, $name), E_USER_DEPRECATED);
1124
+ }
1125
+
1126
+ if ($this->extensionInitialized) {
1127
+ throw new \LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $name));
1128
+ }
1129
+
1130
+ $this->staging->addFilter($name, $filter);
1131
+ }
1132
+
1133
+ /**
1134
+ * Get a filter by name.
1135
+ *
1136
+ * Subclasses may override this method and load filters differently;
1137
+ * so no list of filters is available.
1138
+ *
1139
+ * @param string $name The filter name
1140
+ *
1141
+ * @return \Twig_Filter|false
1142
+ *
1143
+ * @internal
1144
+ */
1145
+ public function getFilter($name)
1146
+ {
1147
+ if (!$this->extensionInitialized) {
1148
+ $this->initExtensions();
1149
+ }
1150
+
1151
+ if (isset($this->filters[$name])) {
1152
+ return $this->filters[$name];
1153
+ }
1154
+
1155
+ foreach ($this->filters as $pattern => $filter) {
1156
+ $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count);
1157
+
1158
+ if ($count) {
1159
+ if (preg_match('#^'.$pattern.'$#', $name, $matches)) {
1160
+ array_shift($matches);
1161
+ $filter->setArguments($matches);
1162
+
1163
+ return $filter;
1164
+ }
1165
+ }
1166
+ }
1167
+
1168
+ foreach ($this->filterCallbacks as $callback) {
1169
+ if (false !== $filter = \call_user_func($callback, $name)) {
1170
+ return $filter;
1171
+ }
1172
+ }
1173
+
1174
+ return false;
1175
+ }
1176
+
1177
+ public function registerUndefinedFilterCallback($callable)
1178
+ {
1179
+ $this->filterCallbacks[] = $callable;
1180
+ }
1181
+
1182
+ /**
1183
+ * Gets the registered Filters.
1184
+ *
1185
+ * Be warned that this method cannot return filters defined with registerUndefinedFilterCallback.
1186
+ *
1187
+ * @return \Twig_FilterInterface[]
1188
+ *
1189
+ * @see registerUndefinedFilterCallback
1190
+ *
1191
+ * @internal
1192
+ */
1193
+ public function getFilters()
1194
+ {
1195
+ if (!$this->extensionInitialized) {
1196
+ $this->initExtensions();
1197
+ }
1198
+
1199
+ return $this->filters;
1200
+ }
1201
+
1202
+ /**
1203
+ * Registers a Test.
1204
+ *
1205
+ * @param string|TwigTest $name The test name or a \Twig_SimpleTest instance
1206
+ * @param \Twig_TestInterface|TwigTest $test A \Twig_TestInterface instance or a \Twig_SimpleTest instance
1207
+ */
1208
+ public function addTest($name, $test = null)
1209
+ {
1210
+ if (!$name instanceof TwigTest && !($test instanceof TwigTest || $test instanceof \Twig_TestInterface)) {
1211
+ throw new \LogicException('A test must be an instance of \Twig_TestInterface or \Twig_SimpleTest.');
1212
+ }
1213
+
1214
+ if ($name instanceof TwigTest) {
1215
+ $test = $name;
1216
+ $name = $test->getName();
1217
+ } else {
1218
+ @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__, $name), E_USER_DEPRECATED);
1219
+ }
1220
+
1221
+ if ($this->extensionInitialized) {
1222
+ throw new \LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name));
1223
+ }
1224
+
1225
+ $this->staging->addTest($name, $test);
1226
+ }
1227
+
1228
+ /**
1229
+ * Gets the registered Tests.
1230
+ *
1231
+ * @return \Twig_TestInterface[]
1232
+ *
1233
+ * @internal
1234
+ */
1235
+ public function getTests()
1236
+ {
1237
+ if (!$this->extensionInitialized) {
1238
+ $this->initExtensions();
1239
+ }
1240
+
1241
+ return $this->tests;
1242
+ }
1243
+
1244
+ /**
1245
+ * Gets a test by name.
1246
+ *
1247
+ * @param string $name The test name
1248
+ *
1249
+ * @return \Twig_Test|false
1250
+ *
1251
+ * @internal
1252
+ */
1253
+ public function getTest($name)
1254
+ {
1255
+ if (!$this->extensionInitialized) {
1256
+ $this->initExtensions();
1257
+ }
1258
+
1259
+ if (isset($this->tests[$name])) {
1260
+ return $this->tests[$name];
1261
+ }
1262
+
1263
+ foreach ($this->tests as $pattern => $test) {
1264
+ $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count);
1265
+
1266
+ if ($count) {
1267
+ if (preg_match('#^'.$pattern.'$#', $name, $matches)) {
1268
+ array_shift($matches);
1269
+ $test->setArguments($matches);
1270
+
1271
+ return $test;
1272
+ }
1273
+ }
1274
+ }
1275
+
1276
+ return false;
1277
+ }
1278
+
1279
+ /**
1280
+ * Registers a Function.
1281
+ *
1282
+ * @param string|TwigFunction $name The function name or a \Twig_SimpleFunction instance
1283
+ * @param \Twig_FunctionInterface|TwigFunction $function
1284
+ */
1285
+ public function addFunction($name, $function = null)
1286
+ {
1287
+ if (!$name instanceof TwigFunction && !($function instanceof TwigFunction || $function instanceof \Twig_FunctionInterface)) {
1288
+ throw new \LogicException('A function must be an instance of \Twig_FunctionInterface or \Twig_SimpleFunction.');
1289
+ }
1290
+
1291
+ if ($name instanceof TwigFunction) {
1292
+ $function = $name;
1293
+ $name = $function->getName();
1294
+ } else {
1295
+ @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), E_USER_DEPRECATED);
1296
+ }
1297
+
1298
+ if ($this->extensionInitialized) {
1299
+ throw new \LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name));
1300
+ }
1301
+
1302
+ $this->staging->addFunction($name, $function);
1303
+ }
1304
+
1305
+ /**
1306
+ * Get a function by name.
1307
+ *
1308
+ * Subclasses may override this method and load functions differently;
1309
+ * so no list of functions is available.
1310
+ *
1311
+ * @param string $name function name
1312
+ *
1313
+ * @return \Twig_Function|false
1314
+ *
1315
+ * @internal
1316
+ */
1317
+ public function getFunction($name)
1318
+ {
1319
+ if (!$this->extensionInitialized) {
1320
+ $this->initExtensions();
1321
+ }
1322
+
1323
+ if (isset($this->functions[$name])) {
1324
+ return $this->functions[$name];
1325
+ }
1326
+
1327
+ foreach ($this->functions as $pattern => $function) {
1328
+ $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count);
1329
+
1330
+ if ($count) {
1331
+ if (preg_match('#^'.$pattern.'$#', $name, $matches)) {
1332
+ array_shift($matches);
1333
+ $function->setArguments($matches);
1334
+
1335
+ return $function;
1336
+ }
1337
+ }
1338
+ }
1339
+
1340
+ foreach ($this->functionCallbacks as $callback) {
1341
+ if (false !== $function = \call_user_func($callback, $name)) {
1342
+ return $function;
1343
+ }
1344
+ }
1345
+
1346
+ return false;
1347
+ }
1348
+
1349
+ public function registerUndefinedFunctionCallback($callable)
1350
+ {
1351
+ $this->functionCallbacks[] = $callable;
1352
+ }
1353
+
1354
+ /**
1355
+ * Gets registered functions.
1356
+ *
1357
+ * Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback.
1358
+ *
1359
+ * @return \Twig_FunctionInterface[]
1360
+ *
1361
+ * @see registerUndefinedFunctionCallback
1362
+ *
1363
+ * @internal
1364
+ */
1365
+ public function getFunctions()
1366
+ {
1367
+ if (!$this->extensionInitialized) {
1368
+ $this->initExtensions();
1369
+ }
1370
+
1371
+ return $this->functions;
1372
+ }
1373
+
1374
+ /**
1375
+ * Registers a Global.
1376
+ *
1377
+ * New globals can be added before compiling or rendering a template;
1378
+ * but after, you can only update existing globals.
1379
+ *
1380
+ * @param string $name The global name
1381
+ * @param mixed $value The global value
1382
+ */
1383
+ public function addGlobal($name, $value)
1384
+ {
1385
+ if ($this->extensionInitialized || $this->runtimeInitialized) {
1386
+ if (null === $this->globals) {
1387
+ $this->globals = $this->initGlobals();
1388
+ }
1389
+
1390
+ if (!\array_key_exists($name, $this->globals)) {
1391
+ // The deprecation notice must be turned into the following exception in Twig 2.0
1392
+ @trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated since version 1.21.', $name), E_USER_DEPRECATED);
1393
+ //throw new \LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name));
1394
+ }
1395
+ }
1396
+
1397
+ if ($this->extensionInitialized || $this->runtimeInitialized) {
1398
+ // update the value
1399
+ $this->globals[$name] = $value;
1400
+ } else {
1401
+ $this->staging->addGlobal($name, $value);
1402
+ }
1403
+ }
1404
+
1405
+ /**
1406
+ * Gets the registered Globals.
1407
+ *
1408
+ * @return array An array of globals
1409
+ *
1410
+ * @internal
1411
+ */
1412
+ public function getGlobals()
1413
+ {
1414
+ if (!$this->runtimeInitialized && !$this->extensionInitialized) {
1415
+ return $this->initGlobals();
1416
+ }
1417
+
1418
+ if (null === $this->globals) {
1419
+ $this->globals = $this->initGlobals();
1420
+ }
1421
+
1422
+ return $this->globals;
1423
+ }
1424
+
1425
+ /**
1426
+ * Merges a context with the defined globals.
1427
+ *
1428
+ * @param array $context An array representing the context
1429
+ *
1430
+ * @return array The context merged with the globals
1431
+ */
1432
+ public function mergeGlobals(array $context)
1433
+ {
1434
+ // we don't use array_merge as the context being generally
1435
+ // bigger than globals, this code is faster.
1436
+ foreach ($this->getGlobals() as $key => $value) {
1437
+ if (!\array_key_exists($key, $context)) {
1438
+ $context[$key] = $value;
1439
+ }
1440
+ }
1441
+
1442
+ return $context;
1443
+ }
1444
+
1445
+ /**
1446
+ * Gets the registered unary Operators.
1447
+ *
1448
+ * @return array An array of unary operators
1449
+ *
1450
+ * @internal
1451
+ */
1452
+ public function getUnaryOperators()
1453
+ {
1454
+ if (!$this->extensionInitialized) {
1455
+ $this->initExtensions();
1456
+ }
1457
+
1458
+ return $this->unaryOperators;
1459
+ }
1460
+
1461
+ /**
1462
+ * Gets the registered binary Operators.
1463
+ *
1464
+ * @return array An array of binary operators
1465
+ *
1466
+ * @internal
1467
+ */
1468
+ public function getBinaryOperators()
1469
+ {
1470
+ if (!$this->extensionInitialized) {
1471
+ $this->initExtensions();
1472
+ }
1473
+
1474
+ return $this->binaryOperators;
1475
+ }
1476
+
1477
+ /**
1478
+ * @deprecated since 1.23 (to be removed in 2.0)
1479
+ */
1480
+ public function computeAlternatives($name, $items)
1481
+ {
1482
+ @trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
1483
+
1484
+ return SyntaxError::computeAlternatives($name, $items);
1485
+ }
1486
+
1487
+ /**
1488
+ * @internal
1489
+ */
1490
+ protected function initGlobals()
1491
+ {
1492
+ $globals = [];
1493
+ foreach ($this->extensions as $name => $extension) {
1494
+ if (!$extension instanceof GlobalsInterface) {
1495
+ $m = new \ReflectionMethod($extension, 'getGlobals');
1496
+
1497
+ $parentClass = $m->getDeclaringClass()->getName();
1498
+ if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) {
1499
+ @trigger_error(sprintf('Defining the getGlobals() method in the "%s" extension without explicitly implementing Twig\Extension\GlobalsInterface is deprecated since version 1.23.', $name), E_USER_DEPRECATED);
1500
+ }
1501
+ }
1502
+
1503
+ $extGlob = $extension->getGlobals();
1504
+ if (!\is_array($extGlob)) {
1505
+ throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension)));
1506
+ }
1507
+
1508
+ $globals[] = $extGlob;
1509
+ }
1510
+
1511
+ $globals[] = $this->staging->getGlobals();
1512
+
1513
+ return \call_user_func_array('array_merge', $globals);
1514
+ }
1515
+
1516
+ /**
1517
+ * @internal
1518
+ */
1519
+ protected function initExtensions()
1520
+ {
1521
+ if ($this->extensionInitialized) {
1522
+ return;
1523
+ }
1524
+
1525
+ $this->parsers = new \Twig_TokenParserBroker([], [], false);
1526
+ $this->filters = [];
1527
+ $this->functions = [];
1528
+ $this->tests = [];
1529
+ $this->visitors = [];
1530
+ $this->unaryOperators = [];
1531
+ $this->binaryOperators = [];
1532
+
1533
+ foreach ($this->extensions as $extension) {
1534
+ $this->initExtension($extension);
1535
+ }
1536
+ $this->initExtension($this->staging);
1537
+ // Done at the end only, so that an exception during initialization does not mark the environment as initialized when catching the exception
1538
+ $this->extensionInitialized = true;
1539
+ }
1540
+
1541
+ /**
1542
+ * @internal
1543
+ */
1544
+ protected function initExtension(ExtensionInterface $extension)
1545
+ {
1546
+ // filters
1547
+ foreach ($extension->getFilters() as $name => $filter) {
1548
+ if ($filter instanceof TwigFilter) {
1549
+ $name = $filter->getName();
1550
+ } else {
1551
+ @trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated since version 1.21. Use \Twig_SimpleFilter instead.', \get_class($filter), $name), E_USER_DEPRECATED);
1552
+ }
1553
+
1554
+ $this->filters[$name] = $filter;
1555
+ }
1556
+
1557
+ // functions
1558
+ foreach ($extension->getFunctions() as $name => $function) {
1559
+ if ($function instanceof TwigFunction) {
1560
+ $name = $function->getName();
1561
+ } else {
1562
+ @trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated since version 1.21. Use \Twig_SimpleFunction instead.', \get_class($function), $name), E_USER_DEPRECATED);
1563
+ }
1564
+
1565
+ $this->functions[$name] = $function;
1566
+ }
1567
+
1568
+ // tests
1569
+ foreach ($extension->getTests() as $name => $test) {
1570
+ if ($test instanceof TwigTest) {
1571
+ $name = $test->getName();
1572
+ } else {
1573
+ @trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated since version 1.21. Use \Twig_SimpleTest instead.', \get_class($test), $name), E_USER_DEPRECATED);
1574
+ }
1575
+
1576
+ $this->tests[$name] = $test;
1577
+ }
1578
+
1579
+ // token parsers
1580
+ foreach ($extension->getTokenParsers() as $parser) {
1581
+ if ($parser instanceof TokenParserInterface) {
1582
+ $this->parsers->addTokenParser($parser);
1583
+ } elseif ($parser instanceof \Twig_TokenParserBrokerInterface) {
1584
+ @trigger_error('Registering a \Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', E_USER_DEPRECATED);
1585
+
1586
+ $this->parsers->addTokenParserBroker($parser);
1587
+ } else {
1588
+ throw new \LogicException('getTokenParsers() must return an array of \Twig_TokenParserInterface or \Twig_TokenParserBrokerInterface instances.');
1589
+ }
1590
+ }
1591
+
1592
+ // node visitors
1593
+ foreach ($extension->getNodeVisitors() as $visitor) {
1594
+ $this->visitors[] = $visitor;
1595
+ }
1596
+
1597
+ // operators
1598
+ if ($operators = $extension->getOperators()) {
1599
+ if (!\is_array($operators)) {
1600
+ throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array with operators, got "%s".', \get_class($extension), \is_object($operators) ? \get_class($operators) : \gettype($operators).(\is_resource($operators) ? '' : '#'.$operators)));
1601
+ }
1602
+
1603
+ if (2 !== \count($operators)) {
1604
+ throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators)));
1605
+ }
1606
+
1607
+ $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]);
1608
+ $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]);
1609
+ }
1610
+ }
1611
+
1612
+ /**
1613
+ * @deprecated since 1.22 (to be removed in 2.0)
1614
+ */
1615
+ protected function writeCacheFile($file, $content)
1616
+ {
1617
+ $this->cache->write($file, $content);
1618
+ }
1619
+
1620
+ private function updateOptionsHash()
1621
+ {
1622
+ $hashParts = array_merge(
1623
+ array_keys($this->extensions),
1624
+ [
1625
+ (int) \function_exists('twig_template_get_attributes'),
1626
+ PHP_MAJOR_VERSION,
1627
+ PHP_MINOR_VERSION,
1628
+ self::VERSION,
1629
+ (int) $this->debug,
1630
+ $this->baseTemplateClass,
1631
+ (int) $this->strictVariables,
1632
+ ]
1633
+ );
1634
+ $this->optionsHash = implode(':', $hashParts);
1635
+ }
1636
+ }
1637
+
1638
+ class_alias('Twig\Environment', 'Twig_Environment');
vendor/twig/twig/src/Error/Error.php ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Error;
13
+
14
+ use Twig\Source;
15
+ use Twig\Template;
16
+
17
+ /**
18
+ * Twig base exception.
19
+ *
20
+ * This exception class and its children must only be used when
21
+ * an error occurs during the loading of a template, when a syntax error
22
+ * is detected in a template, or when rendering a template. Other
23
+ * errors must use regular PHP exception classes (like when the template
24
+ * cache directory is not writable for instance).
25
+ *
26
+ * To help debugging template issues, this class tracks the original template
27
+ * name and line where the error occurred.
28
+ *
29
+ * Whenever possible, you must set these information (original template name
30
+ * and line number) yourself by passing them to the constructor. If some or all
31
+ * these information are not available from where you throw the exception, then
32
+ * this class will guess them automatically (when the line number is set to -1
33
+ * and/or the name is set to null). As this is a costly operation, this
34
+ * can be disabled by passing false for both the name and the line number
35
+ * when creating a new instance of this class.
36
+ *
37
+ * @author Fabien Potencier <fabien@symfony.com>
38
+ */
39
+ class Error extends \Exception
40
+ {
41
+ protected $lineno;
42
+ // to be renamed to name in 2.0
43
+ protected $filename;
44
+ protected $rawMessage;
45
+
46
+ private $sourcePath;
47
+ private $sourceCode;
48
+
49
+ /**
50
+ * Constructor.
51
+ *
52
+ * Set the line number to -1 to enable its automatic guessing.
53
+ * Set the name to null to enable its automatic guessing.
54
+ *
55
+ * @param string $message The error message
56
+ * @param int $lineno The template line where the error occurred
57
+ * @param Source|string|null $source The source context where the error occurred
58
+ * @param \Exception $previous The previous exception
59
+ */
60
+ public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null)
61
+ {
62
+ if (null === $source) {
63
+ $name = null;
64
+ } elseif (!$source instanceof Source) {
65
+ // for compat with the Twig C ext., passing the template name as string is accepted
66
+ $name = $source;
67
+ } else {
68
+ $name = $source->getName();
69
+ $this->sourceCode = $source->getCode();
70
+ $this->sourcePath = $source->getPath();
71
+ }
72
+ parent::__construct('', 0, $previous);
73
+
74
+ $this->lineno = $lineno;
75
+ $this->filename = $name;
76
+ $this->rawMessage = $message;
77
+ $this->updateRepr();
78
+ }
79
+
80
+ /**
81
+ * Gets the raw message.
82
+ *
83
+ * @return string The raw message
84
+ */
85
+ public function getRawMessage()
86
+ {
87
+ return $this->rawMessage;
88
+ }
89
+
90
+ /**
91
+ * Gets the logical name where the error occurred.
92
+ *
93
+ * @return string The name
94
+ *
95
+ * @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead.
96
+ */
97
+ public function getTemplateFile()
98
+ {
99
+ @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
100
+
101
+ return $this->filename;
102
+ }
103
+
104
+ /**
105
+ * Sets the logical name where the error occurred.
106
+ *
107
+ * @param string $name The name
108
+ *
109
+ * @deprecated since 1.27 (to be removed in 2.0). Use setSourceContext() instead.
110
+ */
111
+ public function setTemplateFile($name)
112
+ {
113
+ @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
114
+
115
+ $this->filename = $name;
116
+
117
+ $this->updateRepr();
118
+ }
119
+
120
+ /**
121
+ * Gets the logical name where the error occurred.
122
+ *
123
+ * @return string The name
124
+ *
125
+ * @deprecated since 1.29 (to be removed in 2.0). Use getSourceContext() instead.
126
+ */
127
+ public function getTemplateName()
128
+ {
129
+ @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
130
+
131
+ return $this->filename;
132
+ }
133
+
134
+ /**
135
+ * Sets the logical name where the error occurred.
136
+ *
137
+ * @param string $name The name
138
+ *
139
+ * @deprecated since 1.29 (to be removed in 2.0). Use setSourceContext() instead.
140
+ */
141
+ public function setTemplateName($name)
142
+ {
143
+ @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
144
+
145
+ $this->filename = $name;
146
+ $this->sourceCode = $this->sourcePath = null;
147
+
148
+ $this->updateRepr();
149
+ }
150
+
151
+ /**
152
+ * Gets the template line where the error occurred.
153
+ *
154
+ * @return int The template line
155
+ */
156
+ public function getTemplateLine()
157
+ {
158
+ return $this->lineno;
159
+ }
160
+
161
+ /**
162
+ * Sets the template line where the error occurred.
163
+ *
164
+ * @param int $lineno The template line
165
+ */
166
+ public function setTemplateLine($lineno)
167
+ {
168
+ $this->lineno = $lineno;
169
+
170
+ $this->updateRepr();
171
+ }
172
+
173
+ /**
174
+ * Gets the source context of the Twig template where the error occurred.
175
+ *
176
+ * @return Source|null
177
+ */
178
+ public function getSourceContext()
179
+ {
180
+ return $this->filename ? new Source($this->sourceCode, $this->filename, $this->sourcePath) : null;
181
+ }
182
+
183
+ /**
184
+ * Sets the source context of the Twig template where the error occurred.
185
+ */
186
+ public function setSourceContext(Source $source = null)
187
+ {
188
+ if (null === $source) {
189
+ $this->sourceCode = $this->filename = $this->sourcePath = null;
190
+ } else {
191
+ $this->sourceCode = $source->getCode();
192
+ $this->filename = $source->getName();
193
+ $this->sourcePath = $source->getPath();
194
+ }
195
+
196
+ $this->updateRepr();
197
+ }
198
+
199
+ public function guess()
200
+ {
201
+ $this->guessTemplateInfo();
202
+ $this->updateRepr();
203
+ }
204
+
205
+ public function appendMessage($rawMessage)
206
+ {
207
+ $this->rawMessage .= $rawMessage;
208
+ $this->updateRepr();
209
+ }
210
+
211
+ /**
212
+ * @internal
213
+ */
214
+ protected function updateRepr()
215
+ {
216
+ $this->message = $this->rawMessage;
217
+
218
+ if ($this->sourcePath && $this->lineno > 0) {
219
+ $this->file = $this->sourcePath;
220
+ $this->line = $this->lineno;
221
+
222
+ return;
223
+ }
224
+
225
+ $dot = false;
226
+ if ('.' === substr($this->message, -1)) {
227
+ $this->message = substr($this->message, 0, -1);
228
+ $dot = true;
229
+ }
230
+
231
+ $questionMark = false;
232
+ if ('?' === substr($this->message, -1)) {
233
+ $this->message = substr($this->message, 0, -1);
234
+ $questionMark = true;
235
+ }
236
+
237
+ if ($this->filename) {
238
+ if (\is_string($this->filename) || (\is_object($this->filename) && method_exists($this->filename, '__toString'))) {
239
+ $name = sprintf('"%s"', $this->filename);
240
+ } else {
241
+ $name = json_encode($this->filename);
242
+ }
243
+ $this->message .= sprintf(' in %s', $name);
244
+ }
245
+
246
+ if ($this->lineno && $this->lineno >= 0) {
247
+ $this->message .= sprintf(' at line %d', $this->lineno);
248
+ }
249
+
250
+ if ($dot) {
251
+ $this->message .= '.';
252
+ }
253
+
254
+ if ($questionMark) {
255
+ $this->message .= '?';
256
+ }
257
+ }
258
+
259
+ /**
260
+ * @internal
261
+ */
262
+ protected function guessTemplateInfo()
263
+ {
264
+ $template = null;
265
+ $templateClass = null;
266
+
267
+ $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
268
+ foreach ($backtrace as $trace) {
269
+ if (isset($trace['object']) && $trace['object'] instanceof Template && 'Twig_Template' !== \get_class($trace['object'])) {
270
+ $currentClass = \get_class($trace['object']);
271
+ $isEmbedContainer = 0 === strpos($templateClass, $currentClass);
272
+ if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
273
+ $template = $trace['object'];
274
+ $templateClass = \get_class($trace['object']);
275
+ }
276
+ }
277
+ }
278
+
279
+ // update template name
280
+ if (null !== $template && null === $this->filename) {
281
+ $this->filename = $template->getTemplateName();
282
+ }
283
+
284
+ // update template path if any
285
+ if (null !== $template && null === $this->sourcePath) {
286
+ $src = $template->getSourceContext();
287
+ $this->sourceCode = $src->getCode();
288
+ $this->sourcePath = $src->getPath();
289
+ }
290
+
291
+ if (null === $template || $this->lineno > -1) {
292
+ return;
293
+ }
294
+
295
+ $r = new \ReflectionObject($template);
296
+ $file = $r->getFileName();
297
+
298
+ $exceptions = [$e = $this];
299
+ while ($e instanceof self && $e = $e->getPrevious()) {
300
+ $exceptions[] = $e;
301
+ }
302
+
303
+ while ($e = array_pop($exceptions)) {
304
+ $traces = $e->getTrace();
305
+ array_unshift($traces, ['file' => $e->getFile(), 'line' => $e->getLine()]);
306
+
307
+ while ($trace = array_shift($traces)) {
308
+ if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) {
309
+ continue;
310
+ }
311
+
312
+ foreach ($template->getDebugInfo() as $codeLine => $templateLine) {
313
+ if ($codeLine <= $trace['line']) {
314
+ // update template line
315
+ $this->lineno = $templateLine;
316
+
317
+ return;
318
+ }
319
+ }
320
+ }
321
+ }
322
+ }
323
+ }
324
+
325
+ class_alias('Twig\Error\Error', 'Twig_Error');
vendor/twig/twig/src/Error/LoaderError.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Error;
13
+
14
+ /**
15
+ * Exception thrown when an error occurs during template loading.
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ class LoaderError extends Error
20
+ {
21
+ }
22
+
23
+ class_alias('Twig\Error\LoaderError', 'Twig_Error_Loader');
vendor/twig/twig/src/Error/RuntimeError.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Error;
14
+
15
+ /**
16
+ * Exception thrown when an error occurs at runtime.
17
+ *
18
+ * @author Fabien Potencier <fabien@symfony.com>
19
+ */
20
+ class RuntimeError extends Error
21
+ {
22
+ }
23
+
24
+ class_alias('Twig\Error\RuntimeError', 'Twig_Error_Runtime');
vendor/twig/twig/src/Error/SyntaxError.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Error;
14
+
15
+ /**
16
+ * \Exception thrown when a syntax error occurs during lexing or parsing of a template.
17
+ *
18
+ * @author Fabien Potencier <fabien@symfony.com>
19
+ */
20
+ class SyntaxError extends Error
21
+ {
22
+ /**
23
+ * Tweaks the error message to include suggestions.
24
+ *
25
+ * @param string $name The original name of the item that does not exist
26
+ * @param array $items An array of possible items
27
+ */
28
+ public function addSuggestions($name, array $items)
29
+ {
30
+ if (!$alternatives = self::computeAlternatives($name, $items)) {
31
+ return;
32
+ }
33
+
34
+ $this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', $alternatives)));
35
+ }
36
+
37
+ /**
38
+ * @internal
39
+ *
40
+ * To be merged with the addSuggestions() method in 2.0.
41
+ */
42
+ public static function computeAlternatives($name, $items)
43
+ {
44
+ $alternatives = [];
45
+ foreach ($items as $item) {
46
+ $lev = levenshtein($name, $item);
47
+ if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) {
48
+ $alternatives[$item] = $lev;
49
+ }
50
+ }
51
+ asort($alternatives);
52
+
53
+ return array_keys($alternatives);
54
+ }
55
+ }
56
+
57
+ class_alias('Twig\Error\SyntaxError', 'Twig_Error_Syntax');
vendor/twig/twig/src/ExpressionParser.php ADDED
@@ -0,0 +1,834 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig;
14
+
15
+ use Twig\Error\SyntaxError;
16
+ use Twig\Node\Expression\ArrayExpression;
17
+ use Twig\Node\Expression\ArrowFunctionExpression;
18
+ use Twig\Node\Expression\AssignNameExpression;
19
+ use Twig\Node\Expression\Binary\ConcatBinary;
20
+ use Twig\Node\Expression\BlockReferenceExpression;
21
+ use Twig\Node\Expression\ConditionalExpression;
22
+ use Twig\Node\Expression\ConstantExpression;
23
+ use Twig\Node\Expression\GetAttrExpression;
24
+ use Twig\Node\Expression\MethodCallExpression;
25
+ use Twig\Node\Expression\NameExpression;
26
+ use Twig\Node\Expression\ParentExpression;
27
+ use Twig\Node\Expression\Unary\NegUnary;
28
+ use Twig\Node\Expression\Unary\NotUnary;
29
+ use Twig\Node\Expression\Unary\PosUnary;
30
+ use Twig\Node\Node;
31
+
32
+ /**
33
+ * Parses expressions.
34
+ *
35
+ * This parser implements a "Precedence climbing" algorithm.
36
+ *
37
+ * @see https://www.engr.mun.ca/~theo/Misc/exp_parsing.htm
38
+ * @see https://en.wikipedia.org/wiki/Operator-precedence_parser
39
+ *
40
+ * @author Fabien Potencier <fabien@symfony.com>
41
+ *
42
+ * @internal
43
+ */
44
+ class ExpressionParser
45
+ {
46
+ const OPERATOR_LEFT = 1;
47
+ const OPERATOR_RIGHT = 2;
48
+
49
+ protected $parser;
50
+ protected $unaryOperators;
51
+ protected $binaryOperators;
52
+
53
+ private $env;
54
+
55
+ public function __construct(Parser $parser, $env = null)
56
+ {
57
+ $this->parser = $parser;
58
+
59
+ if ($env instanceof Environment) {
60
+ $this->env = $env;
61
+ $this->unaryOperators = $env->getUnaryOperators();
62
+ $this->binaryOperators = $env->getBinaryOperators();
63
+ } else {
64
+ @trigger_error('Passing the operators as constructor arguments to '.__METHOD__.' is deprecated since version 1.27. Pass the environment instead.', E_USER_DEPRECATED);
65
+
66
+ $this->env = $parser->getEnvironment();
67
+ $this->unaryOperators = func_get_arg(1);
68
+ $this->binaryOperators = func_get_arg(2);
69
+ }
70
+ }
71
+
72
+ public function parseExpression($precedence = 0, $allowArrow = false)
73
+ {
74
+ if ($allowArrow && $arrow = $this->parseArrow()) {
75
+ return $arrow;
76
+ }
77
+
78
+ $expr = $this->getPrimary();
79
+ $token = $this->parser->getCurrentToken();
80
+ while ($this->isBinary($token) && $this->binaryOperators[$token->getValue()]['precedence'] >= $precedence) {
81
+ $op = $this->binaryOperators[$token->getValue()];
82
+ $this->parser->getStream()->next();
83
+
84
+ if ('is not' === $token->getValue()) {
85
+ $expr = $this->parseNotTestExpression($expr);
86
+ } elseif ('is' === $token->getValue()) {
87
+ $expr = $this->parseTestExpression($expr);
88
+ } elseif (isset($op['callable'])) {
89
+ $expr = \call_user_func($op['callable'], $this->parser, $expr);
90
+ } else {
91
+ $expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']);
92
+ $class = $op['class'];
93
+ $expr = new $class($expr, $expr1, $token->getLine());
94
+ }
95
+
96
+ $token = $this->parser->getCurrentToken();
97
+ }
98
+
99
+ if (0 === $precedence) {
100
+ return $this->parseConditionalExpression($expr);
101
+ }
102
+
103
+ return $expr;
104
+ }
105
+
106
+ /**
107
+ * @return ArrowFunctionExpression|null
108
+ */
109
+ private function parseArrow()
110
+ {
111
+ $stream = $this->parser->getStream();
112
+
113
+ // short array syntax (one argument, no parentheses)?
114
+ if ($stream->look(1)->test(Token::ARROW_TYPE)) {
115
+ $line = $stream->getCurrent()->getLine();
116
+ $token = $stream->expect(Token::NAME_TYPE);
117
+ $names = [new AssignNameExpression($token->getValue(), $token->getLine())];
118
+ $stream->expect(Token::ARROW_TYPE);
119
+
120
+ return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line);
121
+ }
122
+
123
+ // first, determine if we are parsing an arrow function by finding => (long form)
124
+ $i = 0;
125
+ if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, '(')) {
126
+ return null;
127
+ }
128
+ ++$i;
129
+ while (true) {
130
+ // variable name
131
+ ++$i;
132
+ if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, ',')) {
133
+ break;
134
+ }
135
+ ++$i;
136
+ }
137
+ if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, ')')) {
138
+ return null;
139
+ }
140
+ ++$i;
141
+ if (!$stream->look($i)->test(Token::ARROW_TYPE)) {
142
+ return null;
143
+ }
144
+
145
+ // yes, let's parse it properly
146
+ $token = $stream->expect(Token::PUNCTUATION_TYPE, '(');
147
+ $line = $token->getLine();
148
+
149
+ $names = [];
150
+ while (true) {
151
+ $token = $stream->expect(Token::NAME_TYPE);
152
+ $names[] = new AssignNameExpression($token->getValue(), $token->getLine());
153
+
154
+ if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
155
+ break;
156
+ }
157
+ }
158
+ $stream->expect(Token::PUNCTUATION_TYPE, ')');
159
+ $stream->expect(Token::ARROW_TYPE);
160
+
161
+ return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line);
162
+ }
163
+
164
+ protected function getPrimary()
165
+ {
166
+ $token = $this->parser->getCurrentToken();
167
+
168
+ if ($this->isUnary($token)) {
169
+ $operator = $this->unaryOperators[$token->getValue()];
170
+ $this->parser->getStream()->next();
171
+ $expr = $this->parseExpression($operator['precedence']);
172
+ $class = $operator['class'];
173
+
174
+ return $this->parsePostfixExpression(new $class($expr, $token->getLine()));
175
+ } elseif ($token->test(Token::PUNCTUATION_TYPE, '(')) {
176
+ $this->parser->getStream()->next();
177
+ $expr = $this->parseExpression();
178
+ $this->parser->getStream()->expect(Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed');
179
+
180
+ return $this->parsePostfixExpression($expr);
181
+ }
182
+
183
+ return $this->parsePrimaryExpression();
184
+ }
185
+
186
+ protected function parseConditionalExpression($expr)
187
+ {
188
+ while ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, '?')) {
189
+ if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) {
190
+ $expr2 = $this->parseExpression();
191
+ if ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) {
192
+ $expr3 = $this->parseExpression();
193
+ } else {
194
+ $expr3 = new ConstantExpression('', $this->parser->getCurrentToken()->getLine());
195
+ }
196
+ } else {
197
+ $expr2 = $expr;
198
+ $expr3 = $this->parseExpression();
199
+ }
200
+
201
+ $expr = new ConditionalExpression($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine());
202
+ }
203
+
204
+ return $expr;
205
+ }
206
+
207
+ protected function isUnary(Token $token)
208
+ {
209
+ return $token->test(Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]);
210
+ }
211
+
212
+ protected function isBinary(Token $token)
213
+ {
214
+ return $token->test(Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]);
215
+ }
216
+
217
+ public function parsePrimaryExpression()
218
+ {
219
+ $token = $this->parser->getCurrentToken();
220
+ switch ($token->getType()) {
221
+ case Token::NAME_TYPE:
222
+ $this->parser->getStream()->next();
223
+ switch ($token->getValue()) {
224
+ case 'true':
225
+ case 'TRUE':
226
+ $node = new ConstantExpression(true, $token->getLine());
227
+ break;
228
+
229
+ case 'false':
230
+ case 'FALSE':
231
+ $node = new ConstantExpression(false, $token->getLine());
232
+ break;
233
+
234
+ case 'none':
235
+ case 'NONE':
236
+ case 'null':
237
+ case 'NULL':
238
+ $node = new ConstantExpression(null, $token->getLine());
239
+ break;
240
+
241
+ default:
242
+ if ('(' === $this->parser->getCurrentToken()->getValue()) {
243
+ $node = $this->getFunctionNode($token->getValue(), $token->getLine());
244
+ } else {
245
+ $node = new NameExpression($token->getValue(), $token->getLine());
246
+ }
247
+ }
248
+ break;
249
+
250
+ case Token::NUMBER_TYPE:
251
+ $this->parser->getStream()->next();
252
+ $node = new ConstantExpression($token->getValue(), $token->getLine());
253
+ break;
254
+
255
+ case Token::STRING_TYPE:
256
+ case Token::INTERPOLATION_START_TYPE:
257
+ $node = $this->parseStringExpression();
258
+ break;
259
+
260
+ case Token::OPERATOR_TYPE:
261
+ if (preg_match(Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) {
262
+ // in this context, string operators are variable names
263
+ $this->parser->getStream()->next();
264
+ $node = new NameExpression($token->getValue(), $token->getLine());
265
+ break;
266
+ } elseif (isset($this->unaryOperators[$token->getValue()])) {
267
+ $class = $this->unaryOperators[$token->getValue()]['class'];
268
+
269
+ $ref = new \ReflectionClass($class);
270
+ $negClass = 'Twig\Node\Expression\Unary\NegUnary';
271
+ $posClass = 'Twig\Node\Expression\Unary\PosUnary';
272
+ if (!(\in_array($ref->getName(), [$negClass, $posClass, 'Twig_Node_Expression_Unary_Neg', 'Twig_Node_Expression_Unary_Pos'])
273
+ || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass)
274
+ || $ref->isSubclassOf('Twig_Node_Expression_Unary_Neg') || $ref->isSubclassOf('Twig_Node_Expression_Unary_Pos'))
275
+ ) {
276
+ throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
277
+ }
278
+
279
+ $this->parser->getStream()->next();
280
+ $expr = $this->parsePrimaryExpression();
281
+
282
+ $node = new $class($expr, $token->getLine());
283
+ break;
284
+ }
285
+
286
+ // no break
287
+ default:
288
+ if ($token->test(Token::PUNCTUATION_TYPE, '[')) {
289
+ $node = $this->parseArrayExpression();
290
+ } elseif ($token->test(Token::PUNCTUATION_TYPE, '{')) {
291
+ $node = $this->parseHashExpression();
292
+ } elseif ($token->test(Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) {
293
+ throw new SyntaxError(sprintf('Unexpected operator of value "%s". Did you try to use "===" or "!==" for strict comparison? Use "is same as(value)" instead.', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
294
+ } else {
295
+ throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
296
+ }
297
+ }
298
+
299
+ return $this->parsePostfixExpression($node);
300
+ }
301
+
302
+ public function parseStringExpression()
303
+ {
304
+ $stream = $this->parser->getStream();
305
+
306
+ $nodes = [];
307
+ // a string cannot be followed by another string in a single expression
308
+ $nextCanBeString = true;
309
+ while (true) {
310
+ if ($nextCanBeString && $token = $stream->nextIf(Token::STRING_TYPE)) {
311
+ $nodes[] = new ConstantExpression($token->getValue(), $token->getLine());
312
+ $nextCanBeString = false;
313
+ } elseif ($stream->nextIf(Token::INTERPOLATION_START_TYPE)) {
314
+ $nodes[] = $this->parseExpression();
315
+ $stream->expect(Token::INTERPOLATION_END_TYPE);
316
+ $nextCanBeString = true;
317
+ } else {
318
+ break;
319
+ }
320
+ }
321
+
322
+ $expr = array_shift($nodes);
323
+ foreach ($nodes as $node) {
324
+ $expr = new ConcatBinary($expr, $node, $node->getTemplateLine());
325
+ }
326
+
327
+ return $expr;
328
+ }
329
+
330
+ public function parseArrayExpression()
331
+ {
332
+ $stream = $this->parser->getStream();
333
+ $stream->expect(Token::PUNCTUATION_TYPE, '[', 'An array element was expected');
334
+
335
+ $node = new ArrayExpression([], $stream->getCurrent()->getLine());
336
+ $first = true;
337
+ while (!$stream->test(Token::PUNCTUATION_TYPE, ']')) {
338
+ if (!$first) {
339
+ $stream->expect(Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma');
340
+
341
+ // trailing ,?
342
+ if ($stream->test(Token::PUNCTUATION_TYPE, ']')) {
343
+ break;
344
+ }
345
+ }
346
+ $first = false;
347
+
348
+ $node->addElement($this->parseExpression());
349
+ }
350
+ $stream->expect(Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed');
351
+
352
+ return $node;
353
+ }
354
+
355
+ public function parseHashExpression()
356
+ {
357
+ $stream = $this->parser->getStream();
358
+ $stream->expect(Token::PUNCTUATION_TYPE, '{', 'A hash element was expected');
359
+
360
+ $node = new ArrayExpression([], $stream->getCurrent()->getLine());
361
+ $first = true;
362
+ while (!$stream->test(Token::PUNCTUATION_TYPE, '}')) {
363
+ if (!$first) {
364
+ $stream->expect(Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma');
365
+
366
+ // trailing ,?
367
+ if ($stream->test(Token::PUNCTUATION_TYPE, '}')) {
368
+ break;
369
+ }
370
+ }
371
+ $first = false;
372
+
373
+ // a hash key can be:
374
+ //
375
+ // * a number -- 12
376
+ // * a string -- 'a'
377
+ // * a name, which is equivalent to a string -- a
378
+ // * an expression, which must be enclosed in parentheses -- (1 + 2)
379
+ if (($token = $stream->nextIf(Token::STRING_TYPE)) || ($token = $stream->nextIf(Token::NAME_TYPE)) || $token = $stream->nextIf(Token::NUMBER_TYPE)) {
380
+ $key = new ConstantExpression($token->getValue(), $token->getLine());
381
+ } elseif ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
382
+ $key = $this->parseExpression();
383
+ } else {
384
+ $current = $stream->getCurrent();
385
+
386
+ throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext());
387
+ }
388
+
389
+ $stream->expect(Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
390
+ $value = $this->parseExpression();
391
+
392
+ $node->addElement($value, $key);
393
+ }
394
+ $stream->expect(Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed');
395
+
396
+ return $node;
397
+ }
398
+
399
+ public function parsePostfixExpression($node)
400
+ {
401
+ while (true) {
402
+ $token = $this->parser->getCurrentToken();
403
+ if (Token::PUNCTUATION_TYPE == $token->getType()) {
404
+ if ('.' == $token->getValue() || '[' == $token->getValue()) {
405
+ $node = $this->parseSubscriptExpression($node);
406
+ } elseif ('|' == $token->getValue()) {
407
+ $node = $this->parseFilterExpression($node);
408
+ } else {
409
+ break;
410
+ }
411
+ } else {
412
+ break;
413
+ }
414
+ }
415
+
416
+ return $node;
417
+ }
418
+
419
+ public function getFunctionNode($name, $line)
420
+ {
421
+ switch ($name) {
422
+ case 'parent':
423
+ $this->parseArguments();
424
+ if (!\count($this->parser->getBlockStack())) {
425
+ throw new SyntaxError('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext());
426
+ }
427
+
428
+ if (!$this->parser->getParent() && !$this->parser->hasTraits()) {
429
+ throw new SyntaxError('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext());
430
+ }
431
+
432
+ return new ParentExpression($this->parser->peekBlockStack(), $line);
433
+ case 'block':
434
+ $args = $this->parseArguments();
435
+ if (\count($args) < 1) {
436
+ throw new SyntaxError('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext());
437
+ }
438
+
439
+ return new BlockReferenceExpression($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line);
440
+ case 'attribute':
441
+ $args = $this->parseArguments();
442
+ if (\count($args) < 2) {
443
+ throw new SyntaxError('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext());
444
+ }
445
+
446
+ return new GetAttrExpression($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, Template::ANY_CALL, $line);
447
+ default:
448
+ if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
449
+ $arguments = new ArrayExpression([], $line);
450
+ foreach ($this->parseArguments() as $n) {
451
+ $arguments->addElement($n);
452
+ }
453
+
454
+ $node = new MethodCallExpression($alias['node'], $alias['name'], $arguments, $line);
455
+ $node->setAttribute('safe', true);
456
+
457
+ return $node;
458
+ }
459
+
460
+ $args = $this->parseArguments(true);
461
+ $class = $this->getFunctionNodeClass($name, $line);
462
+
463
+ return new $class($name, $args, $line);
464
+ }
465
+ }
466
+
467
+ public function parseSubscriptExpression($node)
468
+ {
469
+ $stream = $this->parser->getStream();
470
+ $token = $stream->next();
471
+ $lineno = $token->getLine();
472
+ $arguments = new ArrayExpression([], $lineno);
473
+ $type = Template::ANY_CALL;
474
+ if ('.' == $token->getValue()) {
475
+ $token = $stream->next();
476
+ if (
477
+ Token::NAME_TYPE == $token->getType()
478
+ ||
479
+ Token::NUMBER_TYPE == $token->getType()
480
+ ||
481
+ (Token::OPERATOR_TYPE == $token->getType() && preg_match(Lexer::REGEX_NAME, $token->getValue()))
482
+ ) {
483
+ $arg = new ConstantExpression($token->getValue(), $lineno);
484
+
485
+ if ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
486
+ $type = Template::METHOD_CALL;
487
+ foreach ($this->parseArguments() as $n) {
488
+ $arguments->addElement($n);
489
+ }
490
+ }
491
+ } else {
492
+ throw new SyntaxError('Expected name or number.', $lineno, $stream->getSourceContext());
493
+ }
494
+
495
+ if ($node instanceof NameExpression && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) {
496
+ if (!$arg instanceof ConstantExpression) {
497
+ throw new SyntaxError(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext());
498
+ }
499
+
500
+ $name = $arg->getAttribute('value');
501
+
502
+ if ($this->parser->isReservedMacroName($name)) {
503
+ throw new SyntaxError(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
504
+ }
505
+
506
+ $node = new MethodCallExpression($node, 'get'.$name, $arguments, $lineno);
507
+ $node->setAttribute('safe', true);
508
+
509
+ return $node;
510
+ }
511
+ } else {
512
+ $type = Template::ARRAY_CALL;
513
+
514
+ // slice?
515
+ $slice = false;
516
+ if ($stream->test(Token::PUNCTUATION_TYPE, ':')) {
517
+ $slice = true;
518
+ $arg = new ConstantExpression(0, $token->getLine());
519
+ } else {
520
+ $arg = $this->parseExpression();
521
+ }
522
+
523
+ if ($stream->nextIf(Token::PUNCTUATION_TYPE, ':')) {
524
+ $slice = true;
525
+ }
526
+
527
+ if ($slice) {
528
+ if ($stream->test(Token::PUNCTUATION_TYPE, ']')) {
529
+ $length = new ConstantExpression(null, $token->getLine());
530
+ } else {
531
+ $length = $this->parseExpression();
532
+ }
533
+
534
+ $class = $this->getFilterNodeClass('slice', $token->getLine());
535
+ $arguments = new Node([$arg, $length]);
536
+ $filter = new $class($node, new ConstantExpression('slice', $token->getLine()), $arguments, $token->getLine());
537
+
538
+ $stream->expect(Token::PUNCTUATION_TYPE, ']');
539
+
540
+ return $filter;
541
+ }
542
+
543
+ $stream->expect(Token::PUNCTUATION_TYPE, ']');
544
+ }
545
+
546
+ return new GetAttrExpression($node, $arg, $arguments, $type, $lineno);
547
+ }
548
+
549
+ public function parseFilterExpression($node)
550
+ {
551
+ $this->parser->getStream()->next();
552
+
553
+ return $this->parseFilterExpressionRaw($node);
554
+ }
555
+
556
+ public function parseFilterExpressionRaw($node, $tag = null)
557
+ {
558
+ while (true) {
559
+ $token = $this->parser->getStream()->expect(Token::NAME_TYPE);
560
+
561
+ $name = new ConstantExpression($token->getValue(), $token->getLine());
562
+ if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '(')) {
563
+ $arguments = new Node();
564
+ } else {
565
+ $arguments = $this->parseArguments(true, false, true);
566
+ }
567
+
568
+ $class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine());
569
+
570
+ $node = new $class($node, $name, $arguments, $token->getLine(), $tag);
571
+
572
+ if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '|')) {
573
+ break;
574
+ }
575
+
576
+ $this->parser->getStream()->next();
577
+ }
578
+
579
+ return $node;
580
+ }
581
+
582
+ /**
583
+ * Parses arguments.
584
+ *
585
+ * @param bool $namedArguments Whether to allow named arguments or not
586
+ * @param bool $definition Whether we are parsing arguments for a function definition
587
+ *
588
+ * @return Node
589
+ *
590
+ * @throws SyntaxError
591
+ */
592
+ public function parseArguments($namedArguments = false, $definition = false, $allowArrow = false)
593
+ {
594
+ $args = [];
595
+ $stream = $this->parser->getStream();
596
+
597
+ $stream->expect(Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis');
598
+ while (!$stream->test(Token::PUNCTUATION_TYPE, ')')) {
599
+ if (!empty($args)) {
600
+ $stream->expect(Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma');
601
+ }
602
+
603
+ if ($definition) {
604
+ $token = $stream->expect(Token::NAME_TYPE, null, 'An argument must be a name');
605
+ $value = new NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine());
606
+ } else {
607
+ $value = $this->parseExpression(0, $allowArrow);
608
+ }
609
+
610
+ $name = null;
611
+ if ($namedArguments && $token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) {
612
+ if (!$value instanceof NameExpression) {
613
+ throw new SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext());
614
+ }
615
+ $name = $value->getAttribute('name');
616
+
617
+ if ($definition) {
618
+ $value = $this->parsePrimaryExpression();
619
+
620
+ if (!$this->checkConstantExpression($value)) {
621
+ throw new SyntaxError(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext());
622
+ }
623
+ } else {
624
+ $value = $this->parseExpression(0, $allowArrow);
625
+ }
626
+ }
627
+
628
+ if ($definition) {
629
+ if (null === $name) {
630
+ $name = $value->getAttribute('name');
631
+ $value = new ConstantExpression(null, $this->parser->getCurrentToken()->getLine());
632
+ }
633
+ $args[$name] = $value;
634
+ } else {
635
+ if (null === $name) {
636
+ $args[] = $value;
637
+ } else {
638
+ $args[$name] = $value;
639
+ }
640
+ }
641
+ }
642
+ $stream->expect(Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis');
643
+
644
+ return new Node($args);
645
+ }
646
+
647
+ public function parseAssignmentExpression()
648
+ {
649
+ $stream = $this->parser->getStream();
650
+ $targets = [];
651
+ while (true) {
652
+ $token = $this->parser->getCurrentToken();
653
+ if ($stream->test(Token::OPERATOR_TYPE) && preg_match(Lexer::REGEX_NAME, $token->getValue())) {
654
+ // in this context, string operators are variable names
655
+ $this->parser->getStream()->next();
656
+ } else {
657
+ $stream->expect(Token::NAME_TYPE, null, 'Only variables can be assigned to');
658
+ }
659
+ $value = $token->getValue();
660
+ if (\in_array(strtolower($value), ['true', 'false', 'none', 'null'])) {
661
+ throw new SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext());
662
+ }
663
+ $targets[] = new AssignNameExpression($value, $token->getLine());
664
+
665
+ if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
666
+ break;
667
+ }
668
+ }
669
+
670
+ return new Node($targets);
671
+ }
672
+
673
+ public function parseMultitargetExpression()
674
+ {
675
+ $targets = [];
676
+ while (true) {
677
+ $targets[] = $this->parseExpression();
678
+ if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ',')) {
679
+ break;
680
+ }
681
+ }
682
+
683
+ return new Node($targets);
684
+ }
685
+
686
+ private function parseNotTestExpression(\Twig_NodeInterface $node)
687
+ {
688
+ return new NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine());
689
+ }
690
+
691
+ private function parseTestExpression(\Twig_NodeInterface $node)
692
+ {
693
+ $stream = $this->parser->getStream();
694
+ list($name, $test) = $this->getTest($node->getTemplateLine());
695
+
696
+ $class = $this->getTestNodeClass($test);
697
+ $arguments = null;
698
+ if ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
699
+ $arguments = $this->parseArguments(true);
700
+ }
701
+
702
+ return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine());
703
+ }
704
+
705
+ private function getTest($line)
706
+ {
707
+ $stream = $this->parser->getStream();
708
+ $name = $stream->expect(Token::NAME_TYPE)->getValue();
709
+
710
+ if ($test = $this->env->getTest($name)) {
711
+ return [$name, $test];
712
+ }
713
+
714
+ if ($stream->test(Token::NAME_TYPE)) {
715
+ // try 2-words tests
716
+ $name = $name.' '.$this->parser->getCurrentToken()->getValue();
717
+
718
+ if ($test = $this->env->getTest($name)) {
719
+ $stream->next();
720
+
721
+ return [$name, $test];
722
+ }
723
+ }
724
+
725
+ $e = new SyntaxError(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext());
726
+ $e->addSuggestions($name, array_keys($this->env->getTests()));
727
+
728
+ throw $e;
729
+ }
730
+
731
+ private function getTestNodeClass($test)
732
+ {
733
+ if ($test instanceof TwigTest && $test->isDeprecated()) {
734
+ $stream = $this->parser->getStream();
735
+ $message = sprintf('Twig Test "%s" is deprecated', $test->getName());
736
+ if (!\is_bool($test->getDeprecatedVersion())) {
737
+ $message .= sprintf(' since version %s', $test->getDeprecatedVersion());
738
+ }
739
+ if ($test->getAlternative()) {
740
+ $message .= sprintf('. Use "%s" instead', $test->getAlternative());
741
+ }
742
+ $src = $stream->getSourceContext();
743
+ $message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $stream->getCurrent()->getLine());
744
+
745
+ @trigger_error($message, E_USER_DEPRECATED);
746
+ }
747
+
748
+ if ($test instanceof TwigTest) {
749
+ return $test->getNodeClass();
750
+ }
751
+
752
+ return $test instanceof \Twig_Test_Node ? $test->getClass() : 'Twig\Node\Expression\TestExpression';
753
+ }
754
+
755
+ protected function getFunctionNodeClass($name, $line)
756
+ {
757
+ if (false === $function = $this->env->getFunction($name)) {
758
+ $e = new SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext());
759
+ $e->addSuggestions($name, array_keys($this->env->getFunctions()));
760
+
761
+ throw $e;
762
+ }
763
+
764
+ if ($function instanceof TwigFunction && $function->isDeprecated()) {
765
+ $message = sprintf('Twig Function "%s" is deprecated', $function->getName());
766
+ if (!\is_bool($function->getDeprecatedVersion())) {
767
+ $message .= sprintf(' since version %s', $function->getDeprecatedVersion());
768
+ }
769
+ if ($function->getAlternative()) {
770
+ $message .= sprintf('. Use "%s" instead', $function->getAlternative());
771
+ }
772
+ $src = $this->parser->getStream()->getSourceContext();
773
+ $message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $line);
774
+
775
+ @trigger_error($message, E_USER_DEPRECATED);
776
+ }
777
+
778
+ if ($function instanceof TwigFunction) {
779
+ return $function->getNodeClass();
780
+ }
781
+
782
+ return $function instanceof \Twig_Function_Node ? $function->getClass() : 'Twig\Node\Expression\FunctionExpression';
783
+ }
784
+
785
+ protected function getFilterNodeClass($name, $line)
786
+ {
787
+ if (false === $filter = $this->env->getFilter($name)) {
788
+ $e = new SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext());
789
+ $e->addSuggestions($name, array_keys($this->env->getFilters()));
790
+
791
+ throw $e;
792
+ }
793
+
794
+ if ($filter instanceof TwigFilter && $filter->isDeprecated()) {
795
+ $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName());
796
+ if (!\is_bool($filter->getDeprecatedVersion())) {
797
+ $message .= sprintf(' since version %s', $filter->getDeprecatedVersion());
798
+ }
799
+ if ($filter->getAlternative()) {
800
+ $message .= sprintf('. Use "%s" instead', $filter->getAlternative());
801
+ }
802
+ $src = $this->parser->getStream()->getSourceContext();
803
+ $message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $line);
804
+
805
+ @trigger_error($message, E_USER_DEPRECATED);
806
+ }
807
+
808
+ if ($filter instanceof TwigFilter) {
809
+ return $filter->getNodeClass();
810
+ }
811
+
812
+ return $filter instanceof \Twig_Filter_Node ? $filter->getClass() : 'Twig\Node\Expression\FilterExpression';
813
+ }
814
+
815
+ // checks that the node only contains "constant" elements
816
+ protected function checkConstantExpression(\Twig_NodeInterface $node)
817
+ {
818
+ if (!($node instanceof ConstantExpression || $node instanceof ArrayExpression
819
+ || $node instanceof NegUnary || $node instanceof PosUnary
820
+ )) {
821
+ return false;
822
+ }
823
+
824
+ foreach ($node as $n) {
825
+ if (!$this->checkConstantExpression($n)) {
826
+ return false;
827
+ }
828
+ }
829
+
830
+ return true;
831
+ }
832
+ }
833
+
834
+ class_alias('Twig\ExpressionParser', 'Twig_ExpressionParser');
vendor/twig/twig/src/Extension/AbstractExtension.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension;
13
+
14
+ use Twig\Environment;
15
+
16
+ abstract class AbstractExtension implements ExtensionInterface
17
+ {
18
+ /**
19
+ * @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_InitRuntimeInterface instead
20
+ */
21
+ public function initRuntime(Environment $environment)
22
+ {
23
+ }
24
+
25
+ public function getTokenParsers()
26
+ {
27
+ return [];
28
+ }
29
+
30
+ public function getNodeVisitors()
31
+ {
32
+ return [];
33
+ }
34
+
35
+ public function getFilters()
36
+ {
37
+ return [];
38
+ }
39
+
40
+ public function getTests()
41
+ {
42
+ return [];
43
+ }
44
+
45
+ public function getFunctions()
46
+ {
47
+ return [];
48
+ }
49
+
50
+ public function getOperators()
51
+ {
52
+ return [];
53
+ }
54
+
55
+ /**
56
+ * @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_GlobalsInterface instead
57
+ */
58
+ public function getGlobals()
59
+ {
60
+ return [];
61
+ }
62
+
63
+ /**
64
+ * @deprecated since 1.26 (to be removed in 2.0), not used anymore internally
65
+ */
66
+ public function getName()
67
+ {
68
+ return \get_class($this);
69
+ }
70
+ }
71
+
72
+ class_alias('Twig\Extension\AbstractExtension', 'Twig_Extension');
vendor/twig/twig/src/Extension/CoreExtension.php ADDED
@@ -0,0 +1,1724 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension {
13
+ use Twig\ExpressionParser;
14
+ use Twig\TokenParser\ApplyTokenParser;
15
+ use Twig\TokenParser\BlockTokenParser;
16
+ use Twig\TokenParser\DeprecatedTokenParser;
17
+ use Twig\TokenParser\DoTokenParser;
18
+ use Twig\TokenParser\EmbedTokenParser;
19
+ use Twig\TokenParser\ExtendsTokenParser;
20
+ use Twig\TokenParser\FilterTokenParser;
21
+ use Twig\TokenParser\FlushTokenParser;
22
+ use Twig\TokenParser\ForTokenParser;
23
+ use Twig\TokenParser\FromTokenParser;
24
+ use Twig\TokenParser\IfTokenParser;
25
+ use Twig\TokenParser\ImportTokenParser;
26
+ use Twig\TokenParser\IncludeTokenParser;
27
+ use Twig\TokenParser\MacroTokenParser;
28
+ use Twig\TokenParser\SetTokenParser;
29
+ use Twig\TokenParser\SpacelessTokenParser;
30
+ use Twig\TokenParser\UseTokenParser;
31
+ use Twig\TokenParser\WithTokenParser;
32
+ use Twig\TwigFilter;
33
+ use Twig\TwigFunction;
34
+ use Twig\TwigTest;
35
+
36
+ /**
37
+ * @final
38
+ */
39
+ class CoreExtension extends AbstractExtension
40
+ {
41
+ protected $dateFormats = ['F j, Y H:i', '%d days'];
42
+ protected $numberFormat = [0, '.', ','];
43
+ protected $timezone = null;
44
+ protected $escapers = [];
45
+
46
+ /**
47
+ * Defines a new escaper to be used via the escape filter.
48
+ *
49
+ * @param string $strategy The strategy name that should be used as a strategy in the escape call
50
+ * @param callable $callable A valid PHP callable
51
+ */
52
+ public function setEscaper($strategy, $callable)
53
+ {
54
+ $this->escapers[$strategy] = $callable;
55
+ }
56
+
57
+ /**
58
+ * Gets all defined escapers.
59
+ *
60
+ * @return array An array of escapers
61
+ */
62
+ public function getEscapers()
63
+ {
64
+ return $this->escapers;
65
+ }
66
+
67
+ /**
68
+ * Sets the default format to be used by the date filter.
69
+ *
70
+ * @param string $format The default date format string
71
+ * @param string $dateIntervalFormat The default date interval format string
72
+ */
73
+ public function setDateFormat($format = null, $dateIntervalFormat = null)
74
+ {
75
+ if (null !== $format) {
76
+ $this->dateFormats[0] = $format;
77
+ }
78
+
79
+ if (null !== $dateIntervalFormat) {
80
+ $this->dateFormats[1] = $dateIntervalFormat;
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Gets the default format to be used by the date filter.
86
+ *
87
+ * @return array The default date format string and the default date interval format string
88
+ */
89
+ public function getDateFormat()
90
+ {
91
+ return $this->dateFormats;
92
+ }
93
+
94
+ /**
95
+ * Sets the default timezone to be used by the date filter.
96
+ *
97
+ * @param \DateTimeZone|string $timezone The default timezone string or a \DateTimeZone object
98
+ */
99
+ public function setTimezone($timezone)
100
+ {
101
+ $this->timezone = $timezone instanceof \DateTimeZone ? $timezone : new \DateTimeZone($timezone);
102
+ }
103
+
104
+ /**
105
+ * Gets the default timezone to be used by the date filter.
106
+ *
107
+ * @return \DateTimeZone The default timezone currently in use
108
+ */
109
+ public function getTimezone()
110
+ {
111
+ if (null === $this->timezone) {
112
+ $this->timezone = new \DateTimeZone(date_default_timezone_get());
113
+ }
114
+
115
+ return $this->timezone;
116
+ }
117
+
118
+ /**
119
+ * Sets the default format to be used by the number_format filter.
120
+ *
121
+ * @param int $decimal the number of decimal places to use
122
+ * @param string $decimalPoint the character(s) to use for the decimal point
123
+ * @param string $thousandSep the character(s) to use for the thousands separator
124
+ */
125
+ public function setNumberFormat($decimal, $decimalPoint, $thousandSep)
126
+ {
127
+ $this->numberFormat = [$decimal, $decimalPoint, $thousandSep];
128
+ }
129
+
130
+ /**
131
+ * Get the default format used by the number_format filter.
132
+ *
133
+ * @return array The arguments for number_format()
134
+ */
135
+ public function getNumberFormat()
136
+ {
137
+ return $this->numberFormat;
138
+ }
139
+
140
+ public function getTokenParsers()
141
+ {
142
+ return [
143
+ new ApplyTokenParser(),
144
+ new ForTokenParser(),
145
+ new IfTokenParser(),
146
+ new ExtendsTokenParser(),
147
+ new IncludeTokenParser(),
148
+ new BlockTokenParser(),
149
+ new UseTokenParser(),
150
+ new FilterTokenParser(),
151
+ new MacroTokenParser(),
152
+ new ImportTokenParser(),
153
+ new FromTokenParser(),
154
+ new SetTokenParser(),
155
+ new SpacelessTokenParser(),
156
+ new FlushTokenParser(),
157
+ new DoTokenParser(),
158
+ new EmbedTokenParser(),
159
+ new WithTokenParser(),
160
+ new DeprecatedTokenParser(),
161
+ ];
162
+ }
163
+
164
+ public function getFilters()
165
+ {
166
+ $filters = [
167
+ // formatting filters
168
+ new TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]),
169
+ new TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]),
170
+ new TwigFilter('format', 'sprintf'),
171
+ new TwigFilter('replace', 'twig_replace_filter'),
172
+ new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]),
173
+ new TwigFilter('abs', 'abs'),
174
+ new TwigFilter('round', 'twig_round'),
175
+
176
+ // encoding
177
+ new TwigFilter('url_encode', 'twig_urlencode_filter'),
178
+ new TwigFilter('json_encode', 'twig_jsonencode_filter'),
179
+ new TwigFilter('convert_encoding', 'twig_convert_encoding'),
180
+
181
+ // string filters
182
+ new TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]),
183
+ new TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]),
184
+ new TwigFilter('upper', 'strtoupper'),
185
+ new TwigFilter('lower', 'strtolower'),
186
+ new TwigFilter('striptags', 'strip_tags'),
187
+ new TwigFilter('trim', 'twig_trim_filter'),
188
+ new TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]),
189
+ new TwigFilter('spaceless', 'twig_spaceless', ['is_safe' => ['html']]),
190
+
191
+ // array helpers
192
+ new TwigFilter('join', 'twig_join_filter'),
193
+ new TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]),
194
+ new TwigFilter('sort', 'twig_sort_filter'),
195
+ new TwigFilter('merge', 'twig_array_merge'),
196
+ new TwigFilter('batch', 'twig_array_batch'),
197
+ new TwigFilter('filter', 'twig_array_filter'),
198
+ new TwigFilter('map', 'twig_array_map'),
199
+ new TwigFilter('reduce', 'twig_array_reduce'),
200
+
201
+ // string/array filters
202
+ new TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]),
203
+ new TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]),
204
+ new TwigFilter('slice', 'twig_slice', ['needs_environment' => true]),
205
+ new TwigFilter('first', 'twig_first', ['needs_environment' => true]),
206
+ new TwigFilter('last', 'twig_last', ['needs_environment' => true]),
207
+
208
+ // iteration and runtime
209
+ new TwigFilter('default', '_twig_default_filter', ['node_class' => '\Twig\Node\Expression\Filter\DefaultFilter']),
210
+ new TwigFilter('keys', 'twig_get_array_keys_filter'),
211
+
212
+ // escaping
213
+ new TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
214
+ new TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
215
+ ];
216
+
217
+ if (\function_exists('mb_get_info')) {
218
+ $filters[] = new TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]);
219
+ $filters[] = new TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]);
220
+ }
221
+
222
+ return $filters;
223
+ }
224
+
225
+ public function getFunctions()
226
+ {
227
+ return [
228
+ new TwigFunction('max', 'max'),
229
+ new TwigFunction('min', 'min'),
230
+ new TwigFunction('range', 'range'),
231
+ new TwigFunction('constant', 'twig_constant'),
232
+ new TwigFunction('cycle', 'twig_cycle'),
233
+ new TwigFunction('random', 'twig_random', ['needs_environment' => true]),
234
+ new TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]),
235
+ new TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
236
+ new TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]),
237
+ ];
238
+ }
239
+
240
+ public function getTests()
241
+ {
242
+ return [
243
+ new TwigTest('even', null, ['node_class' => '\Twig\Node\Expression\Test\EvenTest']),
244
+ new TwigTest('odd', null, ['node_class' => '\Twig\Node\Expression\Test\OddTest']),
245
+ new TwigTest('defined', null, ['node_class' => '\Twig\Node\Expression\Test\DefinedTest']),
246
+ new TwigTest('sameas', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest', 'deprecated' => '1.21', 'alternative' => 'same as']),
247
+ new TwigTest('same as', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest']),
248
+ new TwigTest('none', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']),
249
+ new TwigTest('null', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']),
250
+ new TwigTest('divisibleby', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest', 'deprecated' => '1.21', 'alternative' => 'divisible by']),
251
+ new TwigTest('divisible by', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest']),
252
+ new TwigTest('constant', null, ['node_class' => '\Twig\Node\Expression\Test\ConstantTest']),
253
+ new TwigTest('empty', 'twig_test_empty'),
254
+ new TwigTest('iterable', 'twig_test_iterable'),
255
+ ];
256
+ }
257
+
258
+ public function getOperators()
259
+ {
260
+ return [
261
+ [
262
+ 'not' => ['precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'],
263
+ '-' => ['precedence' => 500, 'class' => '\Twig\Node\Expression\Unary\NegUnary'],
264
+ '+' => ['precedence' => 500, 'class' => '\Twig\Node\Expression\Unary\PosUnary'],
265
+ ],
266
+ [
267
+ 'or' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
268
+ 'and' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
269
+ 'b-or' => ['precedence' => 16, 'class' => '\Twig\Node\Expression\Binary\BitwiseOrBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
270
+ 'b-xor' => ['precedence' => 17, 'class' => '\Twig\Node\Expression\Binary\BitwiseXorBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
271
+ 'b-and' => ['precedence' => 18, 'class' => '\Twig\Node\Expression\Binary\BitwiseAndBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
272
+ '==' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
273
+ '!=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
274
+ '<' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
275
+ '>' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
276
+ '>=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
277
+ '<=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
278
+ 'not in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotInBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
279
+ 'in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\InBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
280
+ 'matches' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\MatchesBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
281
+ 'starts with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\StartsWithBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
282
+ 'ends with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EndsWithBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
283
+ '..' => ['precedence' => 25, 'class' => '\Twig\Node\Expression\Binary\RangeBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
284
+ '+' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\AddBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
285
+ '-' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\SubBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
286
+ '~' => ['precedence' => 40, 'class' => '\Twig\Node\Expression\Binary\ConcatBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
287
+ '*' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\MulBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
288
+ '/' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\DivBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
289
+ '//' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\FloorDivBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
290
+ '%' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\ModBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
291
+ 'is' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT],
292
+ 'is not' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT],
293
+ '**' => ['precedence' => 200, 'class' => '\Twig\Node\Expression\Binary\PowerBinary', 'associativity' => ExpressionParser::OPERATOR_RIGHT],
294
+ '??' => ['precedence' => 300, 'class' => '\Twig\Node\Expression\NullCoalesceExpression', 'associativity' => ExpressionParser::OPERATOR_RIGHT],
295
+ ],
296
+ ];
297
+ }
298
+
299
+ public function getName()
300
+ {
301
+ return 'core';
302
+ }
303
+ }
304
+
305
+ class_alias('Twig\Extension\CoreExtension', 'Twig_Extension_Core');
306
+ }
307
+
308
+ namespace {
309
+ use Twig\Environment;
310
+ use Twig\Error\LoaderError;
311
+ use Twig\Error\RuntimeError;
312
+ use Twig\Loader\SourceContextLoaderInterface;
313
+ use Twig\Markup;
314
+ use Twig\Node\Expression\ConstantExpression;
315
+ use Twig\Node\Node;
316
+
317
+ /**
318
+ * Cycles over a value.
319
+ *
320
+ * @param \ArrayAccess|array $values
321
+ * @param int $position The cycle position
322
+ *
323
+ * @return string The next value in the cycle
324
+ */
325
+ function twig_cycle($values, $position)
326
+ {
327
+ if (!\is_array($values) && !$values instanceof \ArrayAccess) {
328
+ return $values;
329
+ }
330
+
331
+ return $values[$position % \count($values)];
332
+ }
333
+
334
+ /**
335
+ * Returns a random value depending on the supplied parameter type:
336
+ * - a random item from a \Traversable or array
337
+ * - a random character from a string
338
+ * - a random integer between 0 and the integer parameter.
339
+ *
340
+ * @param \Traversable|array|int|float|string $values The values to pick a random item from
341
+ * @param int|null $max Maximum value used when $values is an int
342
+ *
343
+ * @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is)
344
+ *
345
+ * @return mixed A random value from the given sequence
346
+ */
347
+ function twig_random(Environment $env, $values = null, $max = null)
348
+ {
349
+ if (null === $values) {
350
+ return null === $max ? mt_rand() : mt_rand(0, $max);
351
+ }
352
+
353
+ if (\is_int($values) || \is_float($values)) {
354
+ if (null === $max) {
355
+ if ($values < 0) {
356
+ $max = 0;
357
+ $min = $values;
358
+ } else {
359
+ $max = $values;
360
+ $min = 0;
361
+ }
362
+ } else {
363
+ $min = $values;
364
+ $max = $max;
365
+ }
366
+
367
+ return mt_rand($min, $max);
368
+ }
369
+
370
+ if (\is_string($values)) {
371
+ if ('' === $values) {
372
+ return '';
373
+ }
374
+ if (null !== $charset = $env->getCharset()) {
375
+ if ('UTF-8' !== $charset) {
376
+ $values = twig_convert_encoding($values, 'UTF-8', $charset);
377
+ }
378
+
379
+ // unicode version of str_split()
380
+ // split at all positions, but not after the start and not before the end
381
+ $values = preg_split('/(?<!^)(?!$)/u', $values);
382
+
383
+ if ('UTF-8' !== $charset) {
384
+ foreach ($values as $i => $value) {
385
+ $values[$i] = twig_convert_encoding($value, $charset, 'UTF-8');
386
+ }
387
+ }
388
+ } else {
389
+ return $values[mt_rand(0, \strlen($values) - 1)];
390
+ }
391
+ }
392
+
393
+ if (!twig_test_iterable($values)) {
394
+ return $values;
395
+ }
396
+
397
+ $values = twig_to_array($values);
398
+
399
+ if (0 === \count($values)) {
400
+ throw new RuntimeError('The random function cannot pick from an empty array.');
401
+ }
402
+
403
+ return $values[array_rand($values, 1)];
404
+ }
405
+
406
+ /**
407
+ * Converts a date to the given format.
408
+ *
409
+ * {{ post.published_at|date("m/d/Y") }}
410
+ *
411
+ * @param \DateTime|\DateTimeInterface|\DateInterval|string $date A date
412
+ * @param string|null $format The target format, null to use the default
413
+ * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
414
+ *
415
+ * @return string The formatted date
416
+ */
417
+ function twig_date_format_filter(Environment $env, $date, $format = null, $timezone = null)
418
+ {
419
+ if (null === $format) {
420
+ $formats = $env->getExtension('\Twig\Extension\CoreExtension')->getDateFormat();
421
+ $format = $date instanceof \DateInterval ? $formats[1] : $formats[0];
422
+ }
423
+
424
+ if ($date instanceof \DateInterval) {
425
+ return $date->format($format);
426
+ }
427
+
428
+ return twig_date_converter($env, $date, $timezone)->format($format);
429
+ }
430
+
431
+ /**
432
+ * Returns a new date object modified.
433
+ *
434
+ * {{ post.published_at|date_modify("-1day")|date("m/d/Y") }}
435
+ *
436
+ * @param \DateTime|string $date A date
437
+ * @param string $modifier A modifier string
438
+ *
439
+ * @return \DateTime
440
+ */
441
+ function twig_date_modify_filter(Environment $env, $date, $modifier)
442
+ {
443
+ $date = twig_date_converter($env, $date, false);
444
+ $resultDate = $date->modify($modifier);
445
+
446
+ // This is a hack to ensure PHP 5.2 support and support for \DateTimeImmutable
447
+ // \DateTime::modify does not return the modified \DateTime object < 5.3.0
448
+ // and \DateTimeImmutable does not modify $date.
449
+ return null === $resultDate ? $date : $resultDate;
450
+ }
451
+
452
+ /**
453
+ * Converts an input to a \DateTime instance.
454
+ *
455
+ * {% if date(user.created_at) < date('+2days') %}
456
+ * {# do something #}
457
+ * {% endif %}
458
+ *
459
+ * @param \DateTime|\DateTimeInterface|string|null $date A date
460
+ * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
461
+ *
462
+ * @return \DateTime
463
+ */
464
+ function twig_date_converter(Environment $env, $date = null, $timezone = null)
465
+ {
466
+ // determine the timezone
467
+ if (false !== $timezone) {
468
+ if (null === $timezone) {
469
+ $timezone = $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone();
470
+ } elseif (!$timezone instanceof \DateTimeZone) {
471
+ $timezone = new \DateTimeZone($timezone);
472
+ }
473
+ }
474
+
475
+ // immutable dates
476
+ if ($date instanceof \DateTimeImmutable) {
477
+ return false !== $timezone ? $date->setTimezone($timezone) : $date;
478
+ }
479
+
480
+ if ($date instanceof \DateTime || $date instanceof \DateTimeInterface) {
481
+ $date = clone $date;
482
+ if (false !== $timezone) {
483
+ $date->setTimezone($timezone);
484
+ }
485
+
486
+ return $date;
487
+ }
488
+
489
+ if (null === $date || 'now' === $date) {
490
+ return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone());
491
+ }
492
+
493
+ $asString = (string) $date;
494
+ if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) {
495
+ $date = new \DateTime('@'.$date);
496
+ } else {
497
+ $date = new \DateTime($date, $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone());
498
+ }
499
+
500
+ if (false !== $timezone) {
501
+ $date->setTimezone($timezone);
502
+ }
503
+
504
+ return $date;
505
+ }
506
+
507
+ /**
508
+ * Replaces strings within a string.
509
+ *
510
+ * @param string $str String to replace in
511
+ * @param array|\Traversable $from Replace values
512
+ * @param string|null $to Replace to, deprecated (@see https://secure.php.net/manual/en/function.strtr.php)
513
+ *
514
+ * @return string
515
+ */
516
+ function twig_replace_filter($str, $from, $to = null)
517
+ {
518
+ if (\is_string($from) && \is_string($to)) {
519
+ @trigger_error('Using "replace" with character by character replacement is deprecated since version 1.22 and will be removed in Twig 2.0', E_USER_DEPRECATED);
520
+
521
+ return strtr($str, $from, $to);
522
+ }
523
+
524
+ if (!twig_test_iterable($from)) {
525
+ throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
526
+ }
527
+
528
+ return strtr($str, twig_to_array($from));
529
+ }
530
+
531
+ /**
532
+ * Rounds a number.
533
+ *
534
+ * @param int|float $value The value to round
535
+ * @param int|float $precision The rounding precision
536
+ * @param string $method The method to use for rounding
537
+ *
538
+ * @return int|float The rounded number
539
+ */
540
+ function twig_round($value, $precision = 0, $method = 'common')
541
+ {
542
+ if ('common' == $method) {
543
+ return round($value, $precision);
544
+ }
545
+
546
+ if ('ceil' != $method && 'floor' != $method) {
547
+ throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.');
548
+ }
549
+
550
+ return $method($value * pow(10, $precision)) / pow(10, $precision);
551
+ }
552
+
553
+ /**
554
+ * Number format filter.
555
+ *
556
+ * All of the formatting options can be left null, in that case the defaults will
557
+ * be used. Supplying any of the parameters will override the defaults set in the
558
+ * environment object.
559
+ *
560
+ * @param mixed $number A float/int/string of the number to format
561
+ * @param int $decimal the number of decimal points to display
562
+ * @param string $decimalPoint the character(s) to use for the decimal point
563
+ * @param string $thousandSep the character(s) to use for the thousands separator
564
+ *
565
+ * @return string The formatted number
566
+ */
567
+ function twig_number_format_filter(Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null)
568
+ {
569
+ $defaults = $env->getExtension('\Twig\Extension\CoreExtension')->getNumberFormat();
570
+ if (null === $decimal) {
571
+ $decimal = $defaults[0];
572
+ }
573
+
574
+ if (null === $decimalPoint) {
575
+ $decimalPoint = $defaults[1];
576
+ }
577
+
578
+ if (null === $thousandSep) {
579
+ $thousandSep = $defaults[2];
580
+ }
581
+
582
+ return number_format((float) $number, $decimal, $decimalPoint, $thousandSep);
583
+ }
584
+
585
+ /**
586
+ * URL encodes (RFC 3986) a string as a path segment or an array as a query string.
587
+ *
588
+ * @param string|array $url A URL or an array of query parameters
589
+ *
590
+ * @return string The URL encoded value
591
+ */
592
+ function twig_urlencode_filter($url)
593
+ {
594
+ if (\is_array($url)) {
595
+ if (\defined('PHP_QUERY_RFC3986')) {
596
+ return http_build_query($url, '', '&', PHP_QUERY_RFC3986);
597
+ }
598
+
599
+ return http_build_query($url, '', '&');
600
+ }
601
+
602
+ return rawurlencode($url);
603
+ }
604
+
605
+ /**
606
+ * JSON encodes a variable.
607
+ *
608
+ * @param mixed $value the value to encode
609
+ * @param int $options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT
610
+ *
611
+ * @return mixed The JSON encoded value
612
+ */
613
+ function twig_jsonencode_filter($value, $options = 0)
614
+ {
615
+ if ($value instanceof Markup) {
616
+ $value = (string) $value;
617
+ } elseif (\is_array($value)) {
618
+ array_walk_recursive($value, '_twig_markup2string');
619
+ }
620
+
621
+ return json_encode($value, $options);
622
+ }
623
+
624
+ function _twig_markup2string(&$value)
625
+ {
626
+ if ($value instanceof Markup) {
627
+ $value = (string) $value;
628
+ }
629
+ }
630
+
631
+ /**
632
+ * Merges an array with another one.
633
+ *
634
+ * {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %}
635
+ *
636
+ * {% set items = items|merge({ 'peugeot': 'car' }) %}
637
+ *
638
+ * {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #}
639
+ *
640
+ * @param array|\Traversable $arr1 An array
641
+ * @param array|\Traversable $arr2 An array
642
+ *
643
+ * @return array The merged array
644
+ */
645
+ function twig_array_merge($arr1, $arr2)
646
+ {
647
+ if (!twig_test_iterable($arr1)) {
648
+ throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1)));
649
+ }
650
+
651
+ if (!twig_test_iterable($arr2)) {
652
+ throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2)));
653
+ }
654
+
655
+ return array_merge(twig_to_array($arr1), twig_to_array($arr2));
656
+ }
657
+
658
+ /**
659
+ * Slices a variable.
660
+ *
661
+ * @param mixed $item A variable
662
+ * @param int $start Start of the slice
663
+ * @param int $length Size of the slice
664
+ * @param bool $preserveKeys Whether to preserve key or not (when the input is an array)
665
+ *
666
+ * @return mixed The sliced variable
667
+ */
668
+ function twig_slice(Environment $env, $item, $start, $length = null, $preserveKeys = false)
669
+ {
670
+ if ($item instanceof \Traversable) {
671
+ while ($item instanceof \IteratorAggregate) {
672
+ $item = $item->getIterator();
673
+ }
674
+
675
+ if ($start >= 0 && $length >= 0 && $item instanceof \Iterator) {
676
+ try {
677
+ return iterator_to_array(new \LimitIterator($item, $start, null === $length ? -1 : $length), $preserveKeys);
678
+ } catch (\OutOfBoundsException $e) {
679
+ return [];
680
+ }
681
+ }
682
+
683
+ $item = iterator_to_array($item, $preserveKeys);
684
+ }
685
+
686
+ if (\is_array($item)) {
687
+ return \array_slice($item, $start, $length, $preserveKeys);
688
+ }
689
+
690
+ $item = (string) $item;
691
+
692
+ if (\function_exists('mb_get_info') && null !== $charset = $env->getCharset()) {
693
+ return (string) mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset);
694
+ }
695
+
696
+ return (string) (null === $length ? substr($item, $start) : substr($item, $start, $length));
697
+ }
698
+
699
+ /**
700
+ * Returns the first element of the item.
701
+ *
702
+ * @param mixed $item A variable
703
+ *
704
+ * @return mixed The first element of the item
705
+ */
706
+ function twig_first(Environment $env, $item)
707
+ {
708
+ $elements = twig_slice($env, $item, 0, 1, false);
709
+
710
+ return \is_string($elements) ? $elements : current($elements);
711
+ }
712
+
713
+ /**
714
+ * Returns the last element of the item.
715
+ *
716
+ * @param mixed $item A variable
717
+ *
718
+ * @return mixed The last element of the item
719
+ */
720
+ function twig_last(Environment $env, $item)
721
+ {
722
+ $elements = twig_slice($env, $item, -1, 1, false);
723
+
724
+ return \is_string($elements) ? $elements : current($elements);
725
+ }
726
+
727
+ /**
728
+ * Joins the values to a string.
729
+ *
730
+ * The separators between elements are empty strings per default, you can define them with the optional parameters.
731
+ *
732
+ * {{ [1, 2, 3]|join(', ', ' and ') }}
733
+ * {# returns 1, 2 and 3 #}
734
+ *
735
+ * {{ [1, 2, 3]|join('|') }}
736
+ * {# returns 1|2|3 #}
737
+ *
738
+ * {{ [1, 2, 3]|join }}
739
+ * {# returns 123 #}
740
+ *
741
+ * @param array $value An array
742
+ * @param string $glue The separator
743
+ * @param string|null $and The separator for the last pair
744
+ *
745
+ * @return string The concatenated string
746
+ */
747
+ function twig_join_filter($value, $glue = '', $and = null)
748
+ {
749
+ if (!twig_test_iterable($value)) {
750
+ $value = (array) $value;
751
+ }
752
+
753
+ $value = twig_to_array($value, false);
754
+
755
+ if (0 === \count($value)) {
756
+ return '';
757
+ }
758
+
759
+ if (null === $and || $and === $glue) {
760
+ return implode($glue, $value);
761
+ }
762
+
763
+ if (1 === \count($value)) {
764
+ return $value[0];
765
+ }
766
+
767
+ return implode($glue, \array_slice($value, 0, -1)).$and.$value[\count($value) - 1];
768
+ }
769
+
770
+ /**
771
+ * Splits the string into an array.
772
+ *
773
+ * {{ "one,two,three"|split(',') }}
774
+ * {# returns [one, two, three] #}
775
+ *
776
+ * {{ "one,two,three,four,five"|split(',', 3) }}
777
+ * {# returns [one, two, "three,four,five"] #}
778
+ *
779
+ * {{ "123"|split('') }}
780
+ * {# returns [1, 2, 3] #}
781
+ *
782
+ * {{ "aabbcc"|split('', 2) }}
783
+ * {# returns [aa, bb, cc] #}
784
+ *
785
+ * @param string $value A string
786
+ * @param string $delimiter The delimiter
787
+ * @param int $limit The limit
788
+ *
789
+ * @return array The split string as an array
790
+ */
791
+ function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
792
+ {
793
+ if (!empty($delimiter)) {
794
+ return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
795
+ }
796
+
797
+ if (!\function_exists('mb_get_info') || null === $charset = $env->getCharset()) {
798
+ return str_split($value, null === $limit ? 1 : $limit);
799
+ }
800
+
801
+ if ($limit <= 1) {
802
+ return preg_split('/(?<!^)(?!$)/u', $value);
803
+ }
804
+
805
+ $length = mb_strlen($value, $charset);
806
+ if ($length < $limit) {
807
+ return [$value];
808
+ }
809
+
810
+ $r = [];
811
+ for ($i = 0; $i < $length; $i += $limit) {
812
+ $r[] = mb_substr($value, $i, $limit, $charset);
813
+ }
814
+
815
+ return $r;
816
+ }
817
+
818
+ // The '_default' filter is used internally to avoid using the ternary operator
819
+ // which costs a lot for big contexts (before PHP 5.4). So, on average,
820
+ // a function call is cheaper.
821
+ /**
822
+ * @internal
823
+ */
824
+ function _twig_default_filter($value, $default = '')
825
+ {
826
+ if (twig_test_empty($value)) {
827
+ return $default;
828
+ }
829
+
830
+ return $value;
831
+ }
832
+
833
+ /**
834
+ * Returns the keys for the given array.
835
+ *
836
+ * It is useful when you want to iterate over the keys of an array:
837
+ *
838
+ * {% for key in array|keys %}
839
+ * {# ... #}
840
+ * {% endfor %}
841
+ *
842
+ * @param array $array An array
843
+ *
844
+ * @return array The keys
845
+ */
846
+ function twig_get_array_keys_filter($array)
847
+ {
848
+ if ($array instanceof \Traversable) {
849
+ while ($array instanceof \IteratorAggregate) {
850
+ $array = $array->getIterator();
851
+ }
852
+
853
+ if ($array instanceof \Iterator) {
854
+ $keys = [];
855
+ $array->rewind();
856
+ while ($array->valid()) {
857
+ $keys[] = $array->key();
858
+ $array->next();
859
+ }
860
+
861
+ return $keys;
862
+ }
863
+
864
+ $keys = [];
865
+ foreach ($array as $key => $item) {
866
+ $keys[] = $key;
867
+ }
868
+
869
+ return $keys;
870
+ }
871
+
872
+ if (!\is_array($array)) {
873
+ return [];
874
+ }
875
+
876
+ return array_keys($array);
877
+ }
878
+
879
+ /**
880
+ * Reverses a variable.
881
+ *
882
+ * @param array|\Traversable|string $item An array, a \Traversable instance, or a string
883
+ * @param bool $preserveKeys Whether to preserve key or not
884
+ *
885
+ * @return mixed The reversed input
886
+ */
887
+ function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
888
+ {
889
+ if ($item instanceof \Traversable) {
890
+ return array_reverse(iterator_to_array($item), $preserveKeys);
891
+ }
892
+
893
+ if (\is_array($item)) {
894
+ return array_reverse($item, $preserveKeys);
895
+ }
896
+
897
+ if (null !== $charset = $env->getCharset()) {
898
+ $string = (string) $item;
899
+
900
+ if ('UTF-8' !== $charset) {
901
+ $item = twig_convert_encoding($string, 'UTF-8', $charset);
902
+ }
903
+
904
+ preg_match_all('/./us', $item, $matches);
905
+
906
+ $string = implode('', array_reverse($matches[0]));
907
+
908
+ if ('UTF-8' !== $charset) {
909
+ $string = twig_convert_encoding($string, $charset, 'UTF-8');
910
+ }
911
+
912
+ return $string;
913
+ }
914
+
915
+ return strrev((string) $item);
916
+ }
917
+
918
+ /**
919
+ * Sorts an array.
920
+ *
921
+ * @param array|\Traversable $array
922
+ *
923
+ * @return array
924
+ */
925
+ function twig_sort_filter($array)
926
+ {
927
+ if ($array instanceof \Traversable) {
928
+ $array = iterator_to_array($array);
929
+ } elseif (!\is_array($array)) {
930
+ throw new RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array)));
931
+ }
932
+
933
+ asort($array);
934
+
935
+ return $array;
936
+ }
937
+
938
+ /**
939
+ * @internal
940
+ */
941
+ function twig_in_filter($value, $compare)
942
+ {
943
+ if ($value instanceof Markup) {
944
+ $value = (string) $value;
945
+ }
946
+ if ($compare instanceof Markup) {
947
+ $compare = (string) $compare;
948
+ }
949
+
950
+ if (\is_array($compare)) {
951
+ return \in_array($value, $compare, \is_object($value) || \is_resource($value));
952
+ } elseif (\is_string($compare) && (\is_string($value) || \is_int($value) || \is_float($value))) {
953
+ return '' === $value || false !== strpos($compare, (string) $value);
954
+ } elseif ($compare instanceof \Traversable) {
955
+ if (\is_object($value) || \is_resource($value)) {
956
+ foreach ($compare as $item) {
957
+ if ($item === $value) {
958
+ return true;
959
+ }
960
+ }
961
+ } else {
962
+ foreach ($compare as $item) {
963
+ if ($item == $value) {
964
+ return true;
965
+ }
966
+ }
967
+ }
968
+
969
+ return false;
970
+ }
971
+
972
+ return false;
973
+ }
974
+
975
+ /**
976
+ * Returns a trimmed string.
977
+ *
978
+ * @return string
979
+ *
980
+ * @throws RuntimeError When an invalid trimming side is used (not a string or not 'left', 'right', or 'both')
981
+ */
982
+ function twig_trim_filter($string, $characterMask = null, $side = 'both')
983
+ {
984
+ if (null === $characterMask) {
985
+ $characterMask = " \t\n\r\0\x0B";
986
+ }
987
+
988
+ switch ($side) {
989
+ case 'both':
990
+ return trim($string, $characterMask);
991
+ case 'left':
992
+ return ltrim($string, $characterMask);
993
+ case 'right':
994
+ return rtrim($string, $characterMask);
995
+ default:
996
+ throw new RuntimeError('Trimming side must be "left", "right" or "both".');
997
+ }
998
+ }
999
+
1000
+ /**
1001
+ * Removes whitespaces between HTML tags.
1002
+ *
1003
+ * @return string
1004
+ */
1005
+ function twig_spaceless($content)
1006
+ {
1007
+ return trim(preg_replace('/>\s+</', '><', $content));
1008
+ }
1009
+
1010
+ /**
1011
+ * Escapes a string.
1012
+ *
1013
+ * @param mixed $string The value to be escaped
1014
+ * @param string $strategy The escaping strategy
1015
+ * @param string $charset The charset
1016
+ * @param bool $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false)
1017
+ *
1018
+ * @return string
1019
+ */
1020
+ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false)
1021
+ {
1022
+ if ($autoescape && $string instanceof Markup) {
1023
+ return $string;
1024
+ }
1025
+
1026
+ if (!\is_string($string)) {
1027
+ if (\is_object($string) && method_exists($string, '__toString')) {
1028
+ $string = (string) $string;
1029
+ } elseif (\in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) {
1030
+ return $string;
1031
+ }
1032
+ }
1033
+
1034
+ if ('' === $string) {
1035
+ return '';
1036
+ }
1037
+
1038
+ if (null === $charset) {
1039
+ $charset = $env->getCharset();
1040
+ }
1041
+
1042
+ switch ($strategy) {
1043
+ case 'html':
1044
+ // see https://secure.php.net/htmlspecialchars
1045
+
1046
+ // Using a static variable to avoid initializing the array
1047
+ // each time the function is called. Moving the declaration on the
1048
+ // top of the function slow downs other escaping strategies.
1049
+ static $htmlspecialcharsCharsets = [
1050
+ 'ISO-8859-1' => true, 'ISO8859-1' => true,
1051
+ 'ISO-8859-15' => true, 'ISO8859-15' => true,
1052
+ 'utf-8' => true, 'UTF-8' => true,
1053
+ 'CP866' => true, 'IBM866' => true, '866' => true,
1054
+ 'CP1251' => true, 'WINDOWS-1251' => true, 'WIN-1251' => true,
1055
+ '1251' => true,
1056
+ 'CP1252' => true, 'WINDOWS-1252' => true, '1252' => true,
1057
+ 'KOI8-R' => true, 'KOI8-RU' => true, 'KOI8R' => true,
1058
+ 'BIG5' => true, '950' => true,
1059
+ 'GB2312' => true, '936' => true,
1060
+ 'BIG5-HKSCS' => true,
1061
+ 'SHIFT_JIS' => true, 'SJIS' => true, '932' => true,
1062
+ 'EUC-JP' => true, 'EUCJP' => true,
1063
+ 'ISO8859-5' => true, 'ISO-8859-5' => true, 'MACROMAN' => true,
1064
+ ];
1065
+
1066
+ if (isset($htmlspecialcharsCharsets[$charset])) {
1067
+ return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
1068
+ }
1069
+
1070
+ if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) {
1071
+ // cache the lowercase variant for future iterations
1072
+ $htmlspecialcharsCharsets[$charset] = true;
1073
+
1074
+ return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
1075
+ }
1076
+
1077
+ $string = twig_convert_encoding($string, 'UTF-8', $charset);
1078
+ $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
1079
+
1080
+ return twig_convert_encoding($string, $charset, 'UTF-8');
1081
+
1082
+ case 'js':
1083
+ // escape all non-alphanumeric characters
1084
+ // into their \x or \uHHHH representations
1085
+ if ('UTF-8' !== $charset) {
1086
+ $string = twig_convert_encoding($string, 'UTF-8', $charset);
1087
+ }
1088
+
1089
+ if (!preg_match('//u', $string)) {
1090
+ throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
1091
+ }
1092
+
1093
+ $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', '_twig_escape_js_callback', $string);
1094
+
1095
+ if ('UTF-8' !== $charset) {
1096
+ $string = twig_convert_encoding($string, $charset, 'UTF-8');
1097
+ }
1098
+
1099
+ return $string;
1100
+
1101
+ case 'css':
1102
+ if ('UTF-8' !== $charset) {
1103
+ $string = twig_convert_encoding($string, 'UTF-8', $charset);
1104
+ }
1105
+
1106
+ if (!preg_match('//u', $string)) {
1107
+ throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
1108
+ }
1109
+
1110
+ $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', '_twig_escape_css_callback', $string);
1111
+
1112
+ if ('UTF-8' !== $charset) {
1113
+ $string = twig_convert_encoding($string, $charset, 'UTF-8');
1114
+ }
1115
+
1116
+ return $string;
1117
+
1118
+ case 'html_attr':
1119
+ if ('UTF-8' !== $charset) {
1120
+ $string = twig_convert_encoding($string, 'UTF-8', $charset);
1121
+ }
1122
+
1123
+ if (!preg_match('//u', $string)) {
1124
+ throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
1125
+ }
1126
+
1127
+ $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', '_twig_escape_html_attr_callback', $string);
1128
+
1129
+ if ('UTF-8' !== $charset) {
1130
+ $string = twig_convert_encoding($string, $charset, 'UTF-8');
1131
+ }
1132
+
1133
+ return $string;
1134
+
1135
+ case 'url':
1136
+ return rawurlencode($string);
1137
+
1138
+ default:
1139
+ static $escapers;
1140
+
1141
+ if (null === $escapers) {
1142
+ $escapers = $env->getExtension('\Twig\Extension\CoreExtension')->getEscapers();
1143
+ }
1144
+
1145
+ if (isset($escapers[$strategy])) {
1146
+ return \call_user_func($escapers[$strategy], $env, $string, $charset);
1147
+ }
1148
+
1149
+ $validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers)));
1150
+
1151
+ throw new RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies));
1152
+ }
1153
+ }
1154
+
1155
+ /**
1156
+ * @internal
1157
+ */
1158
+ function twig_escape_filter_is_safe(Node $filterArgs)
1159
+ {
1160
+ foreach ($filterArgs as $arg) {
1161
+ if ($arg instanceof ConstantExpression) {
1162
+ return [$arg->getAttribute('value')];
1163
+ }
1164
+
1165
+ return [];
1166
+ }
1167
+
1168
+ return ['html'];
1169
+ }
1170
+
1171
+ if (\function_exists('mb_convert_encoding')) {
1172
+ function twig_convert_encoding($string, $to, $from)
1173
+ {
1174
+ return mb_convert_encoding($string, $to, $from);
1175
+ }
1176
+ } elseif (\function_exists('iconv')) {
1177
+ function twig_convert_encoding($string, $to, $from)
1178
+ {
1179
+ return iconv($from, $to, $string);
1180
+ }
1181
+ } else {
1182
+ function twig_convert_encoding($string, $to, $from)
1183
+ {
1184
+ throw new RuntimeError('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
1185
+ }
1186
+ }
1187
+
1188
+ if (\function_exists('mb_ord')) {
1189
+ function twig_ord($string)
1190
+ {
1191
+ return mb_ord($string, 'UTF-8');
1192
+ }
1193
+ } else {
1194
+ function twig_ord($string)
1195
+ {
1196
+ $code = ($string = unpack('C*', substr($string, 0, 4))) ? $string[1] : 0;
1197
+ if (0xF0 <= $code) {
1198
+ return (($code - 0xF0) << 18) + (($string[2] - 0x80) << 12) + (($string[3] - 0x80) << 6) + $string[4] - 0x80;
1199
+ }
1200
+ if (0xE0 <= $code) {
1201
+ return (($code - 0xE0) << 12) + (($string[2] - 0x80) << 6) + $string[3] - 0x80;
1202
+ }
1203
+ if (0xC0 <= $code) {
1204
+ return (($code - 0xC0) << 6) + $string[2] - 0x80;
1205
+ }
1206
+
1207
+ return $code;
1208
+ }
1209
+ }
1210
+
1211
+ function _twig_escape_js_callback($matches)
1212
+ {
1213
+ $char = $matches[0];
1214
+
1215
+ /*
1216
+ * A few characters have short escape sequences in JSON and JavaScript.
1217
+ * Escape sequences supported only by JavaScript, not JSON, are ommitted.
1218
+ * \" is also supported but omitted, because the resulting string is not HTML safe.
1219
+ */
1220
+ static $shortMap = [
1221
+ '\\' => '\\\\',
1222
+ '/' => '\\/',
1223
+ "\x08" => '\b',
1224
+ "\x0C" => '\f',
1225
+ "\x0A" => '\n',
1226
+ "\x0D" => '\r',
1227
+ "\x09" => '\t',
1228
+ ];
1229
+
1230
+ if (isset($shortMap[$char])) {
1231
+ return $shortMap[$char];
1232
+ }
1233
+
1234
+ // \uHHHH
1235
+ $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
1236
+ $char = strtoupper(bin2hex($char));
1237
+
1238
+ if (4 >= \strlen($char)) {
1239
+ return sprintf('\u%04s', $char);
1240
+ }
1241
+
1242
+ return sprintf('\u%04s\u%04s', substr($char, 0, -4), substr($char, -4));
1243
+ }
1244
+
1245
+ function _twig_escape_css_callback($matches)
1246
+ {
1247
+ $char = $matches[0];
1248
+
1249
+ return sprintf('\\%X ', 1 === \strlen($char) ? \ord($char) : twig_ord($char));
1250
+ }
1251
+
1252
+ /**
1253
+ * This function is adapted from code coming from Zend Framework.
1254
+ *
1255
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (https://www.zend.com)
1256
+ * @license https://framework.zend.com/license/new-bsd New BSD License
1257
+ */
1258
+ function _twig_escape_html_attr_callback($matches)
1259
+ {
1260
+ $chr = $matches[0];
1261
+ $ord = \ord($chr);
1262
+
1263
+ /*
1264
+ * The following replaces characters undefined in HTML with the
1265
+ * hex entity for the Unicode replacement character.
1266
+ */
1267
+ if (($ord <= 0x1f && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7f && $ord <= 0x9f)) {
1268
+ return '&#xFFFD;';
1269
+ }
1270
+
1271
+ /*
1272
+ * Check if the current character to escape has a name entity we should
1273
+ * replace it with while grabbing the hex value of the character.
1274
+ */
1275
+ if (1 == \strlen($chr)) {
1276
+ /*
1277
+ * While HTML supports far more named entities, the lowest common denominator
1278
+ * has become HTML5's XML Serialisation which is restricted to the those named
1279
+ * entities that XML supports. Using HTML entities would result in this error:
1280
+ * XML Parsing Error: undefined entity
1281
+ */
1282
+ static $entityMap = [
1283
+ 34 => '&quot;', /* quotation mark */
1284
+ 38 => '&amp;', /* ampersand */
1285
+ 60 => '&lt;', /* less-than sign */
1286
+ 62 => '&gt;', /* greater-than sign */
1287
+ ];
1288
+
1289
+ if (isset($entityMap[$ord])) {
1290
+ return $entityMap[$ord];
1291
+ }
1292
+
1293
+ return sprintf('&#x%02X;', $ord);
1294
+ }
1295
+
1296
+ /*
1297
+ * Per OWASP recommendations, we'll use hex entities for any other
1298
+ * characters where a named entity does not exist.
1299
+ */
1300
+ return sprintf('&#x%04X;', twig_ord($chr));
1301
+ }
1302
+
1303
+ // add multibyte extensions if possible
1304
+ if (\function_exists('mb_get_info')) {
1305
+ /**
1306
+ * Returns the length of a variable.
1307
+ *
1308
+ * @param mixed $thing A variable
1309
+ *
1310
+ * @return int The length of the value
1311
+ */
1312
+ function twig_length_filter(Environment $env, $thing)
1313
+ {
1314
+ if (null === $thing) {
1315
+ return 0;
1316
+ }
1317
+
1318
+ if (is_scalar($thing)) {
1319
+ return mb_strlen($thing, $env->getCharset());
1320
+ }
1321
+
1322
+ if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) {
1323
+ return \count($thing);
1324
+ }
1325
+
1326
+ if ($thing instanceof \Traversable) {
1327
+ return iterator_count($thing);
1328
+ }
1329
+
1330
+ if (\is_object($thing) && method_exists($thing, '__toString')) {
1331
+ return mb_strlen((string) $thing, $env->getCharset());
1332
+ }
1333
+
1334
+ return 1;
1335
+ }
1336
+
1337
+ /**
1338
+ * Converts a string to uppercase.
1339
+ *
1340
+ * @param string $string A string
1341
+ *
1342
+ * @return string The uppercased string
1343
+ */
1344
+ function twig_upper_filter(Environment $env, $string)
1345
+ {
1346
+ if (null !== $charset = $env->getCharset()) {
1347
+ return mb_strtoupper($string, $charset);
1348
+ }
1349
+
1350
+ return strtoupper($string);
1351
+ }
1352
+
1353
+ /**
1354
+ * Converts a string to lowercase.
1355
+ *
1356
+ * @param string $string A string
1357
+ *
1358
+ * @return string The lowercased string
1359
+ */
1360
+ function twig_lower_filter(Environment $env, $string)
1361
+ {
1362
+ if (null !== $charset = $env->getCharset()) {
1363
+ return mb_strtolower($string, $charset);
1364
+ }
1365
+
1366
+ return strtolower($string);
1367
+ }
1368
+
1369
+ /**
1370
+ * Returns a titlecased string.
1371
+ *
1372
+ * @param string $string A string
1373
+ *
1374
+ * @return string The titlecased string
1375
+ */
1376
+ function twig_title_string_filter(Environment $env, $string)
1377
+ {
1378
+ if (null !== $charset = $env->getCharset()) {
1379
+ return mb_convert_case($string, MB_CASE_TITLE, $charset);
1380
+ }
1381
+
1382
+ return ucwords(strtolower($string));
1383
+ }
1384
+
1385
+ /**
1386
+ * Returns a capitalized string.
1387
+ *
1388
+ * @param string $string A string
1389
+ *
1390
+ * @return string The capitalized string
1391
+ */
1392
+ function twig_capitalize_string_filter(Environment $env, $string)
1393
+ {
1394
+ if (null !== $charset = $env->getCharset()) {
1395
+ return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, mb_strlen($string, $charset), $charset), $charset);
1396
+ }
1397
+
1398
+ return ucfirst(strtolower($string));
1399
+ }
1400
+ }
1401
+ // and byte fallback
1402
+ else {
1403
+ /**
1404
+ * Returns the length of a variable.
1405
+ *
1406
+ * @param mixed $thing A variable
1407
+ *
1408
+ * @return int The length of the value
1409
+ */
1410
+ function twig_length_filter(Environment $env, $thing)
1411
+ {
1412
+ if (null === $thing) {
1413
+ return 0;
1414
+ }
1415
+
1416
+ if (is_scalar($thing)) {
1417
+ return \strlen($thing);
1418
+ }
1419
+
1420
+ if ($thing instanceof \SimpleXMLElement) {
1421
+ return \count($thing);
1422
+ }
1423
+
1424
+ if (\is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
1425
+ return \strlen((string) $thing);
1426
+ }
1427
+
1428
+ if ($thing instanceof \Countable || \is_array($thing)) {
1429
+ return \count($thing);
1430
+ }
1431
+
1432
+ if ($thing instanceof \IteratorAggregate) {
1433
+ return iterator_count($thing);
1434
+ }
1435
+
1436
+ return 1;
1437
+ }
1438
+
1439
+ /**
1440
+ * Returns a titlecased string.
1441
+ *
1442
+ * @param string $string A string
1443
+ *
1444
+ * @return string The titlecased string
1445
+ */
1446
+ function twig_title_string_filter(Environment $env, $string)
1447
+ {
1448
+ return ucwords(strtolower($string));
1449
+ }
1450
+
1451
+ /**
1452
+ * Returns a capitalized string.
1453
+ *
1454
+ * @param string $string A string
1455
+ *
1456
+ * @return string The capitalized string
1457
+ */
1458
+ function twig_capitalize_string_filter(Environment $env, $string)
1459
+ {
1460
+ return ucfirst(strtolower($string));
1461
+ }
1462
+ }
1463
+
1464
+ /**
1465
+ * @internal
1466
+ */
1467
+ function twig_ensure_traversable($seq)
1468
+ {
1469
+ if ($seq instanceof \Traversable || \is_array($seq)) {
1470
+ return $seq;
1471
+ }
1472
+
1473
+ return [];
1474
+ }
1475
+
1476
+ /**
1477
+ * @internal
1478
+ */
1479
+ function twig_to_array($seq, $preserveKeys = true)
1480
+ {
1481
+ if ($seq instanceof \Traversable) {
1482
+ return iterator_to_array($seq, $preserveKeys);
1483
+ }
1484
+
1485
+ if (!\is_array($seq)) {
1486
+ return $seq;
1487
+ }
1488
+
1489
+ return $preserveKeys ? $seq : array_values($seq);
1490
+ }
1491
+
1492
+ /**
1493
+ * Checks if a variable is empty.
1494
+ *
1495
+ * {# evaluates to true if the foo variable is null, false, or the empty string #}
1496
+ * {% if foo is empty %}
1497
+ * {# ... #}
1498
+ * {% endif %}
1499
+ *
1500
+ * @param mixed $value A variable
1501
+ *
1502
+ * @return bool true if the value is empty, false otherwise
1503
+ */
1504
+ function twig_test_empty($value)
1505
+ {
1506
+ if ($value instanceof \Countable) {
1507
+ return 0 == \count($value);
1508
+ }
1509
+
1510
+ if (\is_object($value) && method_exists($value, '__toString')) {
1511
+ return '' === (string) $value;
1512
+ }
1513
+
1514
+ return '' === $value || false === $value || null === $value || [] === $value;
1515
+ }
1516
+
1517
+ /**
1518
+ * Checks if a variable is traversable.
1519
+ *
1520
+ * {# evaluates to true if the foo variable is an array or a traversable object #}
1521
+ * {% if foo is iterable %}
1522
+ * {# ... #}
1523
+ * {% endif %}
1524
+ *
1525
+ * @param mixed $value A variable
1526
+ *
1527
+ * @return bool true if the value is traversable
1528
+ */
1529
+ function twig_test_iterable($value)
1530
+ {
1531
+ return $value instanceof \Traversable || \is_array($value);
1532
+ }
1533
+
1534
+ /**
1535
+ * Renders a template.
1536
+ *
1537
+ * @param array $context
1538
+ * @param string|array $template The template to render or an array of templates to try consecutively
1539
+ * @param array $variables The variables to pass to the template
1540
+ * @param bool $withContext
1541
+ * @param bool $ignoreMissing Whether to ignore missing templates or not
1542
+ * @param bool $sandboxed Whether to sandbox the template or not
1543
+ *
1544
+ * @return string The rendered template
1545
+ */
1546
+ function twig_include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false)
1547
+ {
1548
+ $alreadySandboxed = false;
1549
+ $sandbox = null;
1550
+ if ($withContext) {
1551
+ $variables = array_merge($context, $variables);
1552
+ }
1553
+
1554
+ if ($isSandboxed = $sandboxed && $env->hasExtension('\Twig\Extension\SandboxExtension')) {
1555
+ $sandbox = $env->getExtension('\Twig\Extension\SandboxExtension');
1556
+ if (!$alreadySandboxed = $sandbox->isSandboxed()) {
1557
+ $sandbox->enableSandbox();
1558
+ }
1559
+ }
1560
+
1561
+ $loaded = null;
1562
+ try {
1563
+ $loaded = $env->resolveTemplate($template);
1564
+ } catch (LoaderError $e) {
1565
+ if (!$ignoreMissing) {
1566
+ if ($isSandboxed && !$alreadySandboxed) {
1567
+ $sandbox->disableSandbox();
1568
+ }
1569
+
1570
+ throw $e;
1571
+ }
1572
+ } catch (\Throwable $e) {
1573
+ if ($isSandboxed && !$alreadySandboxed) {
1574
+ $sandbox->disableSandbox();
1575
+ }
1576
+
1577
+ throw $e;
1578
+ } catch (\Exception $e) {
1579
+ if ($isSandboxed && !$alreadySandboxed) {
1580
+ $sandbox->disableSandbox();
1581
+ }
1582
+
1583
+ throw $e;
1584
+ }
1585
+
1586
+ try {
1587
+ $ret = $loaded ? $loaded->render($variables) : '';
1588
+ } catch (\Exception $e) {
1589
+ if ($isSandboxed && !$alreadySandboxed) {
1590
+ $sandbox->disableSandbox();
1591
+ }
1592
+
1593
+ throw $e;
1594
+ }
1595
+
1596
+ if ($isSandboxed && !$alreadySandboxed) {
1597
+ $sandbox->disableSandbox();
1598
+ }
1599
+
1600
+ return $ret;
1601
+ }
1602
+
1603
+ /**
1604
+ * Returns a template content without rendering it.
1605
+ *
1606
+ * @param string $name The template name
1607
+ * @param bool $ignoreMissing Whether to ignore missing templates or not
1608
+ *
1609
+ * @return string The template source
1610
+ */
1611
+ function twig_source(Environment $env, $name, $ignoreMissing = false)
1612
+ {
1613
+ $loader = $env->getLoader();
1614
+ try {
1615
+ if (!$loader instanceof SourceContextLoaderInterface) {
1616
+ return $loader->getSource($name);
1617
+ } else {
1618
+ return $loader->getSourceContext($name)->getCode();
1619
+ }
1620
+ } catch (LoaderError $e) {
1621
+ if (!$ignoreMissing) {
1622
+ throw $e;
1623
+ }
1624
+ }
1625
+ }
1626
+
1627
+ /**
1628
+ * Provides the ability to get constants from instances as well as class/global constants.
1629
+ *
1630
+ * @param string $constant The name of the constant
1631
+ * @param object|null $object The object to get the constant from
1632
+ *
1633
+ * @return string
1634
+ */
1635
+ function twig_constant($constant, $object = null)
1636
+ {
1637
+ if (null !== $object) {
1638
+ $constant = \get_class($object).'::'.$constant;
1639
+ }
1640
+
1641
+ return \constant($constant);
1642
+ }
1643
+
1644
+ /**
1645
+ * Checks if a constant exists.
1646
+ *
1647
+ * @param string $constant The name of the constant
1648
+ * @param object|null $object The object to get the constant from
1649
+ *
1650
+ * @return bool
1651
+ */
1652
+ function twig_constant_is_defined($constant, $object = null)
1653
+ {
1654
+ if (null !== $object) {
1655
+ $constant = \get_class($object).'::'.$constant;
1656
+ }
1657
+
1658
+ return \defined($constant);
1659
+ }
1660
+
1661
+ /**
1662
+ * Batches item.
1663
+ *
1664
+ * @param array $items An array of items
1665
+ * @param int $size The size of the batch
1666
+ * @param mixed $fill A value used to fill missing items
1667
+ *
1668
+ * @return array
1669
+ */
1670
+ function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
1671
+ {
1672
+ if (!twig_test_iterable($items)) {
1673
+ throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
1674
+ }
1675
+
1676
+ $size = ceil($size);
1677
+
1678
+ $result = array_chunk(twig_to_array($items, $preserveKeys), $size, $preserveKeys);
1679
+
1680
+ if (null !== $fill && $result) {
1681
+ $last = \count($result) - 1;
1682
+ if ($fillCount = $size - \count($result[$last])) {
1683
+ for ($i = 0; $i < $fillCount; ++$i) {
1684
+ $result[$last][] = $fill;
1685
+ }
1686
+ }
1687
+ }
1688
+
1689
+ return $result;
1690
+ }
1691
+
1692
+ function twig_array_filter($array, $arrow)
1693
+ {
1694
+ if (\is_array($array)) {
1695
+ if (\PHP_VERSION_ID >= 50600) {
1696
+ return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH);
1697
+ }
1698
+
1699
+ return array_filter($array, $arrow);
1700
+ }
1701
+
1702
+ // the IteratorIterator wrapping is needed as some internal PHP classes are \Traversable but do not implement \Iterator
1703
+ return new \CallbackFilterIterator(new \IteratorIterator($array), $arrow);
1704
+ }
1705
+
1706
+ function twig_array_map($array, $arrow)
1707
+ {
1708
+ $r = [];
1709
+ foreach ($array as $k => $v) {
1710
+ $r[$k] = $arrow($v, $k);
1711
+ }
1712
+
1713
+ return $r;
1714
+ }
1715
+
1716
+ function twig_array_reduce($array, $arrow, $initial = null)
1717
+ {
1718
+ if (!\is_array($array)) {
1719
+ $array = iterator_to_array($array);
1720
+ }
1721
+
1722
+ return array_reduce($array, $arrow, $initial);
1723
+ }
1724
+ }
vendor/twig/twig/src/Extension/DebugExtension.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension {
13
+ use Twig\TwigFunction;
14
+
15
+ /**
16
+ * @final
17
+ */
18
+ class DebugExtension extends AbstractExtension
19
+ {
20
+ public function getFunctions()
21
+ {
22
+ // dump is safe if var_dump is overridden by xdebug
23
+ $isDumpOutputHtmlSafe = \extension_loaded('xdebug')
24
+ // false means that it was not set (and the default is on) or it explicitly enabled
25
+ && (false === ini_get('xdebug.overload_var_dump') || ini_get('xdebug.overload_var_dump'))
26
+ // false means that it was not set (and the default is on) or it explicitly enabled
27
+ // xdebug.overload_var_dump produces HTML only when html_errors is also enabled
28
+ && (false === ini_get('html_errors') || ini_get('html_errors'))
29
+ || 'cli' === \PHP_SAPI
30
+ ;
31
+
32
+ return [
33
+ new TwigFunction('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]),
34
+ ];
35
+ }
36
+
37
+ public function getName()
38
+ {
39
+ return 'debug';
40
+ }
41
+ }
42
+
43
+ class_alias('Twig\Extension\DebugExtension', 'Twig_Extension_Debug');
44
+ }
45
+
46
+ namespace {
47
+ use Twig\Environment;
48
+ use Twig\Template;
49
+ use Twig\TemplateWrapper;
50
+
51
+ function twig_var_dump(Environment $env, $context, array $vars = [])
52
+ {
53
+ if (!$env->isDebug()) {
54
+ return;
55
+ }
56
+
57
+ ob_start();
58
+
59
+ if (!$vars) {
60
+ $vars = [];
61
+ foreach ($context as $key => $value) {
62
+ if (!$value instanceof Template && !$value instanceof TemplateWrapper) {
63
+ $vars[$key] = $value;
64
+ }
65
+ }
66
+
67
+ var_dump($vars);
68
+ } else {
69
+ foreach ($vars as $var) {
70
+ var_dump($var);
71
+ }
72
+ }
73
+
74
+ return ob_get_clean();
75
+ }
76
+ }
vendor/twig/twig/src/Extension/EscaperExtension.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension {
13
+ use Twig\NodeVisitor\EscaperNodeVisitor;
14
+ use Twig\TokenParser\AutoEscapeTokenParser;
15
+ use Twig\TwigFilter;
16
+
17
+ /**
18
+ * @final
19
+ */
20
+ class EscaperExtension extends AbstractExtension
21
+ {
22
+ protected $defaultStrategy;
23
+
24
+ /**
25
+ * @param string|false|callable $defaultStrategy An escaping strategy
26
+ *
27
+ * @see setDefaultStrategy()
28
+ */
29
+ public function __construct($defaultStrategy = 'html')
30
+ {
31
+ $this->setDefaultStrategy($defaultStrategy);
32
+ }
33
+
34
+ public function getTokenParsers()
35
+ {
36
+ return [new AutoEscapeTokenParser()];
37
+ }
38
+
39
+ public function getNodeVisitors()
40
+ {
41
+ return [new EscaperNodeVisitor()];
42
+ }
43
+
44
+ public function getFilters()
45
+ {
46
+ return [
47
+ new TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]),
48
+ ];
49
+ }
50
+
51
+ /**
52
+ * Sets the default strategy to use when not defined by the user.
53
+ *
54
+ * The strategy can be a valid PHP callback that takes the template
55
+ * name as an argument and returns the strategy to use.
56
+ *
57
+ * @param string|false|callable $defaultStrategy An escaping strategy
58
+ */
59
+ public function setDefaultStrategy($defaultStrategy)
60
+ {
61
+ // for BC
62
+ if (true === $defaultStrategy) {
63
+ @trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.', E_USER_DEPRECATED);
64
+
65
+ $defaultStrategy = 'html';
66
+ }
67
+
68
+ if ('filename' === $defaultStrategy) {
69
+ @trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.', E_USER_DEPRECATED);
70
+
71
+ $defaultStrategy = 'name';
72
+ }
73
+
74
+ if ('name' === $defaultStrategy) {
75
+ $defaultStrategy = ['\Twig\FileExtensionEscapingStrategy', 'guess'];
76
+ }
77
+
78
+ $this->defaultStrategy = $defaultStrategy;
79
+ }
80
+
81
+ /**
82
+ * Gets the default strategy to use when not defined by the user.
83
+ *
84
+ * @param string $name The template name
85
+ *
86
+ * @return string|false The default strategy to use for the template
87
+ */
88
+ public function getDefaultStrategy($name)
89
+ {
90
+ // disable string callables to avoid calling a function named html or js,
91
+ // or any other upcoming escaping strategy
92
+ if (!\is_string($this->defaultStrategy) && false !== $this->defaultStrategy) {
93
+ return \call_user_func($this->defaultStrategy, $name);
94
+ }
95
+
96
+ return $this->defaultStrategy;
97
+ }
98
+
99
+ public function getName()
100
+ {
101
+ return 'escaper';
102
+ }
103
+ }
104
+
105
+ class_alias('Twig\Extension\EscaperExtension', 'Twig_Extension_Escaper');
106
+ }
107
+
108
+ namespace {
109
+ /**
110
+ * Marks a variable as being safe.
111
+ *
112
+ * @param string $string A PHP variable
113
+ *
114
+ * @return string
115
+ */
116
+ function twig_raw_filter($string)
117
+ {
118
+ return $string;
119
+ }
120
+ }
vendor/twig/twig/src/Extension/ExtensionInterface.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension;
13
+
14
+ use Twig\Environment;
15
+ use Twig\NodeVisitor\NodeVisitorInterface;
16
+ use Twig\TokenParser\TokenParserInterface;
17
+ use Twig\TwigFilter;
18
+ use Twig\TwigFunction;
19
+ use Twig\TwigTest;
20
+
21
+ /**
22
+ * Interface implemented by extension classes.
23
+ *
24
+ * @author Fabien Potencier <fabien@symfony.com>
25
+ */
26
+ interface ExtensionInterface
27
+ {
28
+ /**
29
+ * Initializes the runtime environment.
30
+ *
31
+ * This is where you can load some file that contains filter functions for instance.
32
+ *
33
+ * @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_InitRuntimeInterface instead
34
+ */
35
+ public function initRuntime(Environment $environment);
36
+
37
+ /**
38
+ * Returns the token parser instances to add to the existing list.
39
+ *
40
+ * @return TokenParserInterface[]
41
+ */
42
+ public function getTokenParsers();
43
+
44
+ /**
45
+ * Returns the node visitor instances to add to the existing list.
46
+ *
47
+ * @return NodeVisitorInterface[]
48
+ */
49
+ public function getNodeVisitors();
50
+
51
+ /**
52
+ * Returns a list of filters to add to the existing list.
53
+ *
54
+ * @return TwigFilter[]
55
+ */
56
+ public function getFilters();
57
+
58
+ /**
59
+ * Returns a list of tests to add to the existing list.
60
+ *
61
+ * @return TwigTest[]
62
+ */
63
+ public function getTests();
64
+
65
+ /**
66
+ * Returns a list of functions to add to the existing list.
67
+ *
68
+ * @return TwigFunction[]
69
+ */
70
+ public function getFunctions();
71
+
72
+ /**
73
+ * Returns a list of operators to add to the existing list.
74
+ *
75
+ * @return array<array> First array of unary operators, second array of binary operators
76
+ */
77
+ public function getOperators();
78
+
79
+ /**
80
+ * Returns a list of global variables to add to the existing list.
81
+ *
82
+ * @return array An array of global variables
83
+ *
84
+ * @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_GlobalsInterface instead
85
+ */
86
+ public function getGlobals();
87
+
88
+ /**
89
+ * Returns the name of the extension.
90
+ *
91
+ * @return string The extension name
92
+ *
93
+ * @deprecated since 1.26 (to be removed in 2.0), not used anymore internally
94
+ */
95
+ public function getName();
96
+ }
97
+
98
+ class_alias('Twig\Extension\ExtensionInterface', 'Twig_ExtensionInterface');
99
+
100
+ // Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
101
+ class_exists('Twig\Environment');
vendor/twig/twig/src/Extension/GlobalsInterface.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension;
13
+
14
+ /**
15
+ * Enables usage of the deprecated Twig\Extension\AbstractExtension::getGlobals() method.
16
+ *
17
+ * Explicitly implement this interface if you really need to implement the
18
+ * deprecated getGlobals() method in your extensions.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ interface GlobalsInterface
23
+ {
24
+ }
25
+
26
+ class_alias('Twig\Extension\GlobalsInterface', 'Twig_Extension_GlobalsInterface');
vendor/twig/twig/src/Extension/InitRuntimeInterface.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension;
13
+
14
+ /**
15
+ * Enables usage of the deprecated Twig\Extension\AbstractExtension::initRuntime() method.
16
+ *
17
+ * Explicitly implement this interface if you really need to implement the
18
+ * deprecated initRuntime() method in your extensions.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ interface InitRuntimeInterface
23
+ {
24
+ }
25
+
26
+ class_alias('Twig\Extension\InitRuntimeInterface', 'Twig_Extension_InitRuntimeInterface');
vendor/twig/twig/src/Extension/OptimizerExtension.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension;
13
+
14
+ use Twig\NodeVisitor\OptimizerNodeVisitor;
15
+
16
+ /**
17
+ * @final
18
+ */
19
+ class OptimizerExtension extends AbstractExtension
20
+ {
21
+ protected $optimizers;
22
+
23
+ public function __construct($optimizers = -1)
24
+ {
25
+ $this->optimizers = $optimizers;
26
+ }
27
+
28
+ public function getNodeVisitors()
29
+ {
30
+ return [new OptimizerNodeVisitor($this->optimizers)];
31
+ }
32
+
33
+ public function getName()
34
+ {
35
+ return 'optimizer';
36
+ }
37
+ }
38
+
39
+ class_alias('Twig\Extension\OptimizerExtension', 'Twig_Extension_Optimizer');
vendor/twig/twig/src/Extension/ProfilerExtension.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension;
13
+
14
+ use Twig\Profiler\NodeVisitor\ProfilerNodeVisitor;
15
+ use Twig\Profiler\Profile;
16
+
17
+ class ProfilerExtension extends AbstractExtension
18
+ {
19
+ private $actives = [];
20
+
21
+ public function __construct(Profile $profile)
22
+ {
23
+ $this->actives[] = $profile;
24
+ }
25
+
26
+ public function enter(Profile $profile)
27
+ {
28
+ $this->actives[0]->addProfile($profile);
29
+ array_unshift($this->actives, $profile);
30
+ }
31
+
32
+ public function leave(Profile $profile)
33
+ {
34
+ $profile->leave();
35
+ array_shift($this->actives);
36
+
37
+ if (1 === \count($this->actives)) {
38
+ $this->actives[0]->leave();
39
+ }
40
+ }
41
+
42
+ public function getNodeVisitors()
43
+ {
44
+ return [new ProfilerNodeVisitor(\get_class($this))];
45
+ }
46
+
47
+ public function getName()
48
+ {
49
+ return 'profiler';
50
+ }
51
+ }
52
+
53
+ class_alias('Twig\Extension\ProfilerExtension', 'Twig_Extension_Profiler');
vendor/twig/twig/src/Extension/RuntimeExtensionInterface.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension;
13
+
14
+ /**
15
+ * @author Grégoire Pineau <lyrixx@lyrixx.info>
16
+ */
17
+ interface RuntimeExtensionInterface
18
+ {
19
+ }
vendor/twig/twig/src/Extension/SandboxExtension.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension;
13
+
14
+ use Twig\NodeVisitor\SandboxNodeVisitor;
15
+ use Twig\Sandbox\SecurityPolicyInterface;
16
+ use Twig\TokenParser\SandboxTokenParser;
17
+
18
+ /**
19
+ * @final
20
+ */
21
+ class SandboxExtension extends AbstractExtension
22
+ {
23
+ protected $sandboxedGlobally;
24
+ protected $sandboxed;
25
+ protected $policy;
26
+
27
+ public function __construct(SecurityPolicyInterface $policy, $sandboxed = false)
28
+ {
29
+ $this->policy = $policy;
30
+ $this->sandboxedGlobally = $sandboxed;
31
+ }
32
+
33
+ public function getTokenParsers()
34
+ {
35
+ return [new SandboxTokenParser()];
36
+ }
37
+
38
+ public function getNodeVisitors()
39
+ {
40
+ return [new SandboxNodeVisitor()];
41
+ }
42
+
43
+ public function enableSandbox()
44
+ {
45
+ $this->sandboxed = true;
46
+ }
47
+
48
+ public function disableSandbox()
49
+ {
50
+ $this->sandboxed = false;
51
+ }
52
+
53
+ public function isSandboxed()
54
+ {
55
+ return $this->sandboxedGlobally || $this->sandboxed;
56
+ }
57
+
58
+ public function isSandboxedGlobally()
59
+ {
60
+ return $this->sandboxedGlobally;
61
+ }
62
+
63
+ public function setSecurityPolicy(SecurityPolicyInterface $policy)
64
+ {
65
+ $this->policy = $policy;
66
+ }
67
+
68
+ public function getSecurityPolicy()
69
+ {
70
+ return $this->policy;
71
+ }
72
+
73
+ public function checkSecurity($tags, $filters, $functions)
74
+ {
75
+ if ($this->isSandboxed()) {
76
+ $this->policy->checkSecurity($tags, $filters, $functions);
77
+ }
78
+ }
79
+
80
+ public function checkMethodAllowed($obj, $method)
81
+ {
82
+ if ($this->isSandboxed()) {
83
+ $this->policy->checkMethodAllowed($obj, $method);
84
+ }
85
+ }
86
+
87
+ public function checkPropertyAllowed($obj, $method)
88
+ {
89
+ if ($this->isSandboxed()) {
90
+ $this->policy->checkPropertyAllowed($obj, $method);
91
+ }
92
+ }
93
+
94
+ public function ensureToStringAllowed($obj)
95
+ {
96
+ if ($this->isSandboxed() && \is_object($obj) && method_exists($obj, '__toString')) {
97
+ $this->policy->checkMethodAllowed($obj, '__toString');
98
+ }
99
+
100
+ return $obj;
101
+ }
102
+
103
+ public function getName()
104
+ {
105
+ return 'sandbox';
106
+ }
107
+ }
108
+
109
+ class_alias('Twig\Extension\SandboxExtension', 'Twig_Extension_Sandbox');
vendor/twig/twig/src/Extension/StagingExtension.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension;
13
+
14
+ use Twig\NodeVisitor\NodeVisitorInterface;
15
+ use Twig\TokenParser\TokenParserInterface;
16
+
17
+ /**
18
+ * Internal class.
19
+ *
20
+ * This class is used by \Twig\Environment as a staging area and must not be used directly.
21
+ *
22
+ * @author Fabien Potencier <fabien@symfony.com>
23
+ *
24
+ * @internal
25
+ */
26
+ class StagingExtension extends AbstractExtension
27
+ {
28
+ protected $functions = [];
29
+ protected $filters = [];
30
+ protected $visitors = [];
31
+ protected $tokenParsers = [];
32
+ protected $globals = [];
33
+ protected $tests = [];
34
+
35
+ public function addFunction($name, $function)
36
+ {
37
+ if (isset($this->functions[$name])) {
38
+ @trigger_error(sprintf('Overriding function "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
39
+ }
40
+
41
+ $this->functions[$name] = $function;
42
+ }
43
+
44
+ public function getFunctions()
45
+ {
46
+ return $this->functions;
47
+ }
48
+
49
+ public function addFilter($name, $filter)
50
+ {
51
+ if (isset($this->filters[$name])) {
52
+ @trigger_error(sprintf('Overriding filter "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
53
+ }
54
+
55
+ $this->filters[$name] = $filter;
56
+ }
57
+
58
+ public function getFilters()
59
+ {
60
+ return $this->filters;
61
+ }
62
+
63
+ public function addNodeVisitor(NodeVisitorInterface $visitor)
64
+ {
65
+ $this->visitors[] = $visitor;
66
+ }
67
+
68
+ public function getNodeVisitors()
69
+ {
70
+ return $this->visitors;
71
+ }
72
+
73
+ public function addTokenParser(TokenParserInterface $parser)
74
+ {
75
+ if (isset($this->tokenParsers[$parser->getTag()])) {
76
+ @trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), E_USER_DEPRECATED);
77
+ }
78
+
79
+ $this->tokenParsers[$parser->getTag()] = $parser;
80
+ }
81
+
82
+ public function getTokenParsers()
83
+ {
84
+ return $this->tokenParsers;
85
+ }
86
+
87
+ public function addGlobal($name, $value)
88
+ {
89
+ $this->globals[$name] = $value;
90
+ }
91
+
92
+ public function getGlobals()
93
+ {
94
+ return $this->globals;
95
+ }
96
+
97
+ public function addTest($name, $test)
98
+ {
99
+ if (isset($this->tests[$name])) {
100
+ @trigger_error(sprintf('Overriding test "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
101
+ }
102
+
103
+ $this->tests[$name] = $test;
104
+ }
105
+
106
+ public function getTests()
107
+ {
108
+ return $this->tests;
109
+ }
110
+
111
+ public function getName()
112
+ {
113
+ return 'staging';
114
+ }
115
+ }
116
+
117
+ class_alias('Twig\Extension\StagingExtension', 'Twig_Extension_Staging');
vendor/twig/twig/src/Extension/StringLoaderExtension.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Extension {
13
+ use Twig\TwigFunction;
14
+
15
+ /**
16
+ * @final
17
+ */
18
+ class StringLoaderExtension extends AbstractExtension
19
+ {
20
+ public function getFunctions()
21
+ {
22
+ return [
23
+ new TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]),
24
+ ];
25
+ }
26
+
27
+ public function getName()
28
+ {
29
+ return 'string_loader';
30
+ }
31
+ }
32
+
33
+ class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader');
34
+ }
35
+
36
+ namespace {
37
+ use Twig\Environment;
38
+ use Twig\TemplateWrapper;
39
+
40
+ /**
41
+ * Loads a template from a string.
42
+ *
43
+ * {{ include(template_from_string("Hello {{ name }}")) }}
44
+ *
45
+ * @param string $template A template as a string or object implementing __toString()
46
+ * @param string $name An optional name of the template to be used in error messages
47
+ *
48
+ * @return TemplateWrapper
49
+ */
50
+ function twig_template_from_string(Environment $env, $template, $name = null)
51
+ {
52
+ return $env->createTemplate((string) $template, $name);
53
+ }
54
+ }
vendor/twig/twig/src/FileExtensionEscapingStrategy.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig;
13
+
14
+ /**
15
+ * Default autoescaping strategy based on file names.
16
+ *
17
+ * This strategy sets the HTML as the default autoescaping strategy,
18
+ * but changes it based on the template name.
19
+ *
20
+ * Note that there is no runtime performance impact as the
21
+ * default autoescaping strategy is set at compilation time.
22
+ *
23
+ * @author Fabien Potencier <fabien@symfony.com>
24
+ */
25
+ class FileExtensionEscapingStrategy
26
+ {
27
+ /**
28
+ * Guesses the best autoescaping strategy based on the file name.
29
+ *
30
+ * @param string $name The template name
31
+ *
32
+ * @return string|false The escaping strategy name to use or false to disable
33
+ */
34
+ public static function guess($name)
35
+ {
36
+ if (\in_array(substr($name, -1), ['/', '\\'])) {
37
+ return 'html'; // return html for directories
38
+ }
39
+
40
+ if ('.twig' === substr($name, -5)) {
41
+ $name = substr($name, 0, -5);
42
+ }
43
+
44
+ $extension = pathinfo($name, PATHINFO_EXTENSION);
45
+
46
+ switch ($extension) {
47
+ case 'js':
48
+ return 'js';
49
+
50
+ case 'css':
51
+ return 'css';
52
+
53
+ case 'txt':
54
+ return false;
55
+
56
+ default:
57
+ return 'html';
58
+ }
59
+ }
60
+ }
61
+
62
+ class_alias('Twig\FileExtensionEscapingStrategy', 'Twig_FileExtensionEscapingStrategy');
vendor/twig/twig/src/Lexer.php ADDED
@@ -0,0 +1,534 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig;
14
+
15
+ use Twig\Error\SyntaxError;
16
+
17
+ /**
18
+ * Lexes a template string.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class Lexer implements \Twig_LexerInterface
23
+ {
24
+ protected $tokens;
25
+ protected $code;
26
+ protected $cursor;
27
+ protected $lineno;
28
+ protected $end;
29
+ protected $state;
30
+ protected $states;
31
+ protected $brackets;
32
+ protected $env;
33
+ // to be renamed to $name in 2.0 (where it is private)
34
+ protected $filename;
35
+ protected $options;
36
+ protected $regexes;
37
+ protected $position;
38
+ protected $positions;
39
+ protected $currentVarBlockLine;
40
+
41
+ private $source;
42
+
43
+ const STATE_DATA = 0;
44
+ const STATE_BLOCK = 1;
45
+ const STATE_VAR = 2;
46
+ const STATE_STRING = 3;
47
+ const STATE_INTERPOLATION = 4;
48
+
49
+ const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A';
50
+ const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A';
51
+ const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As';
52
+ const REGEX_DQ_STRING_DELIM = '/"/A';
53
+ const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As';
54
+ const PUNCTUATION = '()[]{}?:.,|';
55
+
56
+ public function __construct(Environment $env, array $options = [])
57
+ {
58
+ $this->env = $env;
59
+
60
+ $this->options = array_merge([
61
+ 'tag_comment' => ['{#', '#}'],
62
+ 'tag_block' => ['{%', '%}'],
63
+ 'tag_variable' => ['{{', '}}'],
64
+ 'whitespace_trim' => '-',
65
+ 'whitespace_line_trim' => '~',
66
+ 'whitespace_line_chars' => ' \t\0\x0B',
67
+ 'interpolation' => ['#{', '}'],
68
+ ], $options);
69
+
70
+ // when PHP 7.3 is the min version, we will be able to remove the '#' part in preg_quote as it's part of the default
71
+ $this->regexes = [
72
+ // }}
73
+ 'lex_var' => '{
74
+ \s*
75
+ (?:'.
76
+ preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '#').'\s*'. // -}}\s*
77
+ '|'.
78
+ preg_quote($this->options['whitespace_line_trim'].$this->options['tag_variable'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~}}[ \t\0\x0B]*
79
+ '|'.
80
+ preg_quote($this->options['tag_variable'][1], '#'). // }}
81
+ ')
82
+ }Ax',
83
+
84
+ // %}
85
+ 'lex_block' => '{
86
+ \s*
87
+ (?:'.
88
+ preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*\n?'. // -%}\s*\n?
89
+ '|'.
90
+ preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]*
91
+ '|'.
92
+ preg_quote($this->options['tag_block'][1], '#').'\n?'. // %}\n?
93
+ ')
94
+ }Ax',
95
+
96
+ // {% endverbatim %}
97
+ 'lex_raw_data' => '{'.
98
+ preg_quote($this->options['tag_block'][0], '#'). // {%
99
+ '('.
100
+ $this->options['whitespace_trim']. // -
101
+ '|'.
102
+ $this->options['whitespace_line_trim']. // ~
103
+ ')?\s*'.
104
+ '(?:end%s)'. // endraw or endverbatim
105
+ '\s*'.
106
+ '(?:'.
107
+ preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%}
108
+ '|'.
109
+ preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]*
110
+ '|'.
111
+ preg_quote($this->options['tag_block'][1], '#'). // %}
112
+ ')
113
+ }sx',
114
+
115
+ 'operator' => $this->getOperatorRegex(),
116
+
117
+ // #}
118
+ 'lex_comment' => '{
119
+ (?:'.
120
+ preg_quote($this->options['whitespace_trim']).preg_quote($this->options['tag_comment'][1], '#').'\s*\n?'. // -#}\s*\n?
121
+ '|'.
122
+ preg_quote($this->options['whitespace_line_trim'].$this->options['tag_comment'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~#}[ \t\0\x0B]*
123
+ '|'.
124
+ preg_quote($this->options['tag_comment'][1], '#').'\n?'. // #}\n?
125
+ ')
126
+ }sx',
127
+
128
+ // verbatim %}
129
+ 'lex_block_raw' => '{
130
+ \s*
131
+ (raw|verbatim)
132
+ \s*
133
+ (?:'.
134
+ preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%}\s*
135
+ '|'.
136
+ preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]*
137
+ '|'.
138
+ preg_quote($this->options['tag_block'][1], '#'). // %}
139
+ ')
140
+ }Asx',
141
+
142
+ 'lex_block_line' => '{\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '#').'}As',
143
+
144
+ // {{ or {% or {#
145
+ 'lex_tokens_start' => '{
146
+ ('.
147
+ preg_quote($this->options['tag_variable'][0], '#'). // {{
148
+ '|'.
149
+ preg_quote($this->options['tag_block'][0], '#'). // {%
150
+ '|'.
151
+ preg_quote($this->options['tag_comment'][0], '#'). // {#
152
+ ')('.
153
+ preg_quote($this->options['whitespace_trim'], '#'). // -
154
+ '|'.
155
+ preg_quote($this->options['whitespace_line_trim'], '#'). // ~
156
+ ')?
157
+ }sx',
158
+ 'interpolation_start' => '{'.preg_quote($this->options['interpolation'][0], '#').'\s*}A',
159
+ 'interpolation_end' => '{\s*'.preg_quote($this->options['interpolation'][1], '#').'}A',
160
+ ];
161
+ }
162
+
163
+ public function tokenize($code, $name = null)
164
+ {
165
+ if (!$code instanceof Source) {
166
+ @trigger_error(sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED);
167
+ $this->source = new Source($code, $name);
168
+ } else {
169
+ $this->source = $code;
170
+ }
171
+
172
+ if (((int) ini_get('mbstring.func_overload')) & 2) {
173
+ @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED);
174
+ }
175
+
176
+ if (\function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
177
+ $mbEncoding = mb_internal_encoding();
178
+ mb_internal_encoding('ASCII');
179
+ } else {
180
+ $mbEncoding = null;
181
+ }
182
+
183
+ $this->code = str_replace(["\r\n", "\r"], "\n", $this->source->getCode());
184
+ $this->filename = $this->source->getName();
185
+ $this->cursor = 0;
186
+ $this->lineno = 1;
187
+ $this->end = \strlen($this->code);
188
+ $this->tokens = [];
189
+ $this->state = self::STATE_DATA;
190
+ $this->states = [];
191
+ $this->brackets = [];
192
+ $this->position = -1;
193
+
194
+ // find all token starts in one go
195
+ preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, PREG_OFFSET_CAPTURE);
196
+ $this->positions = $matches;
197
+
198
+ while ($this->cursor < $this->end) {
199
+ // dispatch to the lexing functions depending
200
+ // on the current state
201
+ switch ($this->state) {
202
+ case self::STATE_DATA:
203
+ $this->lexData();
204
+ break;
205
+
206
+ case self::STATE_BLOCK:
207
+ $this->lexBlock();
208
+ break;
209
+
210
+ case self::STATE_VAR:
211
+ $this->lexVar();
212
+ break;
213
+
214
+ case self::STATE_STRING:
215
+ $this->lexString();
216
+ break;
217
+
218
+ case self::STATE_INTERPOLATION:
219
+ $this->lexInterpolation();
220
+ break;
221
+ }
222
+ }
223
+
224
+ $this->pushToken(Token::EOF_TYPE);
225
+
226
+ if (!empty($this->brackets)) {
227
+ list($expect, $lineno) = array_pop($this->brackets);
228
+ throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
229
+ }
230
+
231
+ if ($mbEncoding) {
232
+ mb_internal_encoding($mbEncoding);
233
+ }
234
+
235
+ return new TokenStream($this->tokens, $this->source);
236
+ }
237
+
238
+ protected function lexData()
239
+ {
240
+ // if no matches are left we return the rest of the template as simple text token
241
+ if ($this->position == \count($this->positions[0]) - 1) {
242
+ $this->pushToken(Token::TEXT_TYPE, substr($this->code, $this->cursor));
243
+ $this->cursor = $this->end;
244
+
245
+ return;
246
+ }
247
+
248
+ // Find the first token after the current cursor
249
+ $position = $this->positions[0][++$this->position];
250
+ while ($position[1] < $this->cursor) {
251
+ if ($this->position == \count($this->positions[0]) - 1) {
252
+ return;
253
+ }
254
+ $position = $this->positions[0][++$this->position];
255
+ }
256
+
257
+ // push the template text first
258
+ $text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor);
259
+
260
+ // trim?
261
+ if (isset($this->positions[2][$this->position][0])) {
262
+ if ($this->options['whitespace_trim'] === $this->positions[2][$this->position][0]) {
263
+ // whitespace_trim detected ({%-, {{- or {#-)
264
+ $text = rtrim($text);
265
+ } elseif ($this->options['whitespace_line_trim'] === $this->positions[2][$this->position][0]) {
266
+ // whitespace_line_trim detected ({%~, {{~ or {#~)
267
+ // don't trim \r and \n
268
+ $text = rtrim($text, " \t\0\x0B");
269
+ }
270
+ }
271
+ $this->pushToken(Token::TEXT_TYPE, $text);
272
+ $this->moveCursor($textContent.$position[0]);
273
+
274
+ switch ($this->positions[1][$this->position][0]) {
275
+ case $this->options['tag_comment'][0]:
276
+ $this->lexComment();
277
+ break;
278
+
279
+ case $this->options['tag_block'][0]:
280
+ // raw data?
281
+ if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, 0, $this->cursor)) {
282
+ $this->moveCursor($match[0]);
283
+ $this->lexRawData($match[1]);
284
+ // {% line \d+ %}
285
+ } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, 0, $this->cursor)) {
286
+ $this->moveCursor($match[0]);
287
+ $this->lineno = (int) $match[1];
288
+ } else {
289
+ $this->pushToken(Token::BLOCK_START_TYPE);
290
+ $this->pushState(self::STATE_BLOCK);
291
+ $this->currentVarBlockLine = $this->lineno;
292
+ }
293
+ break;
294
+
295
+ case $this->options['tag_variable'][0]:
296
+ $this->pushToken(Token::VAR_START_TYPE);
297
+ $this->pushState(self::STATE_VAR);
298
+ $this->currentVarBlockLine = $this->lineno;
299
+ break;
300
+ }
301
+ }
302
+
303
+ protected function lexBlock()
304
+ {
305
+ if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) {
306
+ $this->pushToken(Token::BLOCK_END_TYPE);
307
+ $this->moveCursor($match[0]);
308
+ $this->popState();
309
+ } else {
310
+ $this->lexExpression();
311
+ }
312
+ }
313
+
314
+ protected function lexVar()
315
+ {
316
+ if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) {
317
+ $this->pushToken(Token::VAR_END_TYPE);
318
+ $this->moveCursor($match[0]);
319
+ $this->popState();
320
+ } else {
321
+ $this->lexExpression();
322
+ }
323
+ }
324
+
325
+ protected function lexExpression()
326
+ {
327
+ // whitespace
328
+ if (preg_match('/\s+/A', $this->code, $match, 0, $this->cursor)) {
329
+ $this->moveCursor($match[0]);
330
+
331
+ if ($this->cursor >= $this->end) {
332
+ throw new SyntaxError(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source);
333
+ }
334
+ }
335
+
336
+ // arrow function
337
+ if ('=' === $this->code[$this->cursor] && '>' === $this->code[$this->cursor + 1]) {
338
+ $this->pushToken(Token::ARROW_TYPE, '=>');
339
+ $this->moveCursor('=>');
340
+ }
341
+ // operators
342
+ elseif (preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) {
343
+ $this->pushToken(Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0]));
344
+ $this->moveCursor($match[0]);
345
+ }
346
+ // names
347
+ elseif (preg_match(self::REGEX_NAME, $this->code, $match, 0, $this->cursor)) {
348
+ $this->pushToken(Token::NAME_TYPE, $match[0]);
349
+ $this->moveCursor($match[0]);
350
+ }
351
+ // numbers
352
+ elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) {
353
+ $number = (float) $match[0]; // floats
354
+ if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) {
355
+ $number = (int) $match[0]; // integers lower than the maximum
356
+ }
357
+ $this->pushToken(Token::NUMBER_TYPE, $number);
358
+ $this->moveCursor($match[0]);
359
+ }
360
+ // punctuation
361
+ elseif (false !== strpos(self::PUNCTUATION, $this->code[$this->cursor])) {
362
+ // opening bracket
363
+ if (false !== strpos('([{', $this->code[$this->cursor])) {
364
+ $this->brackets[] = [$this->code[$this->cursor], $this->lineno];
365
+ }
366
+ // closing bracket
367
+ elseif (false !== strpos(')]}', $this->code[$this->cursor])) {
368
+ if (empty($this->brackets)) {
369
+ throw new SyntaxError(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
370
+ }
371
+
372
+ list($expect, $lineno) = array_pop($this->brackets);
373
+ if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) {
374
+ throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
375
+ }
376
+ }
377
+
378
+ $this->pushToken(Token::PUNCTUATION_TYPE, $this->code[$this->cursor]);
379
+ ++$this->cursor;
380
+ }
381
+ // strings
382
+ elseif (preg_match(self::REGEX_STRING, $this->code, $match, 0, $this->cursor)) {
383
+ $this->pushToken(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)));
384
+ $this->moveCursor($match[0]);
385
+ }
386
+ // opening double quoted string
387
+ elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
388
+ $this->brackets[] = ['"', $this->lineno];
389
+ $this->pushState(self::STATE_STRING);
390
+ $this->moveCursor($match[0]);
391
+ }
392
+ // unlexable
393
+ else {
394
+ throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
395
+ }
396
+ }
397
+
398
+ protected function lexRawData($tag)
399
+ {
400
+ if ('raw' === $tag) {
401
+ @trigger_error(sprintf('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), E_USER_DEPRECATED);
402
+ }
403
+
404
+ if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
405
+ throw new SyntaxError(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source);
406
+ }
407
+
408
+ $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor);
409
+ $this->moveCursor($text.$match[0][0]);
410
+
411
+ // trim?
412
+ if (isset($match[1][0])) {
413
+ if ($this->options['whitespace_trim'] === $match[1][0]) {
414
+ // whitespace_trim detected ({%-, {{- or {#-)
415
+ $text = rtrim($text);
416
+ } else {
417
+ // whitespace_line_trim detected ({%~, {{~ or {#~)
418
+ // don't trim \r and \n
419
+ $text = rtrim($text, " \t\0\x0B");
420
+ }
421
+ }
422
+
423
+ $this->pushToken(Token::TEXT_TYPE, $text);
424
+ }
425
+
426
+ protected function lexComment()
427
+ {
428
+ if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
429
+ throw new SyntaxError('Unclosed comment.', $this->lineno, $this->source);
430
+ }
431
+
432
+ $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]);
433
+ }
434
+
435
+ protected function lexString()
436
+ {
437
+ if (preg_match($this->regexes['interpolation_start'], $this->code, $match, 0, $this->cursor)) {
438
+ $this->brackets[] = [$this->options['interpolation'][0], $this->lineno];
439
+ $this->pushToken(Token::INTERPOLATION_START_TYPE);
440
+ $this->moveCursor($match[0]);
441
+ $this->pushState(self::STATE_INTERPOLATION);
442
+ } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) {
443
+ $this->pushToken(Token::STRING_TYPE, stripcslashes($match[0]));
444
+ $this->moveCursor($match[0]);
445
+ } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
446
+ list($expect, $lineno) = array_pop($this->brackets);
447
+ if ('"' != $this->code[$this->cursor]) {
448
+ throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
449
+ }
450
+
451
+ $this->popState();
452
+ ++$this->cursor;
453
+ } else {
454
+ // unlexable
455
+ throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
456
+ }
457
+ }
458
+
459
+ protected function lexInterpolation()
460
+ {
461
+ $bracket = end($this->brackets);
462
+ if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, 0, $this->cursor)) {
463
+ array_pop($this->brackets);
464
+ $this->pushToken(Token::INTERPOLATION_END_TYPE);
465
+ $this->moveCursor($match[0]);
466
+ $this->popState();
467
+ } else {
468
+ $this->lexExpression();
469
+ }
470
+ }
471
+
472
+ protected function pushToken($type, $value = '')
473
+ {
474
+ // do not push empty text tokens
475
+ if (Token::TEXT_TYPE === $type && '' === $value) {
476
+ return;
477
+ }
478
+
479
+ $this->tokens[] = new Token($type, $value, $this->lineno);
480
+ }
481
+
482
+ protected function moveCursor($text)
483
+ {
484
+ $this->cursor += \strlen($text);
485
+ $this->lineno += substr_count($text, "\n");
486
+ }
487
+
488
+ protected function getOperatorRegex()
489
+ {
490
+ $operators = array_merge(
491
+ ['='],
492
+ array_keys($this->env->getUnaryOperators()),
493
+ array_keys($this->env->getBinaryOperators())
494
+ );
495
+
496
+ $operators = array_combine($operators, array_map('strlen', $operators));
497
+ arsort($operators);
498
+
499
+ $regex = [];
500
+ foreach ($operators as $operator => $length) {
501
+ // an operator that ends with a character must be followed by
502
+ // a whitespace or a parenthesis
503
+ if (ctype_alpha($operator[$length - 1])) {
504
+ $r = preg_quote($operator, '/').'(?=[\s()])';
505
+ } else {
506
+ $r = preg_quote($operator, '/');
507
+ }
508
+
509
+ // an operator with a space can be any amount of whitespaces
510
+ $r = preg_replace('/\s+/', '\s+', $r);
511
+
512
+ $regex[] = $r;
513
+ }
514
+
515
+ return '/'.implode('|', $regex).'/A';
516
+ }
517
+
518
+ protected function pushState($state)
519
+ {
520
+ $this->states[] = $this->state;
521
+ $this->state = $state;
522
+ }
523
+
524
+ protected function popState()
525
+ {
526
+ if (0 === \count($this->states)) {
527
+ throw new \LogicException('Cannot pop state without a previous state.');
528
+ }
529
+
530
+ $this->state = array_pop($this->states);
531
+ }
532
+ }
533
+
534
+ class_alias('Twig\Lexer', 'Twig_Lexer');
vendor/twig/twig/src/Loader/ArrayLoader.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Loader;
13
+
14
+ use Twig\Error\LoaderError;
15
+ use Twig\Source;
16
+
17
+ /**
18
+ * Loads a template from an array.
19
+ *
20
+ * When using this loader with a cache mechanism, you should know that a new cache
21
+ * key is generated each time a template content "changes" (the cache key being the
22
+ * source code of the template). If you don't want to see your cache grows out of
23
+ * control, you need to take care of clearing the old cache file by yourself.
24
+ *
25
+ * This loader should only be used for unit testing.
26
+ *
27
+ * @final
28
+ *
29
+ * @author Fabien Potencier <fabien@symfony.com>
30
+ */
31
+ class ArrayLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
32
+ {
33
+ protected $templates = [];
34
+
35
+ /**
36
+ * @param array $templates An array of templates (keys are the names, and values are the source code)
37
+ */
38
+ public function __construct(array $templates = [])
39
+ {
40
+ $this->templates = $templates;
41
+ }
42
+
43
+ /**
44
+ * Adds or overrides a template.
45
+ *
46
+ * @param string $name The template name
47
+ * @param string $template The template source
48
+ */
49
+ public function setTemplate($name, $template)
50
+ {
51
+ $this->templates[(string) $name] = $template;
52
+ }
53
+
54
+ public function getSource($name)
55
+ {
56
+ @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED);
57
+
58
+ $name = (string) $name;
59
+ if (!isset($this->templates[$name])) {
60
+ throw new LoaderError(sprintf('Template "%s" is not defined.', $name));
61
+ }
62
+
63
+ return $this->templates[$name];
64
+ }
65
+
66
+ public function getSourceContext($name)
67
+ {
68
+ $name = (string) $name;
69
+ if (!isset($this->templates[$name])) {
70
+ throw new LoaderError(sprintf('Template "%s" is not defined.', $name));
71
+ }
72
+
73
+ return new Source($this->templates[$name], $name);
74
+ }
75
+
76
+ public function exists($name)
77
+ {
78
+ return isset($this->templates[(string) $name]);
79
+ }
80
+
81
+ public function getCacheKey($name)
82
+ {
83
+ $name = (string) $name;
84
+ if (!isset($this->templates[$name])) {
85
+ throw new LoaderError(sprintf('Template "%s" is not defined.', $name));
86
+ }
87
+
88
+ return $name.':'.$this->templates[$name];
89
+ }
90
+
91
+ public function isFresh($name, $time)
92
+ {
93
+ $name = (string) $name;
94
+ if (!isset($this->templates[$name])) {
95
+ throw new LoaderError(sprintf('Template "%s" is not defined.', $name));
96
+ }
97
+
98
+ return true;
99
+ }
100
+ }
101
+
102
+ class_alias('Twig\Loader\ArrayLoader', 'Twig_Loader_Array');
vendor/twig/twig/src/Loader/ChainLoader.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Loader;
13
+
14
+ use Twig\Error\LoaderError;
15
+ use Twig\Source;
16
+
17
+ /**
18
+ * Loads templates from other loaders.
19
+ *
20
+ * @final
21
+ *
22
+ * @author Fabien Potencier <fabien@symfony.com>
23
+ */
24
+ class ChainLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
25
+ {
26
+ private $hasSourceCache = [];
27
+ protected $loaders = [];
28
+
29
+ /**
30
+ * @param LoaderInterface[] $loaders
31
+ */
32
+ public function __construct(array $loaders = [])
33
+ {
34
+ foreach ($loaders as $loader) {
35
+ $this->addLoader($loader);
36
+ }
37
+ }
38
+
39
+ public function addLoader(LoaderInterface $loader)
40
+ {
41
+ $this->loaders[] = $loader;
42
+ $this->hasSourceCache = [];
43
+ }
44
+
45
+ /**
46
+ * @return LoaderInterface[]
47
+ */
48
+ public function getLoaders()
49
+ {
50
+ return $this->loaders;
51
+ }
52
+
53
+ public function getSource($name)
54
+ {
55
+ @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED);
56
+
57
+ $exceptions = [];
58
+ foreach ($this->loaders as $loader) {
59
+ if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) {
60
+ continue;
61
+ }
62
+
63
+ try {
64
+ return $loader->getSource($name);
65
+ } catch (LoaderError $e) {
66
+ $exceptions[] = $e->getMessage();
67
+ }
68
+ }
69
+
70
+ throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
71
+ }
72
+
73
+ public function getSourceContext($name)
74
+ {
75
+ $exceptions = [];
76
+ foreach ($this->loaders as $loader) {
77
+ if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) {
78
+ continue;
79
+ }
80
+
81
+ try {
82
+ if ($loader instanceof SourceContextLoaderInterface) {
83
+ return $loader->getSourceContext($name);
84
+ }
85
+
86
+ return new Source($loader->getSource($name), $name);
87
+ } catch (LoaderError $e) {
88
+ $exceptions[] = $e->getMessage();
89
+ }
90
+ }
91
+
92
+ throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
93
+ }
94
+
95
+ public function exists($name)
96
+ {
97
+ $name = (string) $name;
98
+
99
+ if (isset($this->hasSourceCache[$name])) {
100
+ return $this->hasSourceCache[$name];
101
+ }
102
+
103
+ foreach ($this->loaders as $loader) {
104
+ if ($loader instanceof ExistsLoaderInterface) {
105
+ if ($loader->exists($name)) {
106
+ return $this->hasSourceCache[$name] = true;
107
+ }
108
+
109
+ continue;
110
+ }
111
+
112
+ try {
113
+ if ($loader instanceof SourceContextLoaderInterface) {
114
+ $loader->getSourceContext($name);
115
+ } else {
116
+ $loader->getSource($name);
117
+ }
118
+
119
+ return $this->hasSourceCache[$name] = true;
120
+ } catch (LoaderError $e) {
121
+ }
122
+ }
123
+
124
+ return $this->hasSourceCache[$name] = false;
125
+ }
126
+
127
+ public function getCacheKey($name)
128
+ {
129
+ $exceptions = [];
130
+ foreach ($this->loaders as $loader) {
131
+ if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) {
132
+ continue;
133
+ }
134
+
135
+ try {
136
+ return $loader->getCacheKey($name);
137
+ } catch (LoaderError $e) {
138
+ $exceptions[] = \get_class($loader).': '.$e->getMessage();
139
+ }
140
+ }
141
+
142
+ throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
143
+ }
144
+
145
+ public function isFresh($name, $time)
146
+ {
147
+ $exceptions = [];
148
+ foreach ($this->loaders as $loader) {
149
+ if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) {
150
+ continue;
151
+ }
152
+
153
+ try {
154
+ return $loader->isFresh($name, $time);
155
+ } catch (LoaderError $e) {
156
+ $exceptions[] = \get_class($loader).': '.$e->getMessage();
157
+ }
158
+ }
159
+
160
+ throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
161
+ }
162
+ }
163
+
164
+ class_alias('Twig\Loader\ChainLoader', 'Twig_Loader_Chain');
vendor/twig/twig/src/Loader/ExistsLoaderInterface.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Loader;
13
+
14
+ /**
15
+ * Adds an exists() method for loaders.
16
+ *
17
+ * @author Florin Patan <florinpatan@gmail.com>
18
+ *
19
+ * @deprecated since 1.12 (to be removed in 3.0)
20
+ */
21
+ interface ExistsLoaderInterface
22
+ {
23
+ /**
24
+ * Check if we have the source code of a template, given its name.
25
+ *
26
+ * @param string $name The name of the template to check if we can load
27
+ *
28
+ * @return bool If the template source code is handled by this loader or not
29
+ */
30
+ public function exists($name);
31
+ }
32
+
33
+ class_alias('Twig\Loader\ExistsLoaderInterface', 'Twig_ExistsLoaderInterface');
vendor/twig/twig/src/Loader/FilesystemLoader.php ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Loader;
13
+
14
+ use Twig\Error\LoaderError;
15
+ use Twig\Source;
16
+
17
+ /**
18
+ * Loads template from the filesystem.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
23
+ {
24
+ /** Identifier of the main namespace. */
25
+ const MAIN_NAMESPACE = '__main__';
26
+
27
+ protected $paths = [];
28
+ protected $cache = [];
29
+ protected $errorCache = [];
30
+
31
+ private $rootPath;
32
+
33
+ /**
34
+ * @param string|array $paths A path or an array of paths where to look for templates
35
+ * @param string|null $rootPath The root path common to all relative paths (null for getcwd())
36
+ */
37
+ public function __construct($paths = [], $rootPath = null)
38
+ {
39
+ $this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR;
40
+ if (false !== $realPath = realpath($rootPath)) {
41
+ $this->rootPath = $realPath.\DIRECTORY_SEPARATOR;
42
+ }
43
+
44
+ if ($paths) {
45
+ $this->setPaths($paths);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Returns the paths to the templates.
51
+ *
52
+ * @param string $namespace A path namespace
53
+ *
54
+ * @return array The array of paths where to look for templates
55
+ */
56
+ public function getPaths($namespace = self::MAIN_NAMESPACE)
57
+ {
58
+ return isset($this->paths[$namespace]) ? $this->paths[$namespace] : [];
59
+ }
60
+
61
+ /**
62
+ * Returns the path namespaces.
63
+ *
64
+ * The main namespace is always defined.
65
+ *
66
+ * @return array The array of defined namespaces
67
+ */
68
+ public function getNamespaces()
69
+ {
70
+ return array_keys($this->paths);
71
+ }
72
+
73
+ /**
74
+ * Sets the paths where templates are stored.
75
+ *
76
+ * @param string|array $paths A path or an array of paths where to look for templates
77
+ * @param string $namespace A path namespace
78
+ */
79
+ public function setPaths($paths, $namespace = self::MAIN_NAMESPACE)
80
+ {
81
+ if (!\is_array($paths)) {
82
+ $paths = [$paths];
83
+ }
84
+
85
+ $this->paths[$namespace] = [];
86
+ foreach ($paths as $path) {
87
+ $this->addPath($path, $namespace);
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Adds a path where templates are stored.
93
+ *
94
+ * @param string $path A path where to look for templates
95
+ * @param string $namespace A path namespace
96
+ *
97
+ * @throws LoaderError
98
+ */
99
+ public function addPath($path, $namespace = self::MAIN_NAMESPACE)
100
+ {
101
+ // invalidate the cache
102
+ $this->cache = $this->errorCache = [];
103
+
104
+ $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;
105
+ if (!is_dir($checkPath)) {
106
+ throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
107
+ }
108
+
109
+ $this->paths[$namespace][] = rtrim($path, '/\\');
110
+ }
111
+
112
+ /**
113
+ * Prepends a path where templates are stored.
114
+ *
115
+ * @param string $path A path where to look for templates
116
+ * @param string $namespace A path namespace
117
+ *
118
+ * @throws LoaderError
119
+ */
120
+ public function prependPath($path, $namespace = self::MAIN_NAMESPACE)
121
+ {
122
+ // invalidate the cache
123
+ $this->cache = $this->errorCache = [];
124
+
125
+ $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;
126
+ if (!is_dir($checkPath)) {
127
+ throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
128
+ }
129
+
130
+ $path = rtrim($path, '/\\');
131
+
132
+ if (!isset($this->paths[$namespace])) {
133
+ $this->paths[$namespace][] = $path;
134
+ } else {
135
+ array_unshift($this->paths[$namespace], $path);
136
+ }
137
+ }
138
+
139
+ public function getSource($name)
140
+ {
141
+ @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED);
142
+
143
+ if (null === ($path = $this->findTemplate($name)) || false === $path) {
144
+ return '';
145
+ }
146
+
147
+ return file_get_contents($path);
148
+ }
149
+
150
+ public function getSourceContext($name)
151
+ {
152
+ if (null === ($path = $this->findTemplate($name)) || false === $path) {
153
+ return new Source('', $name, '');
154
+ }
155
+
156
+ return new Source(file_get_contents($path), $name, $path);
157
+ }
158
+
159
+ public function getCacheKey($name)
160
+ {
161
+ if (null === ($path = $this->findTemplate($name)) || false === $path) {
162
+ return '';
163
+ }
164
+ $len = \strlen($this->rootPath);
165
+ if (0 === strncmp($this->rootPath, $path, $len)) {
166
+ return substr($path, $len);
167
+ }
168
+
169
+ return $path;
170
+ }
171
+
172
+ public function exists($name)
173
+ {
174
+ $name = $this->normalizeName($name);
175
+
176
+ if (isset($this->cache[$name])) {
177
+ return true;
178
+ }
179
+
180
+ try {
181
+ return null !== ($path = $this->findTemplate($name, false)) && false !== $path;
182
+ } catch (LoaderError $e) {
183
+ @trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', \get_class($this)), E_USER_DEPRECATED);
184
+
185
+ return false;
186
+ }
187
+ }
188
+
189
+ public function isFresh($name, $time)
190
+ {
191
+ // false support to be removed in 3.0
192
+ if (null === ($path = $this->findTemplate($name)) || false === $path) {
193
+ return false;
194
+ }
195
+
196
+ return filemtime($path) < $time;
197
+ }
198
+
199
+ /**
200
+ * Checks if the template can be found.
201
+ *
202
+ * @param string $name The template name
203
+ *
204
+ * @return string|false|null The template name or false/null
205
+ */
206
+ protected function findTemplate($name)
207
+ {
208
+ $throw = \func_num_args() > 1 ? func_get_arg(1) : true;
209
+ $name = $this->normalizeName($name);
210
+
211
+ if (isset($this->cache[$name])) {
212
+ return $this->cache[$name];
213
+ }
214
+
215
+ if (isset($this->errorCache[$name])) {
216
+ if (!$throw) {
217
+ return false;
218
+ }
219
+
220
+ throw new LoaderError($this->errorCache[$name]);
221
+ }
222
+
223
+ try {
224
+ $this->validateName($name);
225
+
226
+ list($namespace, $shortname) = $this->parseName($name);
227
+ } catch (LoaderError $e) {
228
+ if (!$throw) {
229
+ return false;
230
+ }
231
+
232
+ throw $e;
233
+ }
234
+
235
+ if (!isset($this->paths[$namespace])) {
236
+ $this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace);
237
+
238
+ if (!$throw) {
239
+ return false;
240
+ }
241
+
242
+ throw new LoaderError($this->errorCache[$name]);
243
+ }
244
+
245
+ foreach ($this->paths[$namespace] as $path) {
246
+ if (!$this->isAbsolutePath($path)) {
247
+ $path = $this->rootPath.$path;
248
+ }
249
+
250
+ if (is_file($path.'/'.$shortname)) {
251
+ if (false !== $realpath = realpath($path.'/'.$shortname)) {
252
+ return $this->cache[$name] = $realpath;
253
+ }
254
+
255
+ return $this->cache[$name] = $path.'/'.$shortname;
256
+ }
257
+ }
258
+
259
+ $this->errorCache[$name] = sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace]));
260
+
261
+ if (!$throw) {
262
+ return false;
263
+ }
264
+
265
+ throw new LoaderError($this->errorCache[$name]);
266
+ }
267
+
268
+ protected function parseName($name, $default = self::MAIN_NAMESPACE)
269
+ {
270
+ if (isset($name[0]) && '@' == $name[0]) {
271
+ if (false === $pos = strpos($name, '/')) {
272
+ throw new LoaderError(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name));
273
+ }
274
+
275
+ $namespace = substr($name, 1, $pos - 1);
276
+ $shortname = substr($name, $pos + 1);
277
+
278
+ return [$namespace, $shortname];
279
+ }
280
+
281
+ return [$default, $name];
282
+ }
283
+
284
+ protected function normalizeName($name)
285
+ {
286
+ return preg_replace('#/{2,}#', '/', str_replace('\\', '/', (string) $name));
287
+ }
288
+
289
+ protected function validateName($name)
290
+ {
291
+ if (false !== strpos($name, "\0")) {
292
+ throw new LoaderError('A template name cannot contain NUL bytes.');
293
+ }
294
+
295
+ $name = ltrim($name, '/');
296
+ $parts = explode('/', $name);
297
+ $level = 0;
298
+ foreach ($parts as $part) {
299
+ if ('..' === $part) {
300
+ --$level;
301
+ } elseif ('.' !== $part) {
302
+ ++$level;
303
+ }
304
+
305
+ if ($level < 0) {
306
+ throw new LoaderError(sprintf('Looks like you try to load a template outside configured directories (%s).', $name));
307
+ }
308
+ }
309
+ }
310
+
311
+ private function isAbsolutePath($file)
312
+ {
313
+ return strspn($file, '/\\', 0, 1)
314
+ || (\strlen($file) > 3 && ctype_alpha($file[0])
315
+ && ':' === substr($file, 1, 1)
316
+ && strspn($file, '/\\', 2, 1)
317
+ )
318
+ || null !== parse_url($file, PHP_URL_SCHEME)
319
+ ;
320
+ }
321
+ }
322
+
323
+ class_alias('Twig\Loader\FilesystemLoader', 'Twig_Loader_Filesystem');
vendor/twig/twig/src/Loader/LoaderInterface.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Loader;
13
+
14
+ use Twig\Error\LoaderError;
15
+
16
+ /**
17
+ * Interface all loaders must implement.
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ interface LoaderInterface
22
+ {
23
+ /**
24
+ * Gets the source code of a template, given its name.
25
+ *
26
+ * @param string $name The name of the template to load
27
+ *
28
+ * @return string The template source code
29
+ *
30
+ * @throws LoaderError When $name is not found
31
+ *
32
+ * @deprecated since 1.27 (to be removed in 2.0), implement Twig\Loader\SourceContextLoaderInterface
33
+ */
34
+ public function getSource($name);
35
+
36
+ /**
37
+ * Gets the cache key to use for the cache for a given template name.
38
+ *
39
+ * @param string $name The name of the template to load
40
+ *
41
+ * @return string The cache key
42
+ *
43
+ * @throws LoaderError When $name is not found
44
+ */
45
+ public function getCacheKey($name);
46
+
47
+ /**
48
+ * Returns true if the template is still fresh.
49
+ *
50
+ * @param string $name The template name
51
+ * @param int $time Timestamp of the last modification time of the
52
+ * cached template
53
+ *
54
+ * @return bool true if the template is fresh, false otherwise
55
+ *
56
+ * @throws LoaderError When $name is not found
57
+ */
58
+ public function isFresh($name, $time);
59
+ }
60
+
61
+ class_alias('Twig\Loader\LoaderInterface', 'Twig_LoaderInterface');
vendor/twig/twig/src/Loader/SourceContextLoaderInterface.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Loader;
13
+
14
+ use Twig\Error\LoaderError;
15
+ use Twig\Source;
16
+
17
+ /**
18
+ * Adds a getSourceContext() method for loaders.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ *
22
+ * @deprecated since 1.27 (to be removed in 3.0)
23
+ */
24
+ interface SourceContextLoaderInterface
25
+ {
26
+ /**
27
+ * Returns the source context for a given template logical name.
28
+ *
29
+ * @param string $name The template logical name
30
+ *
31
+ * @return Source
32
+ *
33
+ * @throws LoaderError When $name is not found
34
+ */
35
+ public function getSourceContext($name);
36
+ }
37
+
38
+ class_alias('Twig\Loader\SourceContextLoaderInterface', 'Twig_SourceContextLoaderInterface');
vendor/twig/twig/src/Markup.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig;
13
+
14
+ /**
15
+ * Marks a content as safe.
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ class Markup implements \Countable
20
+ {
21
+ protected $content;
22
+ protected $charset;
23
+
24
+ public function __construct($content, $charset)
25
+ {
26
+ $this->content = (string) $content;
27
+ $this->charset = $charset;
28
+ }
29
+
30
+ public function __toString()
31
+ {
32
+ return $this->content;
33
+ }
34
+
35
+ public function count()
36
+ {
37
+ return \function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : \strlen($this->content);
38
+ }
39
+ }
40
+
41
+ class_alias('Twig\Markup', 'Twig_Markup');
vendor/twig/twig/src/Node/AutoEscapeNode.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+
16
+ /**
17
+ * Represents an autoescape node.
18
+ *
19
+ * The value is the escaping strategy (can be html, js, ...)
20
+ *
21
+ * The true value is equivalent to html.
22
+ *
23
+ * If autoescaping is disabled, then the value is false.
24
+ *
25
+ * @author Fabien Potencier <fabien@symfony.com>
26
+ */
27
+ class AutoEscapeNode extends Node
28
+ {
29
+ public function __construct($value, \Twig_NodeInterface $body, $lineno, $tag = 'autoescape')
30
+ {
31
+ parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag);
32
+ }
33
+
34
+ public function compile(Compiler $compiler)
35
+ {
36
+ $compiler->subcompile($this->getNode('body'));
37
+ }
38
+ }
39
+
40
+ class_alias('Twig\Node\AutoEscapeNode', 'Twig_Node_AutoEscape');
vendor/twig/twig/src/Node/BlockNode.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node;
14
+
15
+ use Twig\Compiler;
16
+
17
+ /**
18
+ * Represents a block node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class BlockNode extends Node
23
+ {
24
+ public function __construct($name, \Twig_NodeInterface $body, $lineno, $tag = null)
25
+ {
26
+ parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag);
27
+ }
28
+
29
+ public function compile(Compiler $compiler)
30
+ {
31
+ $compiler
32
+ ->addDebugInfo($this)
33
+ ->write(sprintf("public function block_%s(\$context, array \$blocks = [])\n", $this->getAttribute('name')), "{\n")
34
+ ->indent()
35
+ ;
36
+
37
+ $compiler
38
+ ->subcompile($this->getNode('body'))
39
+ ->outdent()
40
+ ->write("}\n\n")
41
+ ;
42
+ }
43
+ }
44
+
45
+ class_alias('Twig\Node\BlockNode', 'Twig_Node_Block');
vendor/twig/twig/src/Node/BlockReferenceNode.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node;
14
+
15
+ use Twig\Compiler;
16
+
17
+ /**
18
+ * Represents a block call node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class BlockReferenceNode extends Node implements NodeOutputInterface
23
+ {
24
+ public function __construct($name, $lineno, $tag = null)
25
+ {
26
+ parent::__construct([], ['name' => $name], $lineno, $tag);
27
+ }
28
+
29
+ public function compile(Compiler $compiler)
30
+ {
31
+ $compiler
32
+ ->addDebugInfo($this)
33
+ ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name')))
34
+ ;
35
+ }
36
+ }
37
+
38
+ class_alias('Twig\Node\BlockReferenceNode', 'Twig_Node_BlockReference');
vendor/twig/twig/src/Node/BodyNode.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ /**
15
+ * Represents a body node.
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ class BodyNode extends Node
20
+ {
21
+ }
22
+
23
+ class_alias('Twig\Node\BodyNode', 'Twig_Node_Body');
vendor/twig/twig/src/Node/CheckSecurityNode.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+
16
+ /**
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ class CheckSecurityNode extends Node
20
+ {
21
+ protected $usedFilters;
22
+ protected $usedTags;
23
+ protected $usedFunctions;
24
+
25
+ public function __construct(array $usedFilters, array $usedTags, array $usedFunctions)
26
+ {
27
+ $this->usedFilters = $usedFilters;
28
+ $this->usedTags = $usedTags;
29
+ $this->usedFunctions = $usedFunctions;
30
+
31
+ parent::__construct();
32
+ }
33
+
34
+ public function compile(Compiler $compiler)
35
+ {
36
+ $tags = $filters = $functions = [];
37
+ foreach (['tags', 'filters', 'functions'] as $type) {
38
+ foreach ($this->{'used'.ucfirst($type)} as $name => $node) {
39
+ if ($node instanceof Node) {
40
+ ${$type}[$name] = $node->getTemplateLine();
41
+ } else {
42
+ ${$type}[$node] = null;
43
+ }
44
+ }
45
+ }
46
+
47
+ $compiler
48
+ ->write("\$this->sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');\n")
49
+ ->write('$tags = ')->repr(array_filter($tags))->raw(";\n")
50
+ ->write('$filters = ')->repr(array_filter($filters))->raw(";\n")
51
+ ->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n")
52
+ ->write("try {\n")
53
+ ->indent()
54
+ ->write("\$this->sandbox->checkSecurity(\n")
55
+ ->indent()
56
+ ->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n")
57
+ ->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n")
58
+ ->write(!$functions ? "[]\n" : "['".implode("', '", array_keys($functions))."']\n")
59
+ ->outdent()
60
+ ->write(");\n")
61
+ ->outdent()
62
+ ->write("} catch (SecurityError \$e) {\n")
63
+ ->indent()
64
+ ->write("\$e->setSourceContext(\$this->getSourceContext());\n\n")
65
+ ->write("if (\$e instanceof SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n")
66
+ ->indent()
67
+ ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n")
68
+ ->outdent()
69
+ ->write("} elseif (\$e instanceof SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n")
70
+ ->indent()
71
+ ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n")
72
+ ->outdent()
73
+ ->write("} elseif (\$e instanceof SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n")
74
+ ->indent()
75
+ ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n")
76
+ ->outdent()
77
+ ->write("}\n\n")
78
+ ->write("throw \$e;\n")
79
+ ->outdent()
80
+ ->write("}\n\n")
81
+ ;
82
+ }
83
+ }
84
+
85
+ class_alias('Twig\Node\CheckSecurityNode', 'Twig_Node_CheckSecurity');
vendor/twig/twig/src/Node/CheckToStringNode.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\AbstractExpression;
16
+
17
+ /**
18
+ * Checks if casting an expression to __toString() is allowed by the sandbox.
19
+ *
20
+ * For instance, when there is a simple Print statement, like {{ article }},
21
+ * and if the sandbox is enabled, we need to check that the __toString()
22
+ * method is allowed if 'article' is an object. The same goes for {{ article|upper }}
23
+ * or {{ random(article) }}
24
+ *
25
+ * @author Fabien Potencier <fabien@symfony.com>
26
+ */
27
+ class CheckToStringNode extends AbstractExpression
28
+ {
29
+ public function __construct(AbstractExpression $expr)
30
+ {
31
+ parent::__construct(['expr' => $expr], [], $expr->getTemplateLine(), $expr->getNodeTag());
32
+ }
33
+
34
+ public function compile(Compiler $compiler)
35
+ {
36
+ $compiler
37
+ ->raw('$this->sandbox->ensureToStringAllowed(')
38
+ ->subcompile($this->getNode('expr'))
39
+ ->raw(')')
40
+ ;
41
+ }
42
+ }
vendor/twig/twig/src/Node/DeprecatedNode.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\AbstractExpression;
16
+ use Twig\Node\Expression\ConstantExpression;
17
+
18
+ /**
19
+ * Represents a deprecated node.
20
+ *
21
+ * @author Yonel Ceruto <yonelceruto@gmail.com>
22
+ */
23
+ class DeprecatedNode extends Node
24
+ {
25
+ public function __construct(AbstractExpression $expr, $lineno, $tag = null)
26
+ {
27
+ parent::__construct(['expr' => $expr], [], $lineno, $tag);
28
+ }
29
+
30
+ public function compile(Compiler $compiler)
31
+ {
32
+ $compiler->addDebugInfo($this);
33
+
34
+ $expr = $this->getNode('expr');
35
+
36
+ if ($expr instanceof ConstantExpression) {
37
+ $compiler->write('@trigger_error(')
38
+ ->subcompile($expr);
39
+ } else {
40
+ $varName = $compiler->getVarName();
41
+ $compiler->write(sprintf('$%s = ', $varName))
42
+ ->subcompile($expr)
43
+ ->raw(";\n")
44
+ ->write(sprintf('@trigger_error($%s', $varName));
45
+ }
46
+
47
+ $compiler
48
+ ->raw('.')
49
+ ->string(sprintf(' ("%s" at line %d).', $this->getTemplateName(), $this->getTemplateLine()))
50
+ ->raw(", E_USER_DEPRECATED);\n")
51
+ ;
52
+ }
53
+ }
54
+
55
+ class_alias('Twig\Node\DeprecatedNode', 'Twig_Node_Deprecated');
vendor/twig/twig/src/Node/DoNode.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\AbstractExpression;
16
+
17
+ /**
18
+ * Represents a do node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class DoNode extends Node
23
+ {
24
+ public function __construct(AbstractExpression $expr, $lineno, $tag = null)
25
+ {
26
+ parent::__construct(['expr' => $expr], [], $lineno, $tag);
27
+ }
28
+
29
+ public function compile(Compiler $compiler)
30
+ {
31
+ $compiler
32
+ ->addDebugInfo($this)
33
+ ->write('')
34
+ ->subcompile($this->getNode('expr'))
35
+ ->raw(";\n")
36
+ ;
37
+ }
38
+ }
39
+
40
+ class_alias('Twig\Node\DoNode', 'Twig_Node_Do');
vendor/twig/twig/src/Node/EmbedNode.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\AbstractExpression;
16
+ use Twig\Node\Expression\ConstantExpression;
17
+
18
+ /**
19
+ * Represents an embed node.
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class EmbedNode extends IncludeNode
24
+ {
25
+ // we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module)
26
+ public function __construct($name, $index, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
27
+ {
28
+ parent::__construct(new ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag);
29
+
30
+ $this->setAttribute('name', $name);
31
+ // to be removed in 2.0, used name instead
32
+ $this->setAttribute('filename', $name);
33
+ $this->setAttribute('index', $index);
34
+ }
35
+
36
+ protected function addGetTemplate(Compiler $compiler)
37
+ {
38
+ $compiler
39
+ ->write('$this->loadTemplate(')
40
+ ->string($this->getAttribute('name'))
41
+ ->raw(', ')
42
+ ->repr($this->getTemplateName())
43
+ ->raw(', ')
44
+ ->repr($this->getTemplateLine())
45
+ ->raw(', ')
46
+ ->string($this->getAttribute('index'))
47
+ ->raw(')')
48
+ ;
49
+ }
50
+ }
51
+
52
+ class_alias('Twig\Node\EmbedNode', 'Twig_Node_Embed');
vendor/twig/twig/src/Node/Expression/AbstractExpression.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression;
14
+
15
+ use Twig\Node\Node;
16
+
17
+ /**
18
+ * Abstract class for all nodes that represents an expression.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ abstract class AbstractExpression extends Node
23
+ {
24
+ }
25
+
26
+ class_alias('Twig\Node\Expression\AbstractExpression', 'Twig_Node_Expression');
vendor/twig/twig/src/Node/Expression/ArrayExpression.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class ArrayExpression extends AbstractExpression
17
+ {
18
+ protected $index;
19
+
20
+ public function __construct(array $elements, $lineno)
21
+ {
22
+ parent::__construct($elements, [], $lineno);
23
+
24
+ $this->index = -1;
25
+ foreach ($this->getKeyValuePairs() as $pair) {
26
+ if ($pair['key'] instanceof ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) {
27
+ $this->index = $pair['key']->getAttribute('value');
28
+ }
29
+ }
30
+ }
31
+
32
+ public function getKeyValuePairs()
33
+ {
34
+ $pairs = [];
35
+
36
+ foreach (array_chunk($this->nodes, 2) as $pair) {
37
+ $pairs[] = [
38
+ 'key' => $pair[0],
39
+ 'value' => $pair[1],
40
+ ];
41
+ }
42
+
43
+ return $pairs;
44
+ }
45
+
46
+ public function hasElement(AbstractExpression $key)
47
+ {
48
+ foreach ($this->getKeyValuePairs() as $pair) {
49
+ // we compare the string representation of the keys
50
+ // to avoid comparing the line numbers which are not relevant here.
51
+ if ((string) $key === (string) $pair['key']) {
52
+ return true;
53
+ }
54
+ }
55
+
56
+ return false;
57
+ }
58
+
59
+ public function addElement(AbstractExpression $value, AbstractExpression $key = null)
60
+ {
61
+ if (null === $key) {
62
+ $key = new ConstantExpression(++$this->index, $value->getTemplateLine());
63
+ }
64
+
65
+ array_push($this->nodes, $key, $value);
66
+ }
67
+
68
+ public function compile(Compiler $compiler)
69
+ {
70
+ $compiler->raw('[');
71
+ $first = true;
72
+ foreach ($this->getKeyValuePairs() as $pair) {
73
+ if (!$first) {
74
+ $compiler->raw(', ');
75
+ }
76
+ $first = false;
77
+
78
+ $compiler
79
+ ->subcompile($pair['key'])
80
+ ->raw(' => ')
81
+ ->subcompile($pair['value'])
82
+ ;
83
+ }
84
+ $compiler->raw(']');
85
+ }
86
+ }
87
+
88
+ class_alias('Twig\Node\Expression\ArrayExpression', 'Twig_Node_Expression_Array');
vendor/twig/twig/src/Node/Expression/ArrowFunctionExpression.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Node;
16
+
17
+ /**
18
+ * Represents an arrow function.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class ArrowFunctionExpression extends AbstractExpression
23
+ {
24
+ public function __construct(AbstractExpression $expr, Node $names, $lineno, $tag = null)
25
+ {
26
+ parent::__construct(['expr' => $expr, 'names' => $names], [], $lineno, $tag);
27
+ }
28
+
29
+ public function compile(Compiler $compiler)
30
+ {
31
+ $compiler
32
+ ->addDebugInfo($this)
33
+ ->raw('function (')
34
+ ;
35
+ foreach ($this->getNode('names') as $i => $name) {
36
+ if ($i) {
37
+ $compiler->raw(', ');
38
+ }
39
+
40
+ $compiler
41
+ ->raw('$__')
42
+ ->raw($name->getAttribute('name'))
43
+ ->raw('__')
44
+ ;
45
+ }
46
+ $compiler
47
+ ->raw(') use ($context) { ')
48
+ ;
49
+ foreach ($this->getNode('names') as $name) {
50
+ $compiler
51
+ ->raw('$context["')
52
+ ->raw($name->getAttribute('name'))
53
+ ->raw('"] = $__')
54
+ ->raw($name->getAttribute('name'))
55
+ ->raw('__; ')
56
+ ;
57
+ }
58
+ $compiler
59
+ ->raw('return ')
60
+ ->subcompile($this->getNode('expr'))
61
+ ->raw('; }')
62
+ ;
63
+ }
64
+ }
vendor/twig/twig/src/Node/Expression/AssignNameExpression.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class AssignNameExpression extends NameExpression
18
+ {
19
+ public function compile(Compiler $compiler)
20
+ {
21
+ $compiler
22
+ ->raw('$context[')
23
+ ->string($this->getAttribute('name'))
24
+ ->raw(']')
25
+ ;
26
+ }
27
+ }
28
+
29
+ class_alias('Twig\Node\Expression\AssignNameExpression', 'Twig_Node_Expression_AssignName');
vendor/twig/twig/src/Node/Expression/Binary/AbstractBinary.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\Node\Expression\AbstractExpression;
17
+
18
+ abstract class AbstractBinary extends AbstractExpression
19
+ {
20
+ public function __construct(\Twig_NodeInterface $left, \Twig_NodeInterface $right, $lineno)
21
+ {
22
+ parent::__construct(['left' => $left, 'right' => $right], [], $lineno);
23
+ }
24
+
25
+ public function compile(Compiler $compiler)
26
+ {
27
+ $compiler
28
+ ->raw('(')
29
+ ->subcompile($this->getNode('left'))
30
+ ->raw(' ')
31
+ ;
32
+ $this->operator($compiler);
33
+ $compiler
34
+ ->raw(' ')
35
+ ->subcompile($this->getNode('right'))
36
+ ->raw(')')
37
+ ;
38
+ }
39
+
40
+ abstract public function operator(Compiler $compiler);
41
+ }
42
+
43
+ class_alias('Twig\Node\Expression\Binary\AbstractBinary', 'Twig_Node_Expression_Binary');
vendor/twig/twig/src/Node/Expression/Binary/AddBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class AddBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('+');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\AddBinary', 'Twig_Node_Expression_Binary_Add');
vendor/twig/twig/src/Node/Expression/Binary/AndBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class AndBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('&&');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\AndBinary', 'Twig_Node_Expression_Binary_And');
vendor/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class BitwiseAndBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('&');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\BitwiseAndBinary', 'Twig_Node_Expression_Binary_BitwiseAnd');
vendor/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class BitwiseOrBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('|');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\BitwiseOrBinary', 'Twig_Node_Expression_Binary_BitwiseOr');
vendor/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class BitwiseXorBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('^');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\BitwiseXorBinary', 'Twig_Node_Expression_Binary_BitwiseXor');
vendor/twig/twig/src/Node/Expression/Binary/ConcatBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class ConcatBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('.');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\ConcatBinary', 'Twig_Node_Expression_Binary_Concat');
vendor/twig/twig/src/Node/Expression/Binary/DivBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class DivBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('/');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\DivBinary', 'Twig_Node_Expression_Binary_Div');
vendor/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class EndsWithBinary extends AbstractBinary
17
+ {
18
+ public function compile(Compiler $compiler)
19
+ {
20
+ $left = $compiler->getVarName();
21
+ $right = $compiler->getVarName();
22
+ $compiler
23
+ ->raw(sprintf('(is_string($%s = ', $left))
24
+ ->subcompile($this->getNode('left'))
25
+ ->raw(sprintf(') && is_string($%s = ', $right))
26
+ ->subcompile($this->getNode('right'))
27
+ ->raw(sprintf(') && (\'\' === $%2$s || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right))
28
+ ;
29
+ }
30
+
31
+ public function operator(Compiler $compiler)
32
+ {
33
+ return $compiler->raw('');
34
+ }
35
+ }
36
+
37
+ class_alias('Twig\Node\Expression\Binary\EndsWithBinary', 'Twig_Node_Expression_Binary_EndsWith');
vendor/twig/twig/src/Node/Expression/Binary/EqualBinary.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class EqualBinary extends AbstractBinary
17
+ {
18
+ public function operator(Compiler $compiler)
19
+ {
20
+ return $compiler->raw('==');
21
+ }
22
+ }
23
+
24
+ class_alias('Twig\Node\Expression\Binary\EqualBinary', 'Twig_Node_Expression_Binary_Equal');
vendor/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class FloorDivBinary extends AbstractBinary
17
+ {
18
+ public function compile(Compiler $compiler)
19
+ {
20
+ $compiler->raw('(int) floor(');
21
+ parent::compile($compiler);
22
+ $compiler->raw(')');
23
+ }
24
+
25
+ public function operator(Compiler $compiler)
26
+ {
27
+ return $compiler->raw('/');
28
+ }
29
+ }
30
+
31
+ class_alias('Twig\Node\Expression\Binary\FloorDivBinary', 'Twig_Node_Expression_Binary_FloorDiv');
vendor/twig/twig/src/Node/Expression/Binary/GreaterBinary.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class GreaterBinary extends AbstractBinary
17
+ {
18
+ public function operator(Compiler $compiler)
19
+ {
20
+ return $compiler->raw('>');
21
+ }
22
+ }
23
+
24
+ class_alias('Twig\Node\Expression\Binary\GreaterBinary', 'Twig_Node_Expression_Binary_Greater');
vendor/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class GreaterEqualBinary extends AbstractBinary
17
+ {
18
+ public function operator(Compiler $compiler)
19
+ {
20
+ return $compiler->raw('>=');
21
+ }
22
+ }
23
+
24
+ class_alias('Twig\Node\Expression\Binary\GreaterEqualBinary', 'Twig_Node_Expression_Binary_GreaterEqual');
vendor/twig/twig/src/Node/Expression/Binary/InBinary.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class InBinary extends AbstractBinary
17
+ {
18
+ public function compile(Compiler $compiler)
19
+ {
20
+ $compiler
21
+ ->raw('twig_in_filter(')
22
+ ->subcompile($this->getNode('left'))
23
+ ->raw(', ')
24
+ ->subcompile($this->getNode('right'))
25
+ ->raw(')')
26
+ ;
27
+ }
28
+
29
+ public function operator(Compiler $compiler)
30
+ {
31
+ return $compiler->raw('in');
32
+ }
33
+ }
34
+
35
+ class_alias('Twig\Node\Expression\Binary\InBinary', 'Twig_Node_Expression_Binary_In');
vendor/twig/twig/src/Node/Expression/Binary/LessBinary.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class LessBinary extends AbstractBinary
17
+ {
18
+ public function operator(Compiler $compiler)
19
+ {
20
+ return $compiler->raw('<');
21
+ }
22
+ }
23
+
24
+ class_alias('Twig\Node\Expression\Binary\LessBinary', 'Twig_Node_Expression_Binary_Less');
vendor/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class LessEqualBinary extends AbstractBinary
17
+ {
18
+ public function operator(Compiler $compiler)
19
+ {
20
+ return $compiler->raw('<=');
21
+ }
22
+ }
23
+
24
+ class_alias('Twig\Node\Expression\Binary\LessEqualBinary', 'Twig_Node_Expression_Binary_LessEqual');
vendor/twig/twig/src/Node/Expression/Binary/MatchesBinary.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class MatchesBinary extends AbstractBinary
17
+ {
18
+ public function compile(Compiler $compiler)
19
+ {
20
+ $compiler
21
+ ->raw('preg_match(')
22
+ ->subcompile($this->getNode('right'))
23
+ ->raw(', ')
24
+ ->subcompile($this->getNode('left'))
25
+ ->raw(')')
26
+ ;
27
+ }
28
+
29
+ public function operator(Compiler $compiler)
30
+ {
31
+ return $compiler->raw('');
32
+ }
33
+ }
34
+
35
+ class_alias('Twig\Node\Expression\Binary\MatchesBinary', 'Twig_Node_Expression_Binary_Matches');
vendor/twig/twig/src/Node/Expression/Binary/ModBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class ModBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('%');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\ModBinary', 'Twig_Node_Expression_Binary_Mod');
vendor/twig/twig/src/Node/Expression/Binary/MulBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class MulBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('*');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\MulBinary', 'Twig_Node_Expression_Binary_Mul');
vendor/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class NotEqualBinary extends AbstractBinary
17
+ {
18
+ public function operator(Compiler $compiler)
19
+ {
20
+ return $compiler->raw('!=');
21
+ }
22
+ }
23
+
24
+ class_alias('Twig\Node\Expression\Binary\NotEqualBinary', 'Twig_Node_Expression_Binary_NotEqual');
vendor/twig/twig/src/Node/Expression/Binary/NotInBinary.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class NotInBinary extends AbstractBinary
17
+ {
18
+ public function compile(Compiler $compiler)
19
+ {
20
+ $compiler
21
+ ->raw('!twig_in_filter(')
22
+ ->subcompile($this->getNode('left'))
23
+ ->raw(', ')
24
+ ->subcompile($this->getNode('right'))
25
+ ->raw(')')
26
+ ;
27
+ }
28
+
29
+ public function operator(Compiler $compiler)
30
+ {
31
+ return $compiler->raw('not in');
32
+ }
33
+ }
34
+
35
+ class_alias('Twig\Node\Expression\Binary\NotInBinary', 'Twig_Node_Expression_Binary_NotIn');
vendor/twig/twig/src/Node/Expression/Binary/OrBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class OrBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('||');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\OrBinary', 'Twig_Node_Expression_Binary_Or');
vendor/twig/twig/src/Node/Expression/Binary/PowerBinary.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class PowerBinary extends AbstractBinary
17
+ {
18
+ public function compile(Compiler $compiler)
19
+ {
20
+ if (\PHP_VERSION_ID >= 50600) {
21
+ return parent::compile($compiler);
22
+ }
23
+
24
+ $compiler
25
+ ->raw('pow(')
26
+ ->subcompile($this->getNode('left'))
27
+ ->raw(', ')
28
+ ->subcompile($this->getNode('right'))
29
+ ->raw(')')
30
+ ;
31
+ }
32
+
33
+ public function operator(Compiler $compiler)
34
+ {
35
+ return $compiler->raw('**');
36
+ }
37
+ }
38
+
39
+ class_alias('Twig\Node\Expression\Binary\PowerBinary', 'Twig_Node_Expression_Binary_Power');
vendor/twig/twig/src/Node/Expression/Binary/RangeBinary.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class RangeBinary extends AbstractBinary
17
+ {
18
+ public function compile(Compiler $compiler)
19
+ {
20
+ $compiler
21
+ ->raw('range(')
22
+ ->subcompile($this->getNode('left'))
23
+ ->raw(', ')
24
+ ->subcompile($this->getNode('right'))
25
+ ->raw(')')
26
+ ;
27
+ }
28
+
29
+ public function operator(Compiler $compiler)
30
+ {
31
+ return $compiler->raw('..');
32
+ }
33
+ }
34
+
35
+ class_alias('Twig\Node\Expression\Binary\RangeBinary', 'Twig_Node_Expression_Binary_Range');
vendor/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Binary;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class StartsWithBinary extends AbstractBinary
17
+ {
18
+ public function compile(Compiler $compiler)
19
+ {
20
+ $left = $compiler->getVarName();
21
+ $right = $compiler->getVarName();
22
+ $compiler
23
+ ->raw(sprintf('(is_string($%s = ', $left))
24
+ ->subcompile($this->getNode('left'))
25
+ ->raw(sprintf(') && is_string($%s = ', $right))
26
+ ->subcompile($this->getNode('right'))
27
+ ->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right))
28
+ ;
29
+ }
30
+
31
+ public function operator(Compiler $compiler)
32
+ {
33
+ return $compiler->raw('');
34
+ }
35
+ }
36
+
37
+ class_alias('Twig\Node\Expression\Binary\StartsWithBinary', 'Twig_Node_Expression_Binary_StartsWith');
vendor/twig/twig/src/Node/Expression/Binary/SubBinary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Binary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class SubBinary extends AbstractBinary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ return $compiler->raw('-');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Binary\SubBinary', 'Twig_Node_Expression_Binary_Sub');
vendor/twig/twig/src/Node/Expression/BlockReferenceExpression.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\Node\Node;
17
+
18
+ /**
19
+ * Represents a block call node.
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class BlockReferenceExpression extends AbstractExpression
24
+ {
25
+ /**
26
+ * @param Node|null $template
27
+ */
28
+ public function __construct(\Twig_NodeInterface $name, $template = null, $lineno, $tag = null)
29
+ {
30
+ if (\is_bool($template)) {
31
+ @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
32
+
33
+ $template = null;
34
+ }
35
+
36
+ $nodes = ['name' => $name];
37
+ if (null !== $template) {
38
+ $nodes['template'] = $template;
39
+ }
40
+
41
+ parent::__construct($nodes, ['is_defined_test' => false, 'output' => false], $lineno, $tag);
42
+ }
43
+
44
+ public function compile(Compiler $compiler)
45
+ {
46
+ if ($this->getAttribute('is_defined_test')) {
47
+ $this->compileTemplateCall($compiler, 'hasBlock');
48
+ } else {
49
+ if ($this->getAttribute('output')) {
50
+ $compiler->addDebugInfo($this);
51
+
52
+ $this
53
+ ->compileTemplateCall($compiler, 'displayBlock')
54
+ ->raw(";\n");
55
+ } else {
56
+ $this->compileTemplateCall($compiler, 'renderBlock');
57
+ }
58
+ }
59
+ }
60
+
61
+ private function compileTemplateCall(Compiler $compiler, $method)
62
+ {
63
+ if (!$this->hasNode('template')) {
64
+ $compiler->write('$this');
65
+ } else {
66
+ $compiler
67
+ ->write('$this->loadTemplate(')
68
+ ->subcompile($this->getNode('template'))
69
+ ->raw(', ')
70
+ ->repr($this->getTemplateName())
71
+ ->raw(', ')
72
+ ->repr($this->getTemplateLine())
73
+ ->raw(')')
74
+ ;
75
+ }
76
+
77
+ $compiler->raw(sprintf('->%s', $method));
78
+ $this->compileBlockArguments($compiler);
79
+
80
+ return $compiler;
81
+ }
82
+
83
+ private function compileBlockArguments(Compiler $compiler)
84
+ {
85
+ $compiler
86
+ ->raw('(')
87
+ ->subcompile($this->getNode('name'))
88
+ ->raw(', $context');
89
+
90
+ if (!$this->hasNode('template')) {
91
+ $compiler->raw(', $blocks');
92
+ }
93
+
94
+ return $compiler->raw(')');
95
+ }
96
+ }
97
+
98
+ class_alias('Twig\Node\Expression\BlockReferenceExpression', 'Twig_Node_Expression_BlockReference');
vendor/twig/twig/src/Node/Expression/CallExpression.php ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Error\SyntaxError;
16
+ use Twig\Extension\ExtensionInterface;
17
+ use Twig\Node\Node;
18
+
19
+ abstract class CallExpression extends AbstractExpression
20
+ {
21
+ private $reflector;
22
+
23
+ protected function compileCallable(Compiler $compiler)
24
+ {
25
+ $closingParenthesis = false;
26
+ $isArray = false;
27
+ if ($this->hasAttribute('callable') && $callable = $this->getAttribute('callable')) {
28
+ if (\is_string($callable) && false === strpos($callable, '::')) {
29
+ $compiler->raw($callable);
30
+ } else {
31
+ list($r, $callable) = $this->reflectCallable($callable);
32
+ if ($r instanceof \ReflectionMethod && \is_string($callable[0])) {
33
+ if ($r->isStatic()) {
34
+ $compiler->raw(sprintf('%s::%s', $callable[0], $callable[1]));
35
+ } else {
36
+ $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1]));
37
+ }
38
+ } elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof ExtensionInterface) {
39
+ $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($callable[0]), $callable[1]));
40
+ } else {
41
+ $type = ucfirst($this->getAttribute('type'));
42
+ $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), ', $type, $this->getAttribute('name')));
43
+ $closingParenthesis = true;
44
+ $isArray = true;
45
+ }
46
+ }
47
+ } else {
48
+ $compiler->raw($this->getAttribute('thing')->compile());
49
+ }
50
+
51
+ $this->compileArguments($compiler, $isArray);
52
+
53
+ if ($closingParenthesis) {
54
+ $compiler->raw(')');
55
+ }
56
+ }
57
+
58
+ protected function compileArguments(Compiler $compiler, $isArray = false)
59
+ {
60
+ $compiler->raw($isArray ? '[' : '(');
61
+
62
+ $first = true;
63
+
64
+ if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) {
65
+ $compiler->raw('$this->env');
66
+ $first = false;
67
+ }
68
+
69
+ if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) {
70
+ if (!$first) {
71
+ $compiler->raw(', ');
72
+ }
73
+ $compiler->raw('$context');
74
+ $first = false;
75
+ }
76
+
77
+ if ($this->hasAttribute('arguments')) {
78
+ foreach ($this->getAttribute('arguments') as $argument) {
79
+ if (!$first) {
80
+ $compiler->raw(', ');
81
+ }
82
+ $compiler->string($argument);
83
+ $first = false;
84
+ }
85
+ }
86
+
87
+ if ($this->hasNode('node')) {
88
+ if (!$first) {
89
+ $compiler->raw(', ');
90
+ }
91
+ $compiler->subcompile($this->getNode('node'));
92
+ $first = false;
93
+ }
94
+
95
+ if ($this->hasNode('arguments')) {
96
+ $callable = $this->hasAttribute('callable') ? $this->getAttribute('callable') : null;
97
+
98
+ $arguments = $this->getArguments($callable, $this->getNode('arguments'));
99
+
100
+ foreach ($arguments as $node) {
101
+ if (!$first) {
102
+ $compiler->raw(', ');
103
+ }
104
+ $compiler->subcompile($node);
105
+ $first = false;
106
+ }
107
+ }
108
+
109
+ $compiler->raw($isArray ? ']' : ')');
110
+ }
111
+
112
+ protected function getArguments($callable, $arguments)
113
+ {
114
+ $callType = $this->getAttribute('type');
115
+ $callName = $this->getAttribute('name');
116
+
117
+ $parameters = [];
118
+ $named = false;
119
+ foreach ($arguments as $name => $node) {
120
+ if (!\is_int($name)) {
121
+ $named = true;
122
+ $name = $this->normalizeName($name);
123
+ } elseif ($named) {
124
+ throw new SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine(), $this->getSourceContext());
125
+ }
126
+
127
+ $parameters[$name] = $node;
128
+ }
129
+
130
+ $isVariadic = $this->hasAttribute('is_variadic') && $this->getAttribute('is_variadic');
131
+ if (!$named && !$isVariadic) {
132
+ return $parameters;
133
+ }
134
+
135
+ if (!$callable) {
136
+ if ($named) {
137
+ $message = sprintf('Named arguments are not supported for %s "%s".', $callType, $callName);
138
+ } else {
139
+ $message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName);
140
+ }
141
+
142
+ throw new \LogicException($message);
143
+ }
144
+
145
+ $callableParameters = $this->getCallableParameters($callable, $isVariadic);
146
+ $arguments = [];
147
+ $names = [];
148
+ $missingArguments = [];
149
+ $optionalArguments = [];
150
+ $pos = 0;
151
+ foreach ($callableParameters as $callableParameter) {
152
+ $names[] = $name = $this->normalizeName($callableParameter->name);
153
+
154
+ if (\array_key_exists($name, $parameters)) {
155
+ if (\array_key_exists($pos, $parameters)) {
156
+ throw new SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext());
157
+ }
158
+
159
+ if (\count($missingArguments)) {
160
+ throw new SyntaxError(sprintf(
161
+ 'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".',
162
+ $name, $callType, $callName, implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments)
163
+ ), $this->getTemplateLine(), $this->getSourceContext());
164
+ }
165
+
166
+ $arguments = array_merge($arguments, $optionalArguments);
167
+ $arguments[] = $parameters[$name];
168
+ unset($parameters[$name]);
169
+ $optionalArguments = [];
170
+ } elseif (\array_key_exists($pos, $parameters)) {
171
+ $arguments = array_merge($arguments, $optionalArguments);
172
+ $arguments[] = $parameters[$pos];
173
+ unset($parameters[$pos]);
174
+ $optionalArguments = [];
175
+ ++$pos;
176
+ } elseif ($callableParameter->isDefaultValueAvailable()) {
177
+ $optionalArguments[] = new ConstantExpression($callableParameter->getDefaultValue(), -1);
178
+ } elseif ($callableParameter->isOptional()) {
179
+ if (empty($parameters)) {
180
+ break;
181
+ } else {
182
+ $missingArguments[] = $name;
183
+ }
184
+ } else {
185
+ throw new SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext());
186
+ }
187
+ }
188
+
189
+ if ($isVariadic) {
190
+ $arbitraryArguments = new ArrayExpression([], -1);
191
+ foreach ($parameters as $key => $value) {
192
+ if (\is_int($key)) {
193
+ $arbitraryArguments->addElement($value);
194
+ } else {
195
+ $arbitraryArguments->addElement($value, new ConstantExpression($key, -1));
196
+ }
197
+ unset($parameters[$key]);
198
+ }
199
+
200
+ if ($arbitraryArguments->count()) {
201
+ $arguments = array_merge($arguments, $optionalArguments);
202
+ $arguments[] = $arbitraryArguments;
203
+ }
204
+ }
205
+
206
+ if (!empty($parameters)) {
207
+ $unknownParameter = null;
208
+ foreach ($parameters as $parameter) {
209
+ if ($parameter instanceof Node) {
210
+ $unknownParameter = $parameter;
211
+ break;
212
+ }
213
+ }
214
+
215
+ throw new SyntaxError(
216
+ sprintf(
217
+ 'Unknown argument%s "%s" for %s "%s(%s)".',
218
+ \count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names)
219
+ ),
220
+ $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine(),
221
+ $unknownParameter ? $unknownParameter->getSourceContext() : $this->getSourceContext()
222
+ );
223
+ }
224
+
225
+ return $arguments;
226
+ }
227
+
228
+ protected function normalizeName($name)
229
+ {
230
+ return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name));
231
+ }
232
+
233
+ private function getCallableParameters($callable, $isVariadic)
234
+ {
235
+ list($r) = $this->reflectCallable($callable);
236
+ if (null === $r) {
237
+ return [];
238
+ }
239
+
240
+ $parameters = $r->getParameters();
241
+ if ($this->hasNode('node')) {
242
+ array_shift($parameters);
243
+ }
244
+ if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) {
245
+ array_shift($parameters);
246
+ }
247
+ if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) {
248
+ array_shift($parameters);
249
+ }
250
+ if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) {
251
+ foreach ($this->getAttribute('arguments') as $argument) {
252
+ array_shift($parameters);
253
+ }
254
+ }
255
+ if ($isVariadic) {
256
+ $argument = end($parameters);
257
+ if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) {
258
+ array_pop($parameters);
259
+ } else {
260
+ $callableName = $r->name;
261
+ if ($r instanceof \ReflectionMethod) {
262
+ $callableName = $r->getDeclaringClass()->name.'::'.$callableName;
263
+ }
264
+
265
+ throw new \LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $this->getAttribute('name')));
266
+ }
267
+ }
268
+
269
+ return $parameters;
270
+ }
271
+
272
+ private function reflectCallable($callable)
273
+ {
274
+ if (null !== $this->reflector) {
275
+ return $this->reflector;
276
+ }
277
+
278
+ if (\is_array($callable)) {
279
+ if (!method_exists($callable[0], $callable[1])) {
280
+ // __call()
281
+ return [null, []];
282
+ }
283
+ $r = new \ReflectionMethod($callable[0], $callable[1]);
284
+ } elseif (\is_object($callable) && !$callable instanceof \Closure) {
285
+ $r = new \ReflectionObject($callable);
286
+ $r = $r->getMethod('__invoke');
287
+ $callable = [$callable, '__invoke'];
288
+ } elseif (\is_string($callable) && false !== $pos = strpos($callable, '::')) {
289
+ $class = substr($callable, 0, $pos);
290
+ $method = substr($callable, $pos + 2);
291
+ if (!method_exists($class, $method)) {
292
+ // __staticCall()
293
+ return [null, []];
294
+ }
295
+ $r = new \ReflectionMethod($callable);
296
+ $callable = [$class, $method];
297
+ } else {
298
+ $r = new \ReflectionFunction($callable);
299
+ }
300
+
301
+ return $this->reflector = [$r, $callable];
302
+ }
303
+ }
304
+
305
+ class_alias('Twig\Node\Expression\CallExpression', 'Twig_Node_Expression_Call');
vendor/twig/twig/src/Node/Expression/ConditionalExpression.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class ConditionalExpression extends AbstractExpression
18
+ {
19
+ public function __construct(AbstractExpression $expr1, AbstractExpression $expr2, AbstractExpression $expr3, $lineno)
20
+ {
21
+ parent::__construct(['expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno);
22
+ }
23
+
24
+ public function compile(Compiler $compiler)
25
+ {
26
+ $compiler
27
+ ->raw('((')
28
+ ->subcompile($this->getNode('expr1'))
29
+ ->raw(') ? (')
30
+ ->subcompile($this->getNode('expr2'))
31
+ ->raw(') : (')
32
+ ->subcompile($this->getNode('expr3'))
33
+ ->raw('))')
34
+ ;
35
+ }
36
+ }
37
+
38
+ class_alias('Twig\Node\Expression\ConditionalExpression', 'Twig_Node_Expression_Conditional');
vendor/twig/twig/src/Node/Expression/ConstantExpression.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class ConstantExpression extends AbstractExpression
18
+ {
19
+ public function __construct($value, $lineno)
20
+ {
21
+ parent::__construct([], ['value' => $value], $lineno);
22
+ }
23
+
24
+ public function compile(Compiler $compiler)
25
+ {
26
+ $compiler->repr($this->getAttribute('value'));
27
+ }
28
+ }
29
+
30
+ class_alias('Twig\Node\Expression\ConstantExpression', 'Twig_Node_Expression_Constant');
vendor/twig/twig/src/Node/Expression/Filter/DefaultFilter.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Filter;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\ConditionalExpression;
16
+ use Twig\Node\Expression\ConstantExpression;
17
+ use Twig\Node\Expression\FilterExpression;
18
+ use Twig\Node\Expression\GetAttrExpression;
19
+ use Twig\Node\Expression\NameExpression;
20
+ use Twig\Node\Expression\Test\DefinedTest;
21
+ use Twig\Node\Node;
22
+
23
+ /**
24
+ * Returns the value or the default value when it is undefined or empty.
25
+ *
26
+ * {{ var.foo|default('foo item on var is not defined') }}
27
+ *
28
+ * @author Fabien Potencier <fabien@symfony.com>
29
+ */
30
+ class DefaultFilter extends FilterExpression
31
+ {
32
+ public function __construct(\Twig_NodeInterface $node, ConstantExpression $filterName, \Twig_NodeInterface $arguments, $lineno, $tag = null)
33
+ {
34
+ $default = new FilterExpression($node, new ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine());
35
+
36
+ if ('default' === $filterName->getAttribute('value') && ($node instanceof NameExpression || $node instanceof GetAttrExpression)) {
37
+ $test = new DefinedTest(clone $node, 'defined', new Node(), $node->getTemplateLine());
38
+ $false = \count($arguments) ? $arguments->getNode(0) : new ConstantExpression('', $node->getTemplateLine());
39
+
40
+ $node = new ConditionalExpression($test, $default, $false, $node->getTemplateLine());
41
+ } else {
42
+ $node = $default;
43
+ }
44
+
45
+ parent::__construct($node, $filterName, $arguments, $lineno, $tag);
46
+ }
47
+
48
+ public function compile(Compiler $compiler)
49
+ {
50
+ $compiler->subcompile($this->getNode('node'));
51
+ }
52
+ }
53
+
54
+ class_alias('Twig\Node\Expression\Filter\DefaultFilter', 'Twig_Node_Expression_Filter_Default');
vendor/twig/twig/src/Node/Expression/FilterExpression.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\TwigFilter;
17
+
18
+ class FilterExpression extends CallExpression
19
+ {
20
+ public function __construct(\Twig_NodeInterface $node, ConstantExpression $filterName, \Twig_NodeInterface $arguments, $lineno, $tag = null)
21
+ {
22
+ parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag);
23
+ }
24
+
25
+ public function compile(Compiler $compiler)
26
+ {
27
+ $name = $this->getNode('filter')->getAttribute('value');
28
+ $filter = $compiler->getEnvironment()->getFilter($name);
29
+
30
+ $this->setAttribute('name', $name);
31
+ $this->setAttribute('type', 'filter');
32
+ $this->setAttribute('thing', $filter);
33
+ $this->setAttribute('needs_environment', $filter->needsEnvironment());
34
+ $this->setAttribute('needs_context', $filter->needsContext());
35
+ $this->setAttribute('arguments', $filter->getArguments());
36
+ if ($filter instanceof \Twig_FilterCallableInterface || $filter instanceof TwigFilter) {
37
+ $this->setAttribute('callable', $filter->getCallable());
38
+ }
39
+ if ($filter instanceof TwigFilter) {
40
+ $this->setAttribute('is_variadic', $filter->isVariadic());
41
+ }
42
+
43
+ $this->compileCallable($compiler);
44
+ }
45
+ }
46
+
47
+ class_alias('Twig\Node\Expression\FilterExpression', 'Twig_Node_Expression_Filter');
vendor/twig/twig/src/Node/Expression/FunctionExpression.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\TwigFunction;
16
+
17
+ class FunctionExpression extends CallExpression
18
+ {
19
+ public function __construct($name, \Twig_NodeInterface $arguments, $lineno)
20
+ {
21
+ parent::__construct(['arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno);
22
+ }
23
+
24
+ public function compile(Compiler $compiler)
25
+ {
26
+ $name = $this->getAttribute('name');
27
+ $function = $compiler->getEnvironment()->getFunction($name);
28
+
29
+ $this->setAttribute('name', $name);
30
+ $this->setAttribute('type', 'function');
31
+ $this->setAttribute('thing', $function);
32
+ $this->setAttribute('needs_environment', $function->needsEnvironment());
33
+ $this->setAttribute('needs_context', $function->needsContext());
34
+ $this->setAttribute('arguments', $function->getArguments());
35
+ if ($function instanceof \Twig_FunctionCallableInterface || $function instanceof TwigFunction) {
36
+ $callable = $function->getCallable();
37
+ if ('constant' === $name && $this->getAttribute('is_defined_test')) {
38
+ $callable = 'twig_constant_is_defined';
39
+ }
40
+
41
+ $this->setAttribute('callable', $callable);
42
+ }
43
+ if ($function instanceof TwigFunction) {
44
+ $this->setAttribute('is_variadic', $function->isVariadic());
45
+ }
46
+
47
+ $this->compileCallable($compiler);
48
+ }
49
+ }
50
+
51
+ class_alias('Twig\Node\Expression\FunctionExpression', 'Twig_Node_Expression_Function');
vendor/twig/twig/src/Node/Expression/GetAttrExpression.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\Template;
17
+
18
+ class GetAttrExpression extends AbstractExpression
19
+ {
20
+ public function __construct(AbstractExpression $node, AbstractExpression $attribute, AbstractExpression $arguments = null, $type, $lineno)
21
+ {
22
+ $nodes = ['node' => $node, 'attribute' => $attribute];
23
+ if (null !== $arguments) {
24
+ $nodes['arguments'] = $arguments;
25
+ }
26
+
27
+ parent::__construct($nodes, ['type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false], $lineno);
28
+ }
29
+
30
+ public function compile(Compiler $compiler)
31
+ {
32
+ if ($this->getAttribute('disable_c_ext')) {
33
+ @trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED);
34
+ }
35
+
36
+ if (\function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) {
37
+ $compiler->raw('twig_template_get_attributes($this, ');
38
+ } else {
39
+ $compiler->raw('$this->getAttribute(');
40
+ }
41
+
42
+ if ($this->getAttribute('ignore_strict_check')) {
43
+ $this->getNode('node')->setAttribute('ignore_strict_check', true);
44
+ }
45
+
46
+ $compiler->subcompile($this->getNode('node'));
47
+
48
+ $compiler->raw(', ')->subcompile($this->getNode('attribute'));
49
+
50
+ // only generate optional arguments when needed (to make generated code more readable)
51
+ $needFourth = $this->getAttribute('ignore_strict_check');
52
+ $needThird = $needFourth || $this->getAttribute('is_defined_test');
53
+ $needSecond = $needThird || Template::ANY_CALL !== $this->getAttribute('type');
54
+ $needFirst = $needSecond || $this->hasNode('arguments');
55
+
56
+ if ($needFirst) {
57
+ if ($this->hasNode('arguments')) {
58
+ $compiler->raw(', ')->subcompile($this->getNode('arguments'));
59
+ } else {
60
+ $compiler->raw(', []');
61
+ }
62
+ }
63
+
64
+ if ($needSecond) {
65
+ $compiler->raw(', ')->repr($this->getAttribute('type'));
66
+ }
67
+
68
+ if ($needThird) {
69
+ $compiler->raw(', ')->repr($this->getAttribute('is_defined_test'));
70
+ }
71
+
72
+ if ($needFourth) {
73
+ $compiler->raw(', ')->repr($this->getAttribute('ignore_strict_check'));
74
+ }
75
+
76
+ $compiler->raw(')');
77
+ }
78
+ }
79
+
80
+ class_alias('Twig\Node\Expression\GetAttrExpression', 'Twig_Node_Expression_GetAttr');
vendor/twig/twig/src/Node/Expression/InlinePrint.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Node;
16
+
17
+ /**
18
+ * @internal
19
+ */
20
+ final class InlinePrint extends AbstractExpression
21
+ {
22
+ public function __construct(Node $node, $lineno)
23
+ {
24
+ parent::__construct(['node' => $node], [], $lineno);
25
+ }
26
+
27
+ public function compile(Compiler $compiler)
28
+ {
29
+ $compiler
30
+ ->raw('print (')
31
+ ->subcompile($this->getNode('node'))
32
+ ->raw(')')
33
+ ;
34
+ }
35
+ }
vendor/twig/twig/src/Node/Expression/MethodCallExpression.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class MethodCallExpression extends AbstractExpression
17
+ {
18
+ public function __construct(AbstractExpression $node, $method, ArrayExpression $arguments, $lineno)
19
+ {
20
+ parent::__construct(['node' => $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false], $lineno);
21
+
22
+ if ($node instanceof NameExpression) {
23
+ $node->setAttribute('always_defined', true);
24
+ }
25
+ }
26
+
27
+ public function compile(Compiler $compiler)
28
+ {
29
+ $compiler
30
+ ->subcompile($this->getNode('node'))
31
+ ->raw('->')
32
+ ->raw($this->getAttribute('method'))
33
+ ->raw('(')
34
+ ;
35
+ $first = true;
36
+ foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
37
+ if (!$first) {
38
+ $compiler->raw(', ');
39
+ }
40
+ $first = false;
41
+
42
+ $compiler->subcompile($pair['value']);
43
+ }
44
+ $compiler->raw(')');
45
+ }
46
+ }
47
+
48
+ class_alias('Twig\Node\Expression\MethodCallExpression', 'Twig_Node_Expression_MethodCall');
vendor/twig/twig/src/Node/Expression/NameExpression.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class NameExpression extends AbstractExpression
18
+ {
19
+ protected $specialVars = [
20
+ '_self' => '$this',
21
+ '_context' => '$context',
22
+ '_charset' => '$this->env->getCharset()',
23
+ ];
24
+
25
+ public function __construct($name, $lineno)
26
+ {
27
+ parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno);
28
+ }
29
+
30
+ public function compile(Compiler $compiler)
31
+ {
32
+ $name = $this->getAttribute('name');
33
+
34
+ $compiler->addDebugInfo($this);
35
+
36
+ if ($this->getAttribute('is_defined_test')) {
37
+ if ($this->isSpecial()) {
38
+ $compiler->repr(true);
39
+ } elseif (\PHP_VERSION_ID >= 700400) {
40
+ $compiler
41
+ ->raw('array_key_exists(')
42
+ ->string($name)
43
+ ->raw(', $context)')
44
+ ;
45
+ } else {
46
+ $compiler
47
+ ->raw('(isset($context[')
48
+ ->string($name)
49
+ ->raw(']) || array_key_exists(')
50
+ ->string($name)
51
+ ->raw(', $context))')
52
+ ;
53
+ }
54
+ } elseif ($this->isSpecial()) {
55
+ $compiler->raw($this->specialVars[$name]);
56
+ } elseif ($this->getAttribute('always_defined')) {
57
+ $compiler
58
+ ->raw('$context[')
59
+ ->string($name)
60
+ ->raw(']')
61
+ ;
62
+ } else {
63
+ if (\PHP_VERSION_ID >= 70000) {
64
+ // use PHP 7 null coalescing operator
65
+ $compiler
66
+ ->raw('($context[')
67
+ ->string($name)
68
+ ->raw('] ?? ')
69
+ ;
70
+
71
+ if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
72
+ $compiler->raw('null)');
73
+ } else {
74
+ $compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
75
+ }
76
+ } elseif (\PHP_VERSION_ID >= 50400) {
77
+ // PHP 5.4 ternary operator performance was optimized
78
+ $compiler
79
+ ->raw('(isset($context[')
80
+ ->string($name)
81
+ ->raw(']) ? $context[')
82
+ ->string($name)
83
+ ->raw('] : ')
84
+ ;
85
+
86
+ if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
87
+ $compiler->raw('null)');
88
+ } else {
89
+ $compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
90
+ }
91
+ } else {
92
+ $compiler
93
+ ->raw('$this->getContext($context, ')
94
+ ->string($name)
95
+ ;
96
+
97
+ if ($this->getAttribute('ignore_strict_check')) {
98
+ $compiler->raw(', true');
99
+ }
100
+
101
+ $compiler
102
+ ->raw(')')
103
+ ;
104
+ }
105
+ }
106
+ }
107
+
108
+ public function isSpecial()
109
+ {
110
+ return isset($this->specialVars[$this->getAttribute('name')]);
111
+ }
112
+
113
+ public function isSimple()
114
+ {
115
+ return !$this->isSpecial() && !$this->getAttribute('is_defined_test');
116
+ }
117
+ }
118
+
119
+ class_alias('Twig\Node\Expression\NameExpression', 'Twig_Node_Expression_Name');
vendor/twig/twig/src/Node/Expression/NullCoalesceExpression.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\Binary\AndBinary;
16
+ use Twig\Node\Expression\Test\DefinedTest;
17
+ use Twig\Node\Expression\Test\NullTest;
18
+ use Twig\Node\Expression\Unary\NotUnary;
19
+ use Twig\Node\Node;
20
+
21
+ class NullCoalesceExpression extends ConditionalExpression
22
+ {
23
+ public function __construct(\Twig_NodeInterface $left, \Twig_NodeInterface $right, $lineno)
24
+ {
25
+ $test = new AndBinary(
26
+ new DefinedTest(clone $left, 'defined', new Node(), $left->getTemplateLine()),
27
+ new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()),
28
+ $left->getTemplateLine()
29
+ );
30
+
31
+ parent::__construct($test, $left, $right, $lineno);
32
+ }
33
+
34
+ public function compile(Compiler $compiler)
35
+ {
36
+ /*
37
+ * This optimizes only one case. PHP 7 also supports more complex expressions
38
+ * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works,
39
+ * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced
40
+ * cases might be implemented as an optimizer node visitor, but has not been done
41
+ * as benefits are probably not worth the added complexity.
42
+ */
43
+ if (\PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof NameExpression) {
44
+ $this->getNode('expr2')->setAttribute('always_defined', true);
45
+ $compiler
46
+ ->raw('((')
47
+ ->subcompile($this->getNode('expr2'))
48
+ ->raw(') ?? (')
49
+ ->subcompile($this->getNode('expr3'))
50
+ ->raw('))')
51
+ ;
52
+ } else {
53
+ parent::compile($compiler);
54
+ }
55
+ }
56
+ }
57
+
58
+ class_alias('Twig\Node\Expression\NullCoalesceExpression', 'Twig_Node_Expression_NullCoalesce');
vendor/twig/twig/src/Node/Expression/ParentExpression.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression;
14
+
15
+ use Twig\Compiler;
16
+
17
+ /**
18
+ * Represents a parent node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class ParentExpression extends AbstractExpression
23
+ {
24
+ public function __construct($name, $lineno, $tag = null)
25
+ {
26
+ parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag);
27
+ }
28
+
29
+ public function compile(Compiler $compiler)
30
+ {
31
+ if ($this->getAttribute('output')) {
32
+ $compiler
33
+ ->addDebugInfo($this)
34
+ ->write('$this->displayParentBlock(')
35
+ ->string($this->getAttribute('name'))
36
+ ->raw(", \$context, \$blocks);\n")
37
+ ;
38
+ } else {
39
+ $compiler
40
+ ->raw('$this->renderParentBlock(')
41
+ ->string($this->getAttribute('name'))
42
+ ->raw(', $context, $blocks)')
43
+ ;
44
+ }
45
+ }
46
+ }
47
+
48
+ class_alias('Twig\Node\Expression\ParentExpression', 'Twig_Node_Expression_Parent');
vendor/twig/twig/src/Node/Expression/TempNameExpression.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression;
13
+
14
+ use Twig\Compiler;
15
+
16
+ class TempNameExpression extends AbstractExpression
17
+ {
18
+ public function __construct($name, $lineno)
19
+ {
20
+ parent::__construct([], ['name' => $name], $lineno);
21
+ }
22
+
23
+ public function compile(Compiler $compiler)
24
+ {
25
+ $compiler
26
+ ->raw('$_')
27
+ ->raw($this->getAttribute('name'))
28
+ ->raw('_')
29
+ ;
30
+ }
31
+ }
32
+
33
+ class_alias('Twig\Node\Expression\TempNameExpression', 'Twig_Node_Expression_TempName');
vendor/twig/twig/src/Node/Expression/Test/ConstantTest.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Test;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\TestExpression;
16
+
17
+ /**
18
+ * Checks if a variable is the exact same value as a constant.
19
+ *
20
+ * {% if post.status is constant('Post::PUBLISHED') %}
21
+ * the status attribute is exactly the same as Post::PUBLISHED
22
+ * {% endif %}
23
+ *
24
+ * @author Fabien Potencier <fabien@symfony.com>
25
+ */
26
+ class ConstantTest extends TestExpression
27
+ {
28
+ public function compile(Compiler $compiler)
29
+ {
30
+ $compiler
31
+ ->raw('(')
32
+ ->subcompile($this->getNode('node'))
33
+ ->raw(' === constant(')
34
+ ;
35
+
36
+ if ($this->getNode('arguments')->hasNode(1)) {
37
+ $compiler
38
+ ->raw('get_class(')
39
+ ->subcompile($this->getNode('arguments')->getNode(1))
40
+ ->raw(')."::".')
41
+ ;
42
+ }
43
+
44
+ $compiler
45
+ ->subcompile($this->getNode('arguments')->getNode(0))
46
+ ->raw('))')
47
+ ;
48
+ }
49
+ }
50
+
51
+ class_alias('Twig\Node\Expression\Test\ConstantTest', 'Twig_Node_Expression_Test_Constant');
vendor/twig/twig/src/Node/Expression/Test/DefinedTest.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Test;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Error\SyntaxError;
16
+ use Twig\Node\Expression\ArrayExpression;
17
+ use Twig\Node\Expression\BlockReferenceExpression;
18
+ use Twig\Node\Expression\ConstantExpression;
19
+ use Twig\Node\Expression\FunctionExpression;
20
+ use Twig\Node\Expression\GetAttrExpression;
21
+ use Twig\Node\Expression\NameExpression;
22
+ use Twig\Node\Expression\TestExpression;
23
+
24
+ /**
25
+ * Checks if a variable is defined in the current context.
26
+ *
27
+ * {# defined works with variable names and variable attributes #}
28
+ * {% if foo is defined %}
29
+ * {# ... #}
30
+ * {% endif %}
31
+ *
32
+ * @author Fabien Potencier <fabien@symfony.com>
33
+ */
34
+ class DefinedTest extends TestExpression
35
+ {
36
+ public function __construct(\Twig_NodeInterface $node, $name, \Twig_NodeInterface $arguments = null, $lineno)
37
+ {
38
+ if ($node instanceof NameExpression) {
39
+ $node->setAttribute('is_defined_test', true);
40
+ } elseif ($node instanceof GetAttrExpression) {
41
+ $node->setAttribute('is_defined_test', true);
42
+ $this->changeIgnoreStrictCheck($node);
43
+ } elseif ($node instanceof BlockReferenceExpression) {
44
+ $node->setAttribute('is_defined_test', true);
45
+ } elseif ($node instanceof FunctionExpression && 'constant' === $node->getAttribute('name')) {
46
+ $node->setAttribute('is_defined_test', true);
47
+ } elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) {
48
+ $node = new ConstantExpression(true, $node->getTemplateLine());
49
+ } else {
50
+ throw new SyntaxError('The "defined" test only works with simple variables.', $lineno);
51
+ }
52
+
53
+ parent::__construct($node, $name, $arguments, $lineno);
54
+ }
55
+
56
+ protected function changeIgnoreStrictCheck(GetAttrExpression $node)
57
+ {
58
+ $node->setAttribute('ignore_strict_check', true);
59
+
60
+ if ($node->getNode('node') instanceof GetAttrExpression) {
61
+ $this->changeIgnoreStrictCheck($node->getNode('node'));
62
+ }
63
+ }
64
+
65
+ public function compile(Compiler $compiler)
66
+ {
67
+ $compiler->subcompile($this->getNode('node'));
68
+ }
69
+ }
70
+
71
+ class_alias('Twig\Node\Expression\Test\DefinedTest', 'Twig_Node_Expression_Test_Defined');
vendor/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Test;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\TestExpression;
16
+
17
+ /**
18
+ * Checks if a variable is divisible by a number.
19
+ *
20
+ * {% if loop.index is divisible by(3) %}
21
+ *
22
+ * @author Fabien Potencier <fabien@symfony.com>
23
+ */
24
+ class DivisiblebyTest extends TestExpression
25
+ {
26
+ public function compile(Compiler $compiler)
27
+ {
28
+ $compiler
29
+ ->raw('(0 == ')
30
+ ->subcompile($this->getNode('node'))
31
+ ->raw(' % ')
32
+ ->subcompile($this->getNode('arguments')->getNode(0))
33
+ ->raw(')')
34
+ ;
35
+ }
36
+ }
37
+
38
+ class_alias('Twig\Node\Expression\Test\DivisiblebyTest', 'Twig_Node_Expression_Test_Divisibleby');
vendor/twig/twig/src/Node/Expression/Test/EvenTest.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Test;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\TestExpression;
16
+
17
+ /**
18
+ * Checks if a number is even.
19
+ *
20
+ * {{ var is even }}
21
+ *
22
+ * @author Fabien Potencier <fabien@symfony.com>
23
+ */
24
+ class EvenTest extends TestExpression
25
+ {
26
+ public function compile(Compiler $compiler)
27
+ {
28
+ $compiler
29
+ ->raw('(')
30
+ ->subcompile($this->getNode('node'))
31
+ ->raw(' % 2 == 0')
32
+ ->raw(')')
33
+ ;
34
+ }
35
+ }
36
+
37
+ class_alias('Twig\Node\Expression\Test\EvenTest', 'Twig_Node_Expression_Test_Even');
vendor/twig/twig/src/Node/Expression/Test/NullTest.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Test;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\TestExpression;
16
+
17
+ /**
18
+ * Checks that a variable is null.
19
+ *
20
+ * {{ var is none }}
21
+ *
22
+ * @author Fabien Potencier <fabien@symfony.com>
23
+ */
24
+ class NullTest extends TestExpression
25
+ {
26
+ public function compile(Compiler $compiler)
27
+ {
28
+ $compiler
29
+ ->raw('(null === ')
30
+ ->subcompile($this->getNode('node'))
31
+ ->raw(')')
32
+ ;
33
+ }
34
+ }
35
+
36
+ class_alias('Twig\Node\Expression\Test\NullTest', 'Twig_Node_Expression_Test_Null');
vendor/twig/twig/src/Node/Expression/Test/OddTest.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Test;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\TestExpression;
16
+
17
+ /**
18
+ * Checks if a number is odd.
19
+ *
20
+ * {{ var is odd }}
21
+ *
22
+ * @author Fabien Potencier <fabien@symfony.com>
23
+ */
24
+ class OddTest extends TestExpression
25
+ {
26
+ public function compile(Compiler $compiler)
27
+ {
28
+ $compiler
29
+ ->raw('(')
30
+ ->subcompile($this->getNode('node'))
31
+ ->raw(' % 2 == 1')
32
+ ->raw(')')
33
+ ;
34
+ }
35
+ }
36
+
37
+ class_alias('Twig\Node\Expression\Test\OddTest', 'Twig_Node_Expression_Test_Odd');
vendor/twig/twig/src/Node/Expression/Test/SameasTest.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression\Test;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\TestExpression;
16
+
17
+ /**
18
+ * Checks if a variable is the same as another one (=== in PHP).
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class SameasTest extends TestExpression
23
+ {
24
+ public function compile(Compiler $compiler)
25
+ {
26
+ $compiler
27
+ ->raw('(')
28
+ ->subcompile($this->getNode('node'))
29
+ ->raw(' === ')
30
+ ->subcompile($this->getNode('arguments')->getNode(0))
31
+ ->raw(')')
32
+ ;
33
+ }
34
+ }
35
+
36
+ class_alias('Twig\Node\Expression\Test\SameasTest', 'Twig_Node_Expression_Test_Sameas');
vendor/twig/twig/src/Node/Expression/TestExpression.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node\Expression;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\TwigTest;
16
+
17
+ class TestExpression extends CallExpression
18
+ {
19
+ public function __construct(\Twig_NodeInterface $node, $name, \Twig_NodeInterface $arguments = null, $lineno)
20
+ {
21
+ $nodes = ['node' => $node];
22
+ if (null !== $arguments) {
23
+ $nodes['arguments'] = $arguments;
24
+ }
25
+
26
+ parent::__construct($nodes, ['name' => $name], $lineno);
27
+ }
28
+
29
+ public function compile(Compiler $compiler)
30
+ {
31
+ $name = $this->getAttribute('name');
32
+ $test = $compiler->getEnvironment()->getTest($name);
33
+
34
+ $this->setAttribute('name', $name);
35
+ $this->setAttribute('type', 'test');
36
+ $this->setAttribute('thing', $test);
37
+ if ($test instanceof TwigTest) {
38
+ $this->setAttribute('arguments', $test->getArguments());
39
+ }
40
+ if ($test instanceof \Twig_TestCallableInterface || $test instanceof TwigTest) {
41
+ $this->setAttribute('callable', $test->getCallable());
42
+ }
43
+ if ($test instanceof TwigTest) {
44
+ $this->setAttribute('is_variadic', $test->isVariadic());
45
+ }
46
+
47
+ $this->compileCallable($compiler);
48
+ }
49
+ }
50
+
51
+ class_alias('Twig\Node\Expression\TestExpression', 'Twig_Node_Expression_Test');
vendor/twig/twig/src/Node/Expression/Unary/AbstractUnary.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Unary;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\Node\Expression\AbstractExpression;
17
+
18
+ abstract class AbstractUnary extends AbstractExpression
19
+ {
20
+ public function __construct(\Twig_NodeInterface $node, $lineno)
21
+ {
22
+ parent::__construct(['node' => $node], [], $lineno);
23
+ }
24
+
25
+ public function compile(Compiler $compiler)
26
+ {
27
+ $compiler->raw(' ');
28
+ $this->operator($compiler);
29
+ $compiler->subcompile($this->getNode('node'));
30
+ }
31
+
32
+ abstract public function operator(Compiler $compiler);
33
+ }
34
+
35
+ class_alias('Twig\Node\Expression\Unary\AbstractUnary', 'Twig_Node_Expression_Unary');
vendor/twig/twig/src/Node/Expression/Unary/NegUnary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Unary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class NegUnary extends AbstractUnary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ $compiler->raw('-');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Unary\NegUnary', 'Twig_Node_Expression_Unary_Neg');
vendor/twig/twig/src/Node/Expression/Unary/NotUnary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Unary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class NotUnary extends AbstractUnary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ $compiler->raw('!');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Unary\NotUnary', 'Twig_Node_Expression_Unary_Not');
vendor/twig/twig/src/Node/Expression/Unary/PosUnary.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node\Expression\Unary;
14
+
15
+ use Twig\Compiler;
16
+
17
+ class PosUnary extends AbstractUnary
18
+ {
19
+ public function operator(Compiler $compiler)
20
+ {
21
+ $compiler->raw('+');
22
+ }
23
+ }
24
+
25
+ class_alias('Twig\Node\Expression\Unary\PosUnary', 'Twig_Node_Expression_Unary_Pos');
vendor/twig/twig/src/Node/FlushNode.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+
16
+ /**
17
+ * Represents a flush node.
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ class FlushNode extends Node
22
+ {
23
+ public function __construct($lineno, $tag)
24
+ {
25
+ parent::__construct([], [], $lineno, $tag);
26
+ }
27
+
28
+ public function compile(Compiler $compiler)
29
+ {
30
+ $compiler
31
+ ->addDebugInfo($this)
32
+ ->write("flush();\n")
33
+ ;
34
+ }
35
+ }
36
+
37
+ class_alias('Twig\Node\FlushNode', 'Twig_Node_Flush');
vendor/twig/twig/src/Node/ForLoopNode.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+
16
+ /**
17
+ * Internal node used by the for node.
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ class ForLoopNode extends Node
22
+ {
23
+ public function __construct($lineno, $tag = null)
24
+ {
25
+ parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag);
26
+ }
27
+
28
+ public function compile(Compiler $compiler)
29
+ {
30
+ if ($this->getAttribute('else')) {
31
+ $compiler->write("\$context['_iterated'] = true;\n");
32
+ }
33
+
34
+ if ($this->getAttribute('with_loop')) {
35
+ $compiler
36
+ ->write("++\$context['loop']['index0'];\n")
37
+ ->write("++\$context['loop']['index'];\n")
38
+ ->write("\$context['loop']['first'] = false;\n")
39
+ ;
40
+
41
+ if (!$this->getAttribute('ifexpr')) {
42
+ $compiler
43
+ ->write("if (isset(\$context['loop']['length'])) {\n")
44
+ ->indent()
45
+ ->write("--\$context['loop']['revindex0'];\n")
46
+ ->write("--\$context['loop']['revindex'];\n")
47
+ ->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n")
48
+ ->outdent()
49
+ ->write("}\n")
50
+ ;
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ class_alias('Twig\Node\ForLoopNode', 'Twig_Node_ForLoop');
vendor/twig/twig/src/Node/ForNode.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\Node\Expression\AbstractExpression;
17
+ use Twig\Node\Expression\AssignNameExpression;
18
+
19
+ /**
20
+ * Represents a for node.
21
+ *
22
+ * @author Fabien Potencier <fabien@symfony.com>
23
+ */
24
+ class ForNode extends Node
25
+ {
26
+ protected $loop;
27
+
28
+ public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, AbstractExpression $ifexpr = null, \Twig_NodeInterface $body, \Twig_NodeInterface $else = null, $lineno, $tag = null)
29
+ {
30
+ $body = new Node([$body, $this->loop = new ForLoopNode($lineno, $tag)]);
31
+
32
+ if (null !== $ifexpr) {
33
+ $body = new IfNode(new Node([$ifexpr, $body]), null, $lineno, $tag);
34
+ }
35
+
36
+ $nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body];
37
+ if (null !== $else) {
38
+ $nodes['else'] = $else;
39
+ }
40
+
41
+ parent::__construct($nodes, ['with_loop' => true, 'ifexpr' => null !== $ifexpr], $lineno, $tag);
42
+ }
43
+
44
+ public function compile(Compiler $compiler)
45
+ {
46
+ $compiler
47
+ ->addDebugInfo($this)
48
+ ->write("\$context['_parent'] = \$context;\n")
49
+ ->write("\$context['_seq'] = twig_ensure_traversable(")
50
+ ->subcompile($this->getNode('seq'))
51
+ ->raw(");\n")
52
+ ;
53
+
54
+ if ($this->hasNode('else')) {
55
+ $compiler->write("\$context['_iterated'] = false;\n");
56
+ }
57
+
58
+ if ($this->getAttribute('with_loop')) {
59
+ $compiler
60
+ ->write("\$context['loop'] = [\n")
61
+ ->write(" 'parent' => \$context['_parent'],\n")
62
+ ->write(" 'index0' => 0,\n")
63
+ ->write(" 'index' => 1,\n")
64
+ ->write(" 'first' => true,\n")
65
+ ->write("];\n")
66
+ ;
67
+
68
+ if (!$this->getAttribute('ifexpr')) {
69
+ $compiler
70
+ ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof \Countable)) {\n")
71
+ ->indent()
72
+ ->write("\$length = count(\$context['_seq']);\n")
73
+ ->write("\$context['loop']['revindex0'] = \$length - 1;\n")
74
+ ->write("\$context['loop']['revindex'] = \$length;\n")
75
+ ->write("\$context['loop']['length'] = \$length;\n")
76
+ ->write("\$context['loop']['last'] = 1 === \$length;\n")
77
+ ->outdent()
78
+ ->write("}\n")
79
+ ;
80
+ }
81
+ }
82
+
83
+ $this->loop->setAttribute('else', $this->hasNode('else'));
84
+ $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop'));
85
+ $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr'));
86
+
87
+ $compiler
88
+ ->write("foreach (\$context['_seq'] as ")
89
+ ->subcompile($this->getNode('key_target'))
90
+ ->raw(' => ')
91
+ ->subcompile($this->getNode('value_target'))
92
+ ->raw(") {\n")
93
+ ->indent()
94
+ ->subcompile($this->getNode('body'))
95
+ ->outdent()
96
+ ->write("}\n")
97
+ ;
98
+
99
+ if ($this->hasNode('else')) {
100
+ $compiler
101
+ ->write("if (!\$context['_iterated']) {\n")
102
+ ->indent()
103
+ ->subcompile($this->getNode('else'))
104
+ ->outdent()
105
+ ->write("}\n")
106
+ ;
107
+ }
108
+
109
+ $compiler->write("\$_parent = \$context['_parent'];\n");
110
+
111
+ // remove some "private" loop variables (needed for nested loops)
112
+ $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n");
113
+
114
+ // keep the values set in the inner context for variables defined in the outer context
115
+ $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n");
116
+ }
117
+ }
118
+
119
+ class_alias('Twig\Node\ForNode', 'Twig_Node_For');
vendor/twig/twig/src/Node/IfNode.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node;
14
+
15
+ use Twig\Compiler;
16
+
17
+ /**
18
+ * Represents an if node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class IfNode extends Node
23
+ {
24
+ public function __construct(\Twig_NodeInterface $tests, \Twig_NodeInterface $else = null, $lineno, $tag = null)
25
+ {
26
+ $nodes = ['tests' => $tests];
27
+ if (null !== $else) {
28
+ $nodes['else'] = $else;
29
+ }
30
+
31
+ parent::__construct($nodes, [], $lineno, $tag);
32
+ }
33
+
34
+ public function compile(Compiler $compiler)
35
+ {
36
+ $compiler->addDebugInfo($this);
37
+ for ($i = 0, $count = \count($this->getNode('tests')); $i < $count; $i += 2) {
38
+ if ($i > 0) {
39
+ $compiler
40
+ ->outdent()
41
+ ->write('} elseif (')
42
+ ;
43
+ } else {
44
+ $compiler
45
+ ->write('if (')
46
+ ;
47
+ }
48
+
49
+ $compiler
50
+ ->subcompile($this->getNode('tests')->getNode($i))
51
+ ->raw(") {\n")
52
+ ->indent()
53
+ ->subcompile($this->getNode('tests')->getNode($i + 1))
54
+ ;
55
+ }
56
+
57
+ if ($this->hasNode('else')) {
58
+ $compiler
59
+ ->outdent()
60
+ ->write("} else {\n")
61
+ ->indent()
62
+ ->subcompile($this->getNode('else'))
63
+ ;
64
+ }
65
+
66
+ $compiler
67
+ ->outdent()
68
+ ->write("}\n");
69
+ }
70
+ }
71
+
72
+ class_alias('Twig\Node\IfNode', 'Twig_Node_If');
vendor/twig/twig/src/Node/ImportNode.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\AbstractExpression;
16
+ use Twig\Node\Expression\NameExpression;
17
+
18
+ /**
19
+ * Represents an import node.
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class ImportNode extends Node
24
+ {
25
+ public function __construct(AbstractExpression $expr, AbstractExpression $var, $lineno, $tag = null)
26
+ {
27
+ parent::__construct(['expr' => $expr, 'var' => $var], [], $lineno, $tag);
28
+ }
29
+
30
+ public function compile(Compiler $compiler)
31
+ {
32
+ $compiler
33
+ ->addDebugInfo($this)
34
+ ->write('')
35
+ ->subcompile($this->getNode('var'))
36
+ ->raw(' = ')
37
+ ;
38
+
39
+ if ($this->getNode('expr') instanceof NameExpression && '_self' === $this->getNode('expr')->getAttribute('name')) {
40
+ $compiler->raw('$this');
41
+ } else {
42
+ $compiler
43
+ ->raw('$this->loadTemplate(')
44
+ ->subcompile($this->getNode('expr'))
45
+ ->raw(', ')
46
+ ->repr($this->getTemplateName())
47
+ ->raw(', ')
48
+ ->repr($this->getTemplateLine())
49
+ ->raw(')->unwrap()')
50
+ ;
51
+ }
52
+
53
+ $compiler->raw(";\n");
54
+ }
55
+ }
56
+
57
+ class_alias('Twig\Node\ImportNode', 'Twig_Node_Import');
vendor/twig/twig/src/Node/IncludeNode.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\Node\Expression\AbstractExpression;
17
+
18
+ /**
19
+ * Represents an include node.
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class IncludeNode extends Node implements NodeOutputInterface
24
+ {
25
+ public function __construct(AbstractExpression $expr, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
26
+ {
27
+ $nodes = ['expr' => $expr];
28
+ if (null !== $variables) {
29
+ $nodes['variables'] = $variables;
30
+ }
31
+
32
+ parent::__construct($nodes, ['only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing], $lineno, $tag);
33
+ }
34
+
35
+ public function compile(Compiler $compiler)
36
+ {
37
+ $compiler->addDebugInfo($this);
38
+
39
+ if ($this->getAttribute('ignore_missing')) {
40
+ $template = $compiler->getVarName();
41
+
42
+ $compiler
43
+ ->write(sprintf("$%s = null;\n", $template))
44
+ ->write("try {\n")
45
+ ->indent()
46
+ ->write(sprintf('$%s = ', $template))
47
+ ;
48
+
49
+ $this->addGetTemplate($compiler);
50
+
51
+ $compiler
52
+ ->raw(";\n")
53
+ ->outdent()
54
+ ->write("} catch (LoaderError \$e) {\n")
55
+ ->indent()
56
+ ->write("// ignore missing template\n")
57
+ ->outdent()
58
+ ->write("}\n")
59
+ ->write(sprintf("if ($%s) {\n", $template))
60
+ ->indent()
61
+ ->write(sprintf('$%s->display(', $template))
62
+ ;
63
+ $this->addTemplateArguments($compiler);
64
+ $compiler
65
+ ->raw(");\n")
66
+ ->outdent()
67
+ ->write("}\n")
68
+ ;
69
+ } else {
70
+ $this->addGetTemplate($compiler);
71
+ $compiler->raw('->display(');
72
+ $this->addTemplateArguments($compiler);
73
+ $compiler->raw(");\n");
74
+ }
75
+ }
76
+
77
+ protected function addGetTemplate(Compiler $compiler)
78
+ {
79
+ $compiler
80
+ ->write('$this->loadTemplate(')
81
+ ->subcompile($this->getNode('expr'))
82
+ ->raw(', ')
83
+ ->repr($this->getTemplateName())
84
+ ->raw(', ')
85
+ ->repr($this->getTemplateLine())
86
+ ->raw(')')
87
+ ;
88
+ }
89
+
90
+ protected function addTemplateArguments(Compiler $compiler)
91
+ {
92
+ if (!$this->hasNode('variables')) {
93
+ $compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]');
94
+ } elseif (false === $this->getAttribute('only')) {
95
+ $compiler
96
+ ->raw('twig_array_merge($context, ')
97
+ ->subcompile($this->getNode('variables'))
98
+ ->raw(')')
99
+ ;
100
+ } else {
101
+ $compiler->raw('twig_to_array(');
102
+ $compiler->subcompile($this->getNode('variables'));
103
+ $compiler->raw(')');
104
+ }
105
+ }
106
+ }
107
+
108
+ class_alias('Twig\Node\IncludeNode', 'Twig_Node_Include');
vendor/twig/twig/src/Node/MacroNode.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Error\SyntaxError;
16
+
17
+ /**
18
+ * Represents a macro node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class MacroNode extends Node
23
+ {
24
+ const VARARGS_NAME = 'varargs';
25
+
26
+ public function __construct($name, \Twig_NodeInterface $body, \Twig_NodeInterface $arguments, $lineno, $tag = null)
27
+ {
28
+ foreach ($arguments as $argumentName => $argument) {
29
+ if (self::VARARGS_NAME === $argumentName) {
30
+ throw new SyntaxError(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine(), $argument->getSourceContext());
31
+ }
32
+ }
33
+
34
+ parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag);
35
+ }
36
+
37
+ public function compile(Compiler $compiler)
38
+ {
39
+ $compiler
40
+ ->addDebugInfo($this)
41
+ ->write(sprintf('public function get%s(', $this->getAttribute('name')))
42
+ ;
43
+
44
+ $count = \count($this->getNode('arguments'));
45
+ $pos = 0;
46
+ foreach ($this->getNode('arguments') as $name => $default) {
47
+ $compiler
48
+ ->raw('$__'.$name.'__ = ')
49
+ ->subcompile($default)
50
+ ;
51
+
52
+ if (++$pos < $count) {
53
+ $compiler->raw(', ');
54
+ }
55
+ }
56
+
57
+ if (\PHP_VERSION_ID >= 50600) {
58
+ if ($count) {
59
+ $compiler->raw(', ');
60
+ }
61
+
62
+ $compiler->raw('...$__varargs__');
63
+ }
64
+
65
+ $compiler
66
+ ->raw(")\n")
67
+ ->write("{\n")
68
+ ->indent()
69
+ ;
70
+
71
+ $compiler
72
+ ->write("\$context = \$this->env->mergeGlobals([\n")
73
+ ->indent()
74
+ ;
75
+
76
+ foreach ($this->getNode('arguments') as $name => $default) {
77
+ $compiler
78
+ ->write('')
79
+ ->string($name)
80
+ ->raw(' => $__'.$name.'__')
81
+ ->raw(",\n")
82
+ ;
83
+ }
84
+
85
+ $compiler
86
+ ->write('')
87
+ ->string(self::VARARGS_NAME)
88
+ ->raw(' => ')
89
+ ;
90
+
91
+ if (\PHP_VERSION_ID >= 50600) {
92
+ $compiler->raw("\$__varargs__,\n");
93
+ } else {
94
+ $compiler
95
+ ->raw('func_num_args() > ')
96
+ ->repr($count)
97
+ ->raw(' ? array_slice(func_get_args(), ')
98
+ ->repr($count)
99
+ ->raw(") : [],\n")
100
+ ;
101
+ }
102
+
103
+ $compiler
104
+ ->outdent()
105
+ ->write("]);\n\n")
106
+ ->write("\$blocks = [];\n\n")
107
+ ;
108
+ if ($compiler->getEnvironment()->isDebug()) {
109
+ $compiler->write("ob_start();\n");
110
+ } else {
111
+ $compiler->write("ob_start(function () { return ''; });\n");
112
+ }
113
+ $compiler
114
+ ->write("try {\n")
115
+ ->indent()
116
+ ->subcompile($this->getNode('body'))
117
+ ->outdent()
118
+ ->write("} catch (\Exception \$e) {\n")
119
+ ->indent()
120
+ ->write("ob_end_clean();\n\n")
121
+ ->write("throw \$e;\n")
122
+ ->outdent()
123
+ ->write("} catch (\Throwable \$e) {\n")
124
+ ->indent()
125
+ ->write("ob_end_clean();\n\n")
126
+ ->write("throw \$e;\n")
127
+ ->outdent()
128
+ ->write("}\n\n")
129
+ ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset());\n")
130
+ ->outdent()
131
+ ->write("}\n\n")
132
+ ;
133
+ }
134
+ }
135
+
136
+ class_alias('Twig\Node\MacroNode', 'Twig_Node_Macro');
vendor/twig/twig/src/Node/ModuleNode.php ADDED
@@ -0,0 +1,492 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\Node\Expression\AbstractExpression;
17
+ use Twig\Node\Expression\ConstantExpression;
18
+ use Twig\Source;
19
+
20
+ /**
21
+ * Represents a module node.
22
+ *
23
+ * Consider this class as being final. If you need to customize the behavior of
24
+ * the generated class, consider adding nodes to the following nodes: display_start,
25
+ * display_end, constructor_start, constructor_end, and class_end.
26
+ *
27
+ * @author Fabien Potencier <fabien@symfony.com>
28
+ */
29
+ class ModuleNode extends Node
30
+ {
31
+ public function __construct(\Twig_NodeInterface $body, AbstractExpression $parent = null, \Twig_NodeInterface $blocks, \Twig_NodeInterface $macros, \Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '')
32
+ {
33
+ if (!$name instanceof Source) {
34
+ @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED);
35
+ $source = new Source($source, $name);
36
+ } else {
37
+ $source = $name;
38
+ }
39
+
40
+ $nodes = [
41
+ 'body' => $body,
42
+ 'blocks' => $blocks,
43
+ 'macros' => $macros,
44
+ 'traits' => $traits,
45
+ 'display_start' => new Node(),
46
+ 'display_end' => new Node(),
47
+ 'constructor_start' => new Node(),
48
+ 'constructor_end' => new Node(),
49
+ 'class_end' => new Node(),
50
+ ];
51
+ if (null !== $parent) {
52
+ $nodes['parent'] = $parent;
53
+ }
54
+
55
+ // embedded templates are set as attributes so that they are only visited once by the visitors
56
+ parent::__construct($nodes, [
57
+ // source to be remove in 2.0
58
+ 'source' => $source->getCode(),
59
+ // filename to be remove in 2.0 (use getTemplateName() instead)
60
+ 'filename' => $source->getName(),
61
+ 'index' => null,
62
+ 'embedded_templates' => $embeddedTemplates,
63
+ ], 1);
64
+
65
+ // populate the template name of all node children
66
+ $this->setTemplateName($source->getName());
67
+ $this->setSourceContext($source);
68
+ }
69
+
70
+ public function setIndex($index)
71
+ {
72
+ $this->setAttribute('index', $index);
73
+ }
74
+
75
+ public function compile(Compiler $compiler)
76
+ {
77
+ $this->compileTemplate($compiler);
78
+
79
+ foreach ($this->getAttribute('embedded_templates') as $template) {
80
+ $compiler->subcompile($template);
81
+ }
82
+ }
83
+
84
+ protected function compileTemplate(Compiler $compiler)
85
+ {
86
+ if (!$this->getAttribute('index')) {
87
+ $compiler->write('<?php');
88
+ }
89
+
90
+ $this->compileClassHeader($compiler);
91
+
92
+ if (
93
+ \count($this->getNode('blocks'))
94
+ || \count($this->getNode('traits'))
95
+ || !$this->hasNode('parent')
96
+ || $this->getNode('parent') instanceof ConstantExpression
97
+ || \count($this->getNode('constructor_start'))
98
+ || \count($this->getNode('constructor_end'))
99
+ ) {
100
+ $this->compileConstructor($compiler);
101
+ }
102
+
103
+ $this->compileGetParent($compiler);
104
+
105
+ $this->compileDisplay($compiler);
106
+
107
+ $compiler->subcompile($this->getNode('blocks'));
108
+
109
+ $this->compileMacros($compiler);
110
+
111
+ $this->compileGetTemplateName($compiler);
112
+
113
+ $this->compileIsTraitable($compiler);
114
+
115
+ $this->compileDebugInfo($compiler);
116
+
117
+ $this->compileGetSource($compiler);
118
+
119
+ $this->compileGetSourceContext($compiler);
120
+
121
+ $this->compileClassFooter($compiler);
122
+ }
123
+
124
+ protected function compileGetParent(Compiler $compiler)
125
+ {
126
+ if (!$this->hasNode('parent')) {
127
+ return;
128
+ }
129
+ $parent = $this->getNode('parent');
130
+
131
+ $compiler
132
+ ->write("protected function doGetParent(array \$context)\n", "{\n")
133
+ ->indent()
134
+ ->addDebugInfo($parent)
135
+ ->write('return ')
136
+ ;
137
+
138
+ if ($parent instanceof ConstantExpression) {
139
+ $compiler->subcompile($parent);
140
+ } else {
141
+ $compiler
142
+ ->raw('$this->loadTemplate(')
143
+ ->subcompile($parent)
144
+ ->raw(', ')
145
+ ->repr($this->getSourceContext()->getName())
146
+ ->raw(', ')
147
+ ->repr($parent->getTemplateLine())
148
+ ->raw(')')
149
+ ;
150
+ }
151
+
152
+ $compiler
153
+ ->raw(";\n")
154
+ ->outdent()
155
+ ->write("}\n\n")
156
+ ;
157
+ }
158
+
159
+ protected function compileClassHeader(Compiler $compiler)
160
+ {
161
+ $compiler
162
+ ->write("\n\n")
163
+ ;
164
+ if (!$this->getAttribute('index')) {
165
+ $compiler
166
+ ->write("use Twig\Environment;\n")
167
+ ->write("use Twig\Error\LoaderError;\n")
168
+ ->write("use Twig\Error\RuntimeError;\n")
169
+ ->write("use Twig\Markup;\n")
170
+ ->write("use Twig\Sandbox\SecurityError;\n")
171
+ ->write("use Twig\Sandbox\SecurityNotAllowedTagError;\n")
172
+ ->write("use Twig\Sandbox\SecurityNotAllowedFilterError;\n")
173
+ ->write("use Twig\Sandbox\SecurityNotAllowedFunctionError;\n")
174
+ ->write("use Twig\Source;\n")
175
+ ->write("use Twig\Template;\n\n")
176
+ ;
177
+ }
178
+ $compiler
179
+ // if the template name contains */, add a blank to avoid a PHP parse error
180
+ ->write('/* '.str_replace('*/', '* /', $this->getSourceContext()->getName())." */\n")
181
+ ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getSourceContext()->getName(), $this->getAttribute('index')))
182
+ ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass()))
183
+ ->write("{\n")
184
+ ->indent()
185
+ ;
186
+ }
187
+
188
+ protected function compileConstructor(Compiler $compiler)
189
+ {
190
+ $compiler
191
+ ->write("public function __construct(Environment \$env)\n", "{\n")
192
+ ->indent()
193
+ ->subcompile($this->getNode('constructor_start'))
194
+ ->write("parent::__construct(\$env);\n\n")
195
+ ;
196
+
197
+ // parent
198
+ if (!$this->hasNode('parent')) {
199
+ $compiler->write("\$this->parent = false;\n\n");
200
+ }
201
+
202
+ $countTraits = \count($this->getNode('traits'));
203
+ if ($countTraits) {
204
+ // traits
205
+ foreach ($this->getNode('traits') as $i => $trait) {
206
+ $this->compileLoadTemplate($compiler, $trait->getNode('template'), sprintf('$_trait_%s', $i));
207
+
208
+ $node = $trait->getNode('template');
209
+ $compiler
210
+ ->addDebugInfo($node)
211
+ ->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i))
212
+ ->indent()
213
+ ->write("throw new RuntimeError('Template \"'.")
214
+ ->subcompile($trait->getNode('template'))
215
+ ->raw(".'\" cannot be used as a trait.', ")
216
+ ->repr($node->getTemplateLine())
217
+ ->raw(", \$this->getSourceContext());\n")
218
+ ->outdent()
219
+ ->write("}\n")
220
+ ->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i))
221
+ ;
222
+
223
+ foreach ($trait->getNode('targets') as $key => $value) {
224
+ $compiler
225
+ ->write(sprintf('if (!isset($_trait_%s_blocks[', $i))
226
+ ->string($key)
227
+ ->raw("])) {\n")
228
+ ->indent()
229
+ ->write("throw new RuntimeError(sprintf('Block ")
230
+ ->string($key)
231
+ ->raw(' is not defined in trait ')
232
+ ->subcompile($trait->getNode('template'))
233
+ ->raw(".'), ")
234
+ ->repr($node->getTemplateLine())
235
+ ->raw(", \$this->getSourceContext());\n")
236
+ ->outdent()
237
+ ->write("}\n\n")
238
+
239
+ ->write(sprintf('$_trait_%s_blocks[', $i))
240
+ ->subcompile($value)
241
+ ->raw(sprintf('] = $_trait_%s_blocks[', $i))
242
+ ->string($key)
243
+ ->raw(sprintf(']; unset($_trait_%s_blocks[', $i))
244
+ ->string($key)
245
+ ->raw("]);\n\n")
246
+ ;
247
+ }
248
+ }
249
+
250
+ if ($countTraits > 1) {
251
+ $compiler
252
+ ->write("\$this->traits = array_merge(\n")
253
+ ->indent()
254
+ ;
255
+
256
+ for ($i = 0; $i < $countTraits; ++$i) {
257
+ $compiler
258
+ ->write(sprintf('$_trait_%s_blocks'.($i == $countTraits - 1 ? '' : ',')."\n", $i))
259
+ ;
260
+ }
261
+
262
+ $compiler
263
+ ->outdent()
264
+ ->write(");\n\n")
265
+ ;
266
+ } else {
267
+ $compiler
268
+ ->write("\$this->traits = \$_trait_0_blocks;\n\n")
269
+ ;
270
+ }
271
+
272
+ $compiler
273
+ ->write("\$this->blocks = array_merge(\n")
274
+ ->indent()
275
+ ->write("\$this->traits,\n")
276
+ ->write("[\n")
277
+ ;
278
+ } else {
279
+ $compiler
280
+ ->write("\$this->blocks = [\n")
281
+ ;
282
+ }
283
+
284
+ // blocks
285
+ $compiler
286
+ ->indent()
287
+ ;
288
+
289
+ foreach ($this->getNode('blocks') as $name => $node) {
290
+ $compiler
291
+ ->write(sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name))
292
+ ;
293
+ }
294
+
295
+ if ($countTraits) {
296
+ $compiler
297
+ ->outdent()
298
+ ->write("]\n")
299
+ ->outdent()
300
+ ->write(");\n")
301
+ ;
302
+ } else {
303
+ $compiler
304
+ ->outdent()
305
+ ->write("];\n")
306
+ ;
307
+ }
308
+
309
+ $compiler
310
+ ->subcompile($this->getNode('constructor_end'))
311
+ ->outdent()
312
+ ->write("}\n\n")
313
+ ;
314
+ }
315
+
316
+ protected function compileDisplay(Compiler $compiler)
317
+ {
318
+ $compiler
319
+ ->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n")
320
+ ->indent()
321
+ ->subcompile($this->getNode('display_start'))
322
+ ->subcompile($this->getNode('body'))
323
+ ;
324
+
325
+ if ($this->hasNode('parent')) {
326
+ $parent = $this->getNode('parent');
327
+
328
+ $compiler->addDebugInfo($parent);
329
+ if ($parent instanceof ConstantExpression) {
330
+ $compiler
331
+ ->write('$this->parent = $this->loadTemplate(')
332
+ ->subcompile($parent)
333
+ ->raw(', ')
334
+ ->repr($this->getSourceContext()->getName())
335
+ ->raw(', ')
336
+ ->repr($parent->getTemplateLine())
337
+ ->raw(");\n")
338
+ ;
339
+ $compiler->write('$this->parent');
340
+ } else {
341
+ $compiler->write('$this->getParent($context)');
342
+ }
343
+ $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n");
344
+ }
345
+
346
+ $compiler
347
+ ->subcompile($this->getNode('display_end'))
348
+ ->outdent()
349
+ ->write("}\n\n")
350
+ ;
351
+ }
352
+
353
+ protected function compileClassFooter(Compiler $compiler)
354
+ {
355
+ $compiler
356
+ ->subcompile($this->getNode('class_end'))
357
+ ->outdent()
358
+ ->write("}\n")
359
+ ;
360
+ }
361
+
362
+ protected function compileMacros(Compiler $compiler)
363
+ {
364
+ $compiler->subcompile($this->getNode('macros'));
365
+ }
366
+
367
+ protected function compileGetTemplateName(Compiler $compiler)
368
+ {
369
+ $compiler
370
+ ->write("public function getTemplateName()\n", "{\n")
371
+ ->indent()
372
+ ->write('return ')
373
+ ->repr($this->getSourceContext()->getName())
374
+ ->raw(";\n")
375
+ ->outdent()
376
+ ->write("}\n\n")
377
+ ;
378
+ }
379
+
380
+ protected function compileIsTraitable(Compiler $compiler)
381
+ {
382
+ // A template can be used as a trait if:
383
+ // * it has no parent
384
+ // * it has no macros
385
+ // * it has no body
386
+ //
387
+ // Put another way, a template can be used as a trait if it
388
+ // only contains blocks and use statements.
389
+ $traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros'));
390
+ if ($traitable) {
391
+ if ($this->getNode('body') instanceof BodyNode) {
392
+ $nodes = $this->getNode('body')->getNode(0);
393
+ } else {
394
+ $nodes = $this->getNode('body');
395
+ }
396
+
397
+ if (!\count($nodes)) {
398
+ $nodes = new Node([$nodes]);
399
+ }
400
+
401
+ foreach ($nodes as $node) {
402
+ if (!\count($node)) {
403
+ continue;
404
+ }
405
+
406
+ if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) {
407
+ continue;
408
+ }
409
+
410
+ if ($node instanceof BlockReferenceNode) {
411
+ continue;
412
+ }
413
+
414
+ $traitable = false;
415
+ break;
416
+ }
417
+ }
418
+
419
+ if ($traitable) {
420
+ return;
421
+ }
422
+
423
+ $compiler
424
+ ->write("public function isTraitable()\n", "{\n")
425
+ ->indent()
426
+ ->write(sprintf("return %s;\n", $traitable ? 'true' : 'false'))
427
+ ->outdent()
428
+ ->write("}\n\n")
429
+ ;
430
+ }
431
+
432
+ protected function compileDebugInfo(Compiler $compiler)
433
+ {
434
+ $compiler
435
+ ->write("public function getDebugInfo()\n", "{\n")
436
+ ->indent()
437
+ ->write(sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true))))
438
+ ->outdent()
439
+ ->write("}\n\n")
440
+ ;
441
+ }
442
+
443
+ protected function compileGetSource(Compiler $compiler)
444
+ {
445
+ $compiler
446
+ ->write("/** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */\n")
447
+ ->write("public function getSource()\n", "{\n")
448
+ ->indent()
449
+ ->write("@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);\n\n")
450
+ ->write('return $this->getSourceContext()->getCode();')
451
+ ->raw("\n")
452
+ ->outdent()
453
+ ->write("}\n\n")
454
+ ;
455
+ }
456
+
457
+ protected function compileGetSourceContext(Compiler $compiler)
458
+ {
459
+ $compiler
460
+ ->write("public function getSourceContext()\n", "{\n")
461
+ ->indent()
462
+ ->write('return new Source(')
463
+ ->string($compiler->getEnvironment()->isDebug() ? $this->getSourceContext()->getCode() : '')
464
+ ->raw(', ')
465
+ ->string($this->getSourceContext()->getName())
466
+ ->raw(', ')
467
+ ->string($this->getSourceContext()->getPath())
468
+ ->raw(");\n")
469
+ ->outdent()
470
+ ->write("}\n")
471
+ ;
472
+ }
473
+
474
+ protected function compileLoadTemplate(Compiler $compiler, $node, $var)
475
+ {
476
+ if ($node instanceof ConstantExpression) {
477
+ $compiler
478
+ ->write(sprintf('%s = $this->loadTemplate(', $var))
479
+ ->subcompile($node)
480
+ ->raw(', ')
481
+ ->repr($node->getTemplateName())
482
+ ->raw(', ')
483
+ ->repr($node->getTemplateLine())
484
+ ->raw(");\n")
485
+ ;
486
+ } else {
487
+ throw new \LogicException('Trait templates can only be constant nodes.');
488
+ }
489
+ }
490
+ }
491
+
492
+ class_alias('Twig\Node\ModuleNode', 'Twig_Node_Module');
vendor/twig/twig/src/Node/Node.php ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\Source;
17
+
18
+ /**
19
+ * Represents a node in the AST.
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class Node implements \Twig_NodeInterface
24
+ {
25
+ protected $nodes;
26
+ protected $attributes;
27
+ protected $lineno;
28
+ protected $tag;
29
+
30
+ private $name;
31
+ private $sourceContext;
32
+
33
+ /**
34
+ * @param array $nodes An array of named nodes
35
+ * @param array $attributes An array of attributes (should not be nodes)
36
+ * @param int $lineno The line number
37
+ * @param string $tag The tag name associated with the Node
38
+ */
39
+ public function __construct(array $nodes = [], array $attributes = [], $lineno = 0, $tag = null)
40
+ {
41
+ foreach ($nodes as $name => $node) {
42
+ if (!$node instanceof \Twig_NodeInterface) {
43
+ @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, \get_class($this)), E_USER_DEPRECATED);
44
+ }
45
+ }
46
+ $this->nodes = $nodes;
47
+ $this->attributes = $attributes;
48
+ $this->lineno = $lineno;
49
+ $this->tag = $tag;
50
+ }
51
+
52
+ public function __toString()
53
+ {
54
+ $attributes = [];
55
+ foreach ($this->attributes as $name => $value) {
56
+ $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true)));
57
+ }
58
+
59
+ $repr = [\get_class($this).'('.implode(', ', $attributes)];
60
+
61
+ if (\count($this->nodes)) {
62
+ foreach ($this->nodes as $name => $node) {
63
+ $len = \strlen($name) + 4;
64
+ $noderepr = [];
65
+ foreach (explode("\n", (string) $node) as $line) {
66
+ $noderepr[] = str_repeat(' ', $len).$line;
67
+ }
68
+
69
+ $repr[] = sprintf(' %s: %s', $name, ltrim(implode("\n", $noderepr)));
70
+ }
71
+
72
+ $repr[] = ')';
73
+ } else {
74
+ $repr[0] .= ')';
75
+ }
76
+
77
+ return implode("\n", $repr);
78
+ }
79
+
80
+ /**
81
+ * @deprecated since 1.16.1 (to be removed in 2.0)
82
+ */
83
+ public function toXml($asDom = false)
84
+ {
85
+ @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
86
+
87
+ $dom = new \DOMDocument('1.0', 'UTF-8');
88
+ $dom->formatOutput = true;
89
+ $dom->appendChild($xml = $dom->createElement('twig'));
90
+
91
+ $xml->appendChild($node = $dom->createElement('node'));
92
+ $node->setAttribute('class', \get_class($this));
93
+
94
+ foreach ($this->attributes as $name => $value) {
95
+ $node->appendChild($attribute = $dom->createElement('attribute'));
96
+ $attribute->setAttribute('name', $name);
97
+ $attribute->appendChild($dom->createTextNode($value));
98
+ }
99
+
100
+ foreach ($this->nodes as $name => $n) {
101
+ if (null === $n) {
102
+ continue;
103
+ }
104
+
105
+ $child = $n->toXml(true)->getElementsByTagName('node')->item(0);
106
+ $child = $dom->importNode($child, true);
107
+ $child->setAttribute('name', $name);
108
+
109
+ $node->appendChild($child);
110
+ }
111
+
112
+ return $asDom ? $dom : $dom->saveXML();
113
+ }
114
+
115
+ public function compile(Compiler $compiler)
116
+ {
117
+ foreach ($this->nodes as $node) {
118
+ $node->compile($compiler);
119
+ }
120
+ }
121
+
122
+ public function getTemplateLine()
123
+ {
124
+ return $this->lineno;
125
+ }
126
+
127
+ /**
128
+ * @deprecated since 1.27 (to be removed in 2.0)
129
+ */
130
+ public function getLine()
131
+ {
132
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', E_USER_DEPRECATED);
133
+
134
+ return $this->lineno;
135
+ }
136
+
137
+ public function getNodeTag()
138
+ {
139
+ return $this->tag;
140
+ }
141
+
142
+ /**
143
+ * @return bool
144
+ */
145
+ public function hasAttribute($name)
146
+ {
147
+ return \array_key_exists($name, $this->attributes);
148
+ }
149
+
150
+ /**
151
+ * @return mixed
152
+ */
153
+ public function getAttribute($name)
154
+ {
155
+ if (!\array_key_exists($name, $this->attributes)) {
156
+ throw new \LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, \get_class($this)));
157
+ }
158
+
159
+ return $this->attributes[$name];
160
+ }
161
+
162
+ /**
163
+ * @param string $name
164
+ * @param mixed $value
165
+ */
166
+ public function setAttribute($name, $value)
167
+ {
168
+ $this->attributes[$name] = $value;
169
+ }
170
+
171
+ public function removeAttribute($name)
172
+ {
173
+ unset($this->attributes[$name]);
174
+ }
175
+
176
+ /**
177
+ * @return bool
178
+ */
179
+ public function hasNode($name)
180
+ {
181
+ return \array_key_exists($name, $this->nodes);
182
+ }
183
+
184
+ /**
185
+ * @return Node
186
+ */
187
+ public function getNode($name)
188
+ {
189
+ if (!\array_key_exists($name, $this->nodes)) {
190
+ throw new \LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, \get_class($this)));
191
+ }
192
+
193
+ return $this->nodes[$name];
194
+ }
195
+
196
+ public function setNode($name, $node = null)
197
+ {
198
+ if (!$node instanceof \Twig_NodeInterface) {
199
+ @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, \get_class($this)), E_USER_DEPRECATED);
200
+ }
201
+
202
+ $this->nodes[$name] = $node;
203
+ }
204
+
205
+ public function removeNode($name)
206
+ {
207
+ unset($this->nodes[$name]);
208
+ }
209
+
210
+ public function count()
211
+ {
212
+ return \count($this->nodes);
213
+ }
214
+
215
+ public function getIterator()
216
+ {
217
+ return new \ArrayIterator($this->nodes);
218
+ }
219
+
220
+ public function setTemplateName($name)
221
+ {
222
+ $this->name = $name;
223
+ foreach ($this->nodes as $node) {
224
+ if (null !== $node) {
225
+ $node->setTemplateName($name);
226
+ }
227
+ }
228
+ }
229
+
230
+ public function getTemplateName()
231
+ {
232
+ return $this->name;
233
+ }
234
+
235
+ public function setSourceContext(Source $source)
236
+ {
237
+ $this->sourceContext = $source;
238
+ foreach ($this->nodes as $node) {
239
+ if ($node instanceof Node) {
240
+ $node->setSourceContext($source);
241
+ }
242
+ }
243
+ }
244
+
245
+ public function getSourceContext()
246
+ {
247
+ return $this->sourceContext;
248
+ }
249
+
250
+ /**
251
+ * @deprecated since 1.27 (to be removed in 2.0)
252
+ */
253
+ public function setFilename($name)
254
+ {
255
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', E_USER_DEPRECATED);
256
+
257
+ $this->setTemplateName($name);
258
+ }
259
+
260
+ /**
261
+ * @deprecated since 1.27 (to be removed in 2.0)
262
+ */
263
+ public function getFilename()
264
+ {
265
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', E_USER_DEPRECATED);
266
+
267
+ return $this->name;
268
+ }
269
+ }
270
+
271
+ class_alias('Twig\Node\Node', 'Twig_Node');
272
+
273
+ // Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
274
+ class_exists('Twig\Compiler');
vendor/twig/twig/src/Node/NodeCaptureInterface.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ /**
15
+ * Represents a node that captures any nested displayable nodes.
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ interface NodeCaptureInterface
20
+ {
21
+ }
22
+
23
+ class_alias('Twig\Node\NodeCaptureInterface', 'Twig_NodeCaptureInterface');
vendor/twig/twig/src/Node/NodeOutputInterface.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ /**
15
+ * Represents a displayable node in the AST.
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ interface NodeOutputInterface
20
+ {
21
+ }
22
+
23
+ class_alias('Twig\Node\NodeOutputInterface', 'Twig_NodeOutputInterface');
vendor/twig/twig/src/Node/PrintNode.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node;
14
+
15
+ use Twig\Compiler;
16
+ use Twig\Node\Expression\AbstractExpression;
17
+
18
+ /**
19
+ * Represents a node that outputs an expression.
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class PrintNode extends Node implements NodeOutputInterface
24
+ {
25
+ public function __construct(AbstractExpression $expr, $lineno, $tag = null)
26
+ {
27
+ parent::__construct(['expr' => $expr], [], $lineno, $tag);
28
+ }
29
+
30
+ public function compile(Compiler $compiler)
31
+ {
32
+ $compiler
33
+ ->addDebugInfo($this)
34
+ ->write('echo ')
35
+ ->subcompile($this->getNode('expr'))
36
+ ->raw(";\n")
37
+ ;
38
+ }
39
+ }
40
+
41
+ class_alias('Twig\Node\PrintNode', 'Twig_Node_Print');
vendor/twig/twig/src/Node/SandboxNode.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+
16
+ /**
17
+ * Represents a sandbox node.
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ class SandboxNode extends Node
22
+ {
23
+ public function __construct(\Twig_NodeInterface $body, $lineno, $tag = null)
24
+ {
25
+ parent::__construct(['body' => $body], [], $lineno, $tag);
26
+ }
27
+
28
+ public function compile(Compiler $compiler)
29
+ {
30
+ $compiler
31
+ ->addDebugInfo($this)
32
+ ->write("if (!\$alreadySandboxed = \$this->sandbox->isSandboxed()) {\n")
33
+ ->indent()
34
+ ->write("\$this->sandbox->enableSandbox();\n")
35
+ ->outdent()
36
+ ->write("}\n")
37
+ ->subcompile($this->getNode('body'))
38
+ ->write("if (!\$alreadySandboxed) {\n")
39
+ ->indent()
40
+ ->write("\$this->sandbox->disableSandbox();\n")
41
+ ->outdent()
42
+ ->write("}\n")
43
+ ;
44
+ }
45
+ }
46
+
47
+ class_alias('Twig\Node\SandboxNode', 'Twig_Node_Sandbox');
vendor/twig/twig/src/Node/SandboxedPrintNode.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\ConstantExpression;
16
+ use Twig\Node\Expression\FilterExpression;
17
+
18
+ /**
19
+ * Adds a check for the __toString() method when the variable is an object and the sandbox is activated.
20
+ *
21
+ * When there is a simple Print statement, like {{ article }},
22
+ * and if the sandbox is enabled, we need to check that the __toString()
23
+ * method is allowed if 'article' is an object.
24
+ *
25
+ * Not used anymore, to be deprecated in 2.x and removed in 3.0
26
+ *
27
+ * @author Fabien Potencier <fabien@symfony.com>
28
+ */
29
+ class SandboxedPrintNode extends PrintNode
30
+ {
31
+ public function compile(Compiler $compiler)
32
+ {
33
+ $compiler
34
+ ->addDebugInfo($this)
35
+ ->write('echo ')
36
+ ;
37
+ $expr = $this->getNode('expr');
38
+ if ($expr instanceof ConstantExpression) {
39
+ $compiler
40
+ ->subcompile($expr)
41
+ ->raw(";\n")
42
+ ;
43
+ } else {
44
+ $compiler
45
+ ->write('$this->env->getExtension(\'\Twig\Extension\SandboxExtension\')->ensureToStringAllowed(')
46
+ ->subcompile($expr)
47
+ ->raw(");\n")
48
+ ;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Removes node filters.
54
+ *
55
+ * This is mostly needed when another visitor adds filters (like the escaper one).
56
+ *
57
+ * @return Node
58
+ */
59
+ protected function removeNodeFilter(Node $node)
60
+ {
61
+ if ($node instanceof FilterExpression) {
62
+ return $this->removeNodeFilter($node->getNode('node'));
63
+ }
64
+
65
+ return $node;
66
+ }
67
+ }
68
+
69
+ class_alias('Twig\Node\SandboxedPrintNode', 'Twig_Node_SandboxedPrint');
vendor/twig/twig/src/Node/SetNode.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Expression\ConstantExpression;
16
+
17
+ /**
18
+ * Represents a set node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class SetNode extends Node implements NodeCaptureInterface
23
+ {
24
+ public function __construct($capture, \Twig_NodeInterface $names, \Twig_NodeInterface $values, $lineno, $tag = null)
25
+ {
26
+ parent::__construct(['names' => $names, 'values' => $values], ['capture' => $capture, 'safe' => false], $lineno, $tag);
27
+
28
+ /*
29
+ * Optimizes the node when capture is used for a large block of text.
30
+ *
31
+ * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig\Markup("foo");
32
+ */
33
+ if ($this->getAttribute('capture')) {
34
+ $this->setAttribute('safe', true);
35
+
36
+ $values = $this->getNode('values');
37
+ if ($values instanceof TextNode) {
38
+ $this->setNode('values', new ConstantExpression($values->getAttribute('data'), $values->getTemplateLine()));
39
+ $this->setAttribute('capture', false);
40
+ }
41
+ }
42
+ }
43
+
44
+ public function compile(Compiler $compiler)
45
+ {
46
+ $compiler->addDebugInfo($this);
47
+
48
+ if (\count($this->getNode('names')) > 1) {
49
+ $compiler->write('list(');
50
+ foreach ($this->getNode('names') as $idx => $node) {
51
+ if ($idx) {
52
+ $compiler->raw(', ');
53
+ }
54
+
55
+ $compiler->subcompile($node);
56
+ }
57
+ $compiler->raw(')');
58
+ } else {
59
+ if ($this->getAttribute('capture')) {
60
+ if ($compiler->getEnvironment()->isDebug()) {
61
+ $compiler->write("ob_start();\n");
62
+ } else {
63
+ $compiler->write("ob_start(function () { return ''; });\n");
64
+ }
65
+ $compiler
66
+ ->subcompile($this->getNode('values'))
67
+ ;
68
+ }
69
+
70
+ $compiler->subcompile($this->getNode('names'), false);
71
+
72
+ if ($this->getAttribute('capture')) {
73
+ $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset())");
74
+ }
75
+ }
76
+
77
+ if (!$this->getAttribute('capture')) {
78
+ $compiler->raw(' = ');
79
+
80
+ if (\count($this->getNode('names')) > 1) {
81
+ $compiler->write('[');
82
+ foreach ($this->getNode('values') as $idx => $value) {
83
+ if ($idx) {
84
+ $compiler->raw(', ');
85
+ }
86
+
87
+ $compiler->subcompile($value);
88
+ }
89
+ $compiler->raw(']');
90
+ } else {
91
+ if ($this->getAttribute('safe')) {
92
+ $compiler
93
+ ->raw("('' === \$tmp = ")
94
+ ->subcompile($this->getNode('values'))
95
+ ->raw(") ? '' : new Markup(\$tmp, \$this->env->getCharset())")
96
+ ;
97
+ } else {
98
+ $compiler->subcompile($this->getNode('values'));
99
+ }
100
+ }
101
+ }
102
+
103
+ $compiler->raw(";\n");
104
+ }
105
+ }
106
+
107
+ class_alias('Twig\Node\SetNode', 'Twig_Node_Set');
vendor/twig/twig/src/Node/SetTempNode.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+
16
+ /**
17
+ * @internal
18
+ */
19
+ class SetTempNode extends Node
20
+ {
21
+ public function __construct($name, $lineno)
22
+ {
23
+ parent::__construct([], ['name' => $name], $lineno);
24
+ }
25
+
26
+ public function compile(Compiler $compiler)
27
+ {
28
+ $name = $this->getAttribute('name');
29
+ $compiler
30
+ ->addDebugInfo($this)
31
+ ->write('if (isset($context[')
32
+ ->string($name)
33
+ ->raw('])) { $_')
34
+ ->raw($name)
35
+ ->raw('_ = $context[')
36
+ ->repr($name)
37
+ ->raw(']; } else { $_')
38
+ ->raw($name)
39
+ ->raw("_ = null; }\n")
40
+ ;
41
+ }
42
+ }
43
+
44
+ class_alias('Twig\Node\SetTempNode', 'Twig_Node_SetTemp');
vendor/twig/twig/src/Node/SpacelessNode.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+
16
+ /**
17
+ * Represents a spaceless node.
18
+ *
19
+ * It removes spaces between HTML tags.
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class SpacelessNode extends Node
24
+ {
25
+ public function __construct(\Twig_NodeInterface $body, $lineno, $tag = 'spaceless')
26
+ {
27
+ parent::__construct(['body' => $body], [], $lineno, $tag);
28
+ }
29
+
30
+ public function compile(Compiler $compiler)
31
+ {
32
+ $compiler
33
+ ->addDebugInfo($this)
34
+ ;
35
+ if ($compiler->getEnvironment()->isDebug()) {
36
+ $compiler->write("ob_start();\n");
37
+ } else {
38
+ $compiler->write("ob_start(function () { return ''; });\n");
39
+ }
40
+ $compiler
41
+ ->subcompile($this->getNode('body'))
42
+ ->write("echo trim(preg_replace('/>\s+</', '><', ob_get_clean()));\n")
43
+ ;
44
+ }
45
+ }
46
+
47
+ class_alias('Twig\Node\SpacelessNode', 'Twig_Node_Spaceless');
vendor/twig/twig/src/Node/TextNode.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\Node;
14
+
15
+ use Twig\Compiler;
16
+
17
+ /**
18
+ * Represents a text node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class TextNode extends Node implements NodeOutputInterface
23
+ {
24
+ public function __construct($data, $lineno)
25
+ {
26
+ parent::__construct([], ['data' => $data], $lineno);
27
+ }
28
+
29
+ public function compile(Compiler $compiler)
30
+ {
31
+ $compiler
32
+ ->addDebugInfo($this)
33
+ ->write('echo ')
34
+ ->string($this->getAttribute('data'))
35
+ ->raw(";\n")
36
+ ;
37
+ }
38
+ }
39
+
40
+ class_alias('Twig\Node\TextNode', 'Twig_Node_Text');
vendor/twig/twig/src/Node/WithNode.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Node;
13
+
14
+ use Twig\Compiler;
15
+
16
+ /**
17
+ * Represents a nested "with" scope.
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ class WithNode extends Node
22
+ {
23
+ public function __construct(Node $body, Node $variables = null, $only = false, $lineno, $tag = null)
24
+ {
25
+ $nodes = ['body' => $body];
26
+ if (null !== $variables) {
27
+ $nodes['variables'] = $variables;
28
+ }
29
+
30
+ parent::__construct($nodes, ['only' => (bool) $only], $lineno, $tag);
31
+ }
32
+
33
+ public function compile(Compiler $compiler)
34
+ {
35
+ $compiler->addDebugInfo($this);
36
+
37
+ if ($this->hasNode('variables')) {
38
+ $node = $this->getNode('variables');
39
+ $varsName = $compiler->getVarName();
40
+ $compiler
41
+ ->write(sprintf('$%s = ', $varsName))
42
+ ->subcompile($node)
43
+ ->raw(";\n")
44
+ ->write(sprintf("if (!twig_test_iterable(\$%s)) {\n", $varsName))
45
+ ->indent()
46
+ ->write("throw new RuntimeError('Variables passed to the \"with\" tag must be a hash.', ")
47
+ ->repr($node->getTemplateLine())
48
+ ->raw(", \$this->getSourceContext());\n")
49
+ ->outdent()
50
+ ->write("}\n")
51
+ ->write(sprintf("\$%s = twig_to_array(\$%s);\n", $varsName, $varsName))
52
+ ;
53
+
54
+ if ($this->getAttribute('only')) {
55
+ $compiler->write("\$context = ['_parent' => \$context];\n");
56
+ } else {
57
+ $compiler->write("\$context['_parent'] = \$context;\n");
58
+ }
59
+
60
+ $compiler->write(sprintf("\$context = \$this->env->mergeGlobals(array_merge(\$context, \$%s));\n", $varsName));
61
+ } else {
62
+ $compiler->write("\$context['_parent'] = \$context;\n");
63
+ }
64
+
65
+ $compiler
66
+ ->subcompile($this->getNode('body'))
67
+ ->write("\$context = \$context['_parent'];\n")
68
+ ;
69
+ }
70
+ }
71
+
72
+ class_alias('Twig\Node\WithNode', 'Twig_Node_With');
vendor/twig/twig/src/NodeTraverser.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig;
13
+
14
+ use Twig\NodeVisitor\NodeVisitorInterface;
15
+
16
+ /**
17
+ * A node traverser.
18
+ *
19
+ * It visits all nodes and their children and calls the given visitor for each.
20
+ *
21
+ * @final
22
+ *
23
+ * @author Fabien Potencier <fabien@symfony.com>
24
+ */
25
+ class NodeTraverser
26
+ {
27
+ protected $env;
28
+ protected $visitors = [];
29
+
30
+ /**
31
+ * @param NodeVisitorInterface[] $visitors
32
+ */
33
+ public function __construct(Environment $env, array $visitors = [])
34
+ {
35
+ $this->env = $env;
36
+ foreach ($visitors as $visitor) {
37
+ $this->addVisitor($visitor);
38
+ }
39
+ }
40
+
41
+ public function addVisitor(NodeVisitorInterface $visitor)
42
+ {
43
+ $this->visitors[$visitor->getPriority()][] = $visitor;
44
+ }
45
+
46
+ /**
47
+ * Traverses a node and calls the registered visitors.
48
+ *
49
+ * @return \Twig_NodeInterface
50
+ */
51
+ public function traverse(\Twig_NodeInterface $node)
52
+ {
53
+ ksort($this->visitors);
54
+ foreach ($this->visitors as $visitors) {
55
+ foreach ($visitors as $visitor) {
56
+ $node = $this->traverseForVisitor($visitor, $node);
57
+ }
58
+ }
59
+
60
+ return $node;
61
+ }
62
+
63
+ protected function traverseForVisitor(NodeVisitorInterface $visitor, \Twig_NodeInterface $node = null)
64
+ {
65
+ if (null === $node) {
66
+ return;
67
+ }
68
+
69
+ $node = $visitor->enterNode($node, $this->env);
70
+
71
+ foreach ($node as $k => $n) {
72
+ if (null === $n) {
73
+ continue;
74
+ }
75
+
76
+ if (false !== ($m = $this->traverseForVisitor($visitor, $n)) && null !== $m) {
77
+ if ($m !== $n) {
78
+ $node->setNode($k, $m);
79
+ }
80
+ } else {
81
+ $node->removeNode($k);
82
+ }
83
+ }
84
+
85
+ return $visitor->leaveNode($node, $this->env);
86
+ }
87
+ }
88
+
89
+ class_alias('Twig\NodeTraverser', 'Twig_NodeTraverser');
vendor/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\NodeVisitor;
13
+
14
+ use Twig\Environment;
15
+ use Twig\Node\Node;
16
+
17
+ /**
18
+ * Used to make node visitors compatible with Twig 1.x and 2.x.
19
+ *
20
+ * To be removed in Twig 3.1.
21
+ *
22
+ * @author Fabien Potencier <fabien@symfony.com>
23
+ */
24
+ abstract class AbstractNodeVisitor implements NodeVisitorInterface
25
+ {
26
+ final public function enterNode(\Twig_NodeInterface $node, Environment $env)
27
+ {
28
+ if (!$node instanceof Node) {
29
+ throw new \LogicException(sprintf('%s only supports \Twig\Node\Node instances.', __CLASS__));
30
+ }
31
+
32
+ return $this->doEnterNode($node, $env);
33
+ }
34
+
35
+ final public function leaveNode(\Twig_NodeInterface $node, Environment $env)
36
+ {
37
+ if (!$node instanceof Node) {
38
+ throw new \LogicException(sprintf('%s only supports \Twig\Node\Node instances.', __CLASS__));
39
+ }
40
+
41
+ return $this->doLeaveNode($node, $env);
42
+ }
43
+
44
+ /**
45
+ * Called before child nodes are visited.
46
+ *
47
+ * @return Node The modified node
48
+ */
49
+ abstract protected function doEnterNode(Node $node, Environment $env);
50
+
51
+ /**
52
+ * Called after child nodes are visited.
53
+ *
54
+ * @return Node|false|null The modified node or null if the node must be removed
55
+ */
56
+ abstract protected function doLeaveNode(Node $node, Environment $env);
57
+ }
58
+
59
+ class_alias('Twig\NodeVisitor\AbstractNodeVisitor', 'Twig_BaseNodeVisitor');
vendor/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\NodeVisitor;
13
+
14
+ use Twig\Environment;
15
+ use Twig\Node\AutoEscapeNode;
16
+ use Twig\Node\BlockNode;
17
+ use Twig\Node\BlockReferenceNode;
18
+ use Twig\Node\DoNode;
19
+ use Twig\Node\Expression\ConditionalExpression;
20
+ use Twig\Node\Expression\ConstantExpression;
21
+ use Twig\Node\Expression\FilterExpression;
22
+ use Twig\Node\Expression\InlinePrint;
23
+ use Twig\Node\ImportNode;
24
+ use Twig\Node\ModuleNode;
25
+ use Twig\Node\Node;
26
+ use Twig\Node\PrintNode;
27
+ use Twig\NodeTraverser;
28
+
29
+ /**
30
+ * @final
31
+ *
32
+ * @author Fabien Potencier <fabien@symfony.com>
33
+ */
34
+ class EscaperNodeVisitor extends AbstractNodeVisitor
35
+ {
36
+ protected $statusStack = [];
37
+ protected $blocks = [];
38
+ protected $safeAnalysis;
39
+ protected $traverser;
40
+ protected $defaultStrategy = false;
41
+ protected $safeVars = [];
42
+
43
+ public function __construct()
44
+ {
45
+ $this->safeAnalysis = new SafeAnalysisNodeVisitor();
46
+ }
47
+
48
+ protected function doEnterNode(Node $node, Environment $env)
49
+ {
50
+ if ($node instanceof ModuleNode) {
51
+ if ($env->hasExtension('\Twig\Extension\EscaperExtension') && $defaultStrategy = $env->getExtension('\Twig\Extension\EscaperExtension')->getDefaultStrategy($node->getTemplateName())) {
52
+ $this->defaultStrategy = $defaultStrategy;
53
+ }
54
+ $this->safeVars = [];
55
+ $this->blocks = [];
56
+ } elseif ($node instanceof AutoEscapeNode) {
57
+ $this->statusStack[] = $node->getAttribute('value');
58
+ } elseif ($node instanceof BlockNode) {
59
+ $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
60
+ } elseif ($node instanceof ImportNode) {
61
+ $this->safeVars[] = $node->getNode('var')->getAttribute('name');
62
+ }
63
+
64
+ return $node;
65
+ }
66
+
67
+ protected function doLeaveNode(Node $node, Environment $env)
68
+ {
69
+ if ($node instanceof ModuleNode) {
70
+ $this->defaultStrategy = false;
71
+ $this->safeVars = [];
72
+ $this->blocks = [];
73
+ } elseif ($node instanceof FilterExpression) {
74
+ return $this->preEscapeFilterNode($node, $env);
75
+ } elseif ($node instanceof PrintNode && false !== $type = $this->needEscaping($env)) {
76
+ $expression = $node->getNode('expr');
77
+ if ($expression instanceof ConditionalExpression && $this->shouldUnwrapConditional($expression, $env, $type)) {
78
+ return new DoNode($this->unwrapConditional($expression, $env, $type), $expression->getTemplateLine());
79
+ }
80
+
81
+ return $this->escapePrintNode($node, $env, $type);
82
+ }
83
+
84
+ if ($node instanceof AutoEscapeNode || $node instanceof BlockNode) {
85
+ array_pop($this->statusStack);
86
+ } elseif ($node instanceof BlockReferenceNode) {
87
+ $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env);
88
+ }
89
+
90
+ return $node;
91
+ }
92
+
93
+ private function shouldUnwrapConditional(ConditionalExpression $expression, Environment $env, $type)
94
+ {
95
+ $expr2Safe = $this->isSafeFor($type, $expression->getNode('expr2'), $env);
96
+ $expr3Safe = $this->isSafeFor($type, $expression->getNode('expr3'), $env);
97
+
98
+ return $expr2Safe !== $expr3Safe;
99
+ }
100
+
101
+ private function unwrapConditional(ConditionalExpression $expression, Environment $env, $type)
102
+ {
103
+ // convert "echo a ? b : c" to "a ? echo b : echo c" recursively
104
+ $expr2 = $expression->getNode('expr2');
105
+ if ($expr2 instanceof ConditionalExpression && $this->shouldUnwrapConditional($expr2, $env, $type)) {
106
+ $expr2 = $this->unwrapConditional($expr2, $env, $type);
107
+ } else {
108
+ $expr2 = $this->escapeInlinePrintNode(new InlinePrint($expr2, $expr2->getTemplateLine()), $env, $type);
109
+ }
110
+ $expr3 = $expression->getNode('expr3');
111
+ if ($expr3 instanceof ConditionalExpression && $this->shouldUnwrapConditional($expr3, $env, $type)) {
112
+ $expr3 = $this->unwrapConditional($expr3, $env, $type);
113
+ } else {
114
+ $expr3 = $this->escapeInlinePrintNode(new InlinePrint($expr3, $expr3->getTemplateLine()), $env, $type);
115
+ }
116
+
117
+ return new ConditionalExpression($expression->getNode('expr1'), $expr2, $expr3, $expression->getTemplateLine());
118
+ }
119
+
120
+ private function escapeInlinePrintNode(InlinePrint $node, Environment $env, $type)
121
+ {
122
+ $expression = $node->getNode('node');
123
+
124
+ if ($this->isSafeFor($type, $expression, $env)) {
125
+ return $node;
126
+ }
127
+
128
+ return new InlinePrint($this->getEscaperFilter($type, $expression), $node->getTemplateLine());
129
+ }
130
+
131
+ protected function escapePrintNode(PrintNode $node, Environment $env, $type)
132
+ {
133
+ if (false === $type) {
134
+ return $node;
135
+ }
136
+
137
+ $expression = $node->getNode('expr');
138
+
139
+ if ($this->isSafeFor($type, $expression, $env)) {
140
+ return $node;
141
+ }
142
+
143
+ $class = \get_class($node);
144
+
145
+ return new $class($this->getEscaperFilter($type, $expression), $node->getTemplateLine());
146
+ }
147
+
148
+ protected function preEscapeFilterNode(FilterExpression $filter, Environment $env)
149
+ {
150
+ $name = $filter->getNode('filter')->getAttribute('value');
151
+
152
+ $type = $env->getFilter($name)->getPreEscape();
153
+ if (null === $type) {
154
+ return $filter;
155
+ }
156
+
157
+ $node = $filter->getNode('node');
158
+ if ($this->isSafeFor($type, $node, $env)) {
159
+ return $filter;
160
+ }
161
+
162
+ $filter->setNode('node', $this->getEscaperFilter($type, $node));
163
+
164
+ return $filter;
165
+ }
166
+
167
+ protected function isSafeFor($type, \Twig_NodeInterface $expression, $env)
168
+ {
169
+ $safe = $this->safeAnalysis->getSafe($expression);
170
+
171
+ if (null === $safe) {
172
+ if (null === $this->traverser) {
173
+ $this->traverser = new NodeTraverser($env, [$this->safeAnalysis]);
174
+ }
175
+
176
+ $this->safeAnalysis->setSafeVars($this->safeVars);
177
+
178
+ $this->traverser->traverse($expression);
179
+ $safe = $this->safeAnalysis->getSafe($expression);
180
+ }
181
+
182
+ return \in_array($type, $safe) || \in_array('all', $safe);
183
+ }
184
+
185
+ protected function needEscaping(Environment $env)
186
+ {
187
+ if (\count($this->statusStack)) {
188
+ return $this->statusStack[\count($this->statusStack) - 1];
189
+ }
190
+
191
+ return $this->defaultStrategy ? $this->defaultStrategy : false;
192
+ }
193
+
194
+ protected function getEscaperFilter($type, \Twig_NodeInterface $node)
195
+ {
196
+ $line = $node->getTemplateLine();
197
+ $name = new ConstantExpression('escape', $line);
198
+ $args = new Node([new ConstantExpression((string) $type, $line), new ConstantExpression(null, $line), new ConstantExpression(true, $line)]);
199
+
200
+ return new FilterExpression($node, $name, $args, $line);
201
+ }
202
+
203
+ public function getPriority()
204
+ {
205
+ return 0;
206
+ }
207
+ }
208
+
209
+ class_alias('Twig\NodeVisitor\EscaperNodeVisitor', 'Twig_NodeVisitor_Escaper');
vendor/twig/twig/src/NodeVisitor/NodeVisitorInterface.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\NodeVisitor;
13
+
14
+ use Twig\Environment;
15
+
16
+ /**
17
+ * Interface for node visitor classes.
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ interface NodeVisitorInterface
22
+ {
23
+ /**
24
+ * Called before child nodes are visited.
25
+ *
26
+ * @return \Twig_NodeInterface The modified node
27
+ */
28
+ public function enterNode(\Twig_NodeInterface $node, Environment $env);
29
+
30
+ /**
31
+ * Called after child nodes are visited.
32
+ *
33
+ * @return \Twig_NodeInterface|false|null The modified node or null if the node must be removed
34
+ */
35
+ public function leaveNode(\Twig_NodeInterface $node, Environment $env);
36
+
37
+ /**
38
+ * Returns the priority for this visitor.
39
+ *
40
+ * Priority should be between -10 and 10 (0 is the default).
41
+ *
42
+ * @return int The priority level
43
+ */
44
+ public function getPriority();
45
+ }
46
+
47
+ class_alias('Twig\NodeVisitor\NodeVisitorInterface', 'Twig_NodeVisitorInterface');
48
+
49
+ // Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
50
+ class_exists('Twig\Environment');
vendor/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php ADDED
@@ -0,0 +1,273 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\NodeVisitor;
13
+
14
+ use Twig\Environment;
15
+ use Twig\Node\BlockReferenceNode;
16
+ use Twig\Node\BodyNode;
17
+ use Twig\Node\Expression\AbstractExpression;
18
+ use Twig\Node\Expression\BlockReferenceExpression;
19
+ use Twig\Node\Expression\ConstantExpression;
20
+ use Twig\Node\Expression\FilterExpression;
21
+ use Twig\Node\Expression\FunctionExpression;
22
+ use Twig\Node\Expression\GetAttrExpression;
23
+ use Twig\Node\Expression\NameExpression;
24
+ use Twig\Node\Expression\ParentExpression;
25
+ use Twig\Node\Expression\TempNameExpression;
26
+ use Twig\Node\ForNode;
27
+ use Twig\Node\IncludeNode;
28
+ use Twig\Node\Node;
29
+ use Twig\Node\PrintNode;
30
+ use Twig\Node\SetTempNode;
31
+
32
+ /**
33
+ * Tries to optimize the AST.
34
+ *
35
+ * This visitor is always the last registered one.
36
+ *
37
+ * You can configure which optimizations you want to activate via the
38
+ * optimizer mode.
39
+ *
40
+ * @final
41
+ *
42
+ * @author Fabien Potencier <fabien@symfony.com>
43
+ */
44
+ class OptimizerNodeVisitor extends AbstractNodeVisitor
45
+ {
46
+ const OPTIMIZE_ALL = -1;
47
+ const OPTIMIZE_NONE = 0;
48
+ const OPTIMIZE_FOR = 2;
49
+ const OPTIMIZE_RAW_FILTER = 4;
50
+ const OPTIMIZE_VAR_ACCESS = 8;
51
+
52
+ protected $loops = [];
53
+ protected $loopsTargets = [];
54
+ protected $optimizers;
55
+ protected $prependedNodes = [];
56
+ protected $inABody = false;
57
+
58
+ /**
59
+ * @param int $optimizers The optimizer mode
60
+ */
61
+ public function __construct($optimizers = -1)
62
+ {
63
+ if (!\is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) {
64
+ throw new \InvalidArgumentException(sprintf('Optimizer mode "%s" is not valid.', $optimizers));
65
+ }
66
+
67
+ $this->optimizers = $optimizers;
68
+ }
69
+
70
+ protected function doEnterNode(Node $node, Environment $env)
71
+ {
72
+ if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
73
+ $this->enterOptimizeFor($node, $env);
74
+ }
75
+
76
+ if (\PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('\Twig\Extension\SandboxExtension')) {
77
+ if ($this->inABody) {
78
+ if (!$node instanceof AbstractExpression) {
79
+ if ('Twig_Node' !== \get_class($node)) {
80
+ array_unshift($this->prependedNodes, []);
81
+ }
82
+ } else {
83
+ $node = $this->optimizeVariables($node, $env);
84
+ }
85
+ } elseif ($node instanceof BodyNode) {
86
+ $this->inABody = true;
87
+ }
88
+ }
89
+
90
+ return $node;
91
+ }
92
+
93
+ protected function doLeaveNode(Node $node, Environment $env)
94
+ {
95
+ $expression = $node instanceof AbstractExpression;
96
+
97
+ if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
98
+ $this->leaveOptimizeFor($node, $env);
99
+ }
100
+
101
+ if (self::OPTIMIZE_RAW_FILTER === (self::OPTIMIZE_RAW_FILTER & $this->optimizers)) {
102
+ $node = $this->optimizeRawFilter($node, $env);
103
+ }
104
+
105
+ $node = $this->optimizePrintNode($node, $env);
106
+
107
+ if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('\Twig\Extension\SandboxExtension')) {
108
+ if ($node instanceof BodyNode) {
109
+ $this->inABody = false;
110
+ } elseif ($this->inABody) {
111
+ if (!$expression && 'Twig_Node' !== \get_class($node) && $prependedNodes = array_shift($this->prependedNodes)) {
112
+ $nodes = [];
113
+ foreach (array_unique($prependedNodes) as $name) {
114
+ $nodes[] = new SetTempNode($name, $node->getTemplateLine());
115
+ }
116
+
117
+ $nodes[] = $node;
118
+ $node = new Node($nodes);
119
+ }
120
+ }
121
+ }
122
+
123
+ return $node;
124
+ }
125
+
126
+ protected function optimizeVariables(\Twig_NodeInterface $node, Environment $env)
127
+ {
128
+ if ('Twig_Node_Expression_Name' === \get_class($node) && $node->isSimple()) {
129
+ $this->prependedNodes[0][] = $node->getAttribute('name');
130
+
131
+ return new TempNameExpression($node->getAttribute('name'), $node->getTemplateLine());
132
+ }
133
+
134
+ return $node;
135
+ }
136
+
137
+ /**
138
+ * Optimizes print nodes.
139
+ *
140
+ * It replaces:
141
+ *
142
+ * * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()"
143
+ *
144
+ * @return \Twig_NodeInterface
145
+ */
146
+ protected function optimizePrintNode(\Twig_NodeInterface $node, Environment $env)
147
+ {
148
+ if (!$node instanceof PrintNode) {
149
+ return $node;
150
+ }
151
+
152
+ $exprNode = $node->getNode('expr');
153
+ if (
154
+ $exprNode instanceof BlockReferenceExpression ||
155
+ $exprNode instanceof ParentExpression
156
+ ) {
157
+ $exprNode->setAttribute('output', true);
158
+
159
+ return $exprNode;
160
+ }
161
+
162
+ return $node;
163
+ }
164
+
165
+ /**
166
+ * Removes "raw" filters.
167
+ *
168
+ * @return \Twig_NodeInterface
169
+ */
170
+ protected function optimizeRawFilter(\Twig_NodeInterface $node, Environment $env)
171
+ {
172
+ if ($node instanceof FilterExpression && 'raw' == $node->getNode('filter')->getAttribute('value')) {
173
+ return $node->getNode('node');
174
+ }
175
+
176
+ return $node;
177
+ }
178
+
179
+ /**
180
+ * Optimizes "for" tag by removing the "loop" variable creation whenever possible.
181
+ */
182
+ protected function enterOptimizeFor(\Twig_NodeInterface $node, Environment $env)
183
+ {
184
+ if ($node instanceof ForNode) {
185
+ // disable the loop variable by default
186
+ $node->setAttribute('with_loop', false);
187
+ array_unshift($this->loops, $node);
188
+ array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name'));
189
+ array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name'));
190
+ } elseif (!$this->loops) {
191
+ // we are outside a loop
192
+ return;
193
+ }
194
+
195
+ // when do we need to add the loop variable back?
196
+
197
+ // the loop variable is referenced for the current loop
198
+ elseif ($node instanceof NameExpression && 'loop' === $node->getAttribute('name')) {
199
+ $node->setAttribute('always_defined', true);
200
+ $this->addLoopToCurrent();
201
+ }
202
+
203
+ // optimize access to loop targets
204
+ elseif ($node instanceof NameExpression && \in_array($node->getAttribute('name'), $this->loopsTargets)) {
205
+ $node->setAttribute('always_defined', true);
206
+ }
207
+
208
+ // block reference
209
+ elseif ($node instanceof BlockReferenceNode || $node instanceof BlockReferenceExpression) {
210
+ $this->addLoopToCurrent();
211
+ }
212
+
213
+ // include without the only attribute
214
+ elseif ($node instanceof IncludeNode && !$node->getAttribute('only')) {
215
+ $this->addLoopToAll();
216
+ }
217
+
218
+ // include function without the with_context=false parameter
219
+ elseif ($node instanceof FunctionExpression
220
+ && 'include' === $node->getAttribute('name')
221
+ && (!$node->getNode('arguments')->hasNode('with_context')
222
+ || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value')
223
+ )
224
+ ) {
225
+ $this->addLoopToAll();
226
+ }
227
+
228
+ // the loop variable is referenced via an attribute
229
+ elseif ($node instanceof GetAttrExpression
230
+ && (!$node->getNode('attribute') instanceof ConstantExpression
231
+ || 'parent' === $node->getNode('attribute')->getAttribute('value')
232
+ )
233
+ && (true === $this->loops[0]->getAttribute('with_loop')
234
+ || ($node->getNode('node') instanceof NameExpression
235
+ && 'loop' === $node->getNode('node')->getAttribute('name')
236
+ )
237
+ )
238
+ ) {
239
+ $this->addLoopToAll();
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Optimizes "for" tag by removing the "loop" variable creation whenever possible.
245
+ */
246
+ protected function leaveOptimizeFor(\Twig_NodeInterface $node, Environment $env)
247
+ {
248
+ if ($node instanceof ForNode) {
249
+ array_shift($this->loops);
250
+ array_shift($this->loopsTargets);
251
+ array_shift($this->loopsTargets);
252
+ }
253
+ }
254
+
255
+ protected function addLoopToCurrent()
256
+ {
257
+ $this->loops[0]->setAttribute('with_loop', true);
258
+ }
259
+
260
+ protected function addLoopToAll()
261
+ {
262
+ foreach ($this->loops as $loop) {
263
+ $loop->setAttribute('with_loop', true);
264
+ }
265
+ }
266
+
267
+ public function getPriority()
268
+ {
269
+ return 255;
270
+ }
271
+ }
272
+
273
+ class_alias('Twig\NodeVisitor\OptimizerNodeVisitor', 'Twig_NodeVisitor_Optimizer');
vendor/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\NodeVisitor;
13
+
14
+ use Twig\Environment;
15
+ use Twig\Node\Expression\BlockReferenceExpression;
16
+ use Twig\Node\Expression\ConditionalExpression;
17
+ use Twig\Node\Expression\ConstantExpression;
18
+ use Twig\Node\Expression\FilterExpression;
19
+ use Twig\Node\Expression\FunctionExpression;
20
+ use Twig\Node\Expression\GetAttrExpression;
21
+ use Twig\Node\Expression\MethodCallExpression;
22
+ use Twig\Node\Expression\NameExpression;
23
+ use Twig\Node\Expression\ParentExpression;
24
+ use Twig\Node\Node;
25
+
26
+ /**
27
+ * @final
28
+ */
29
+ class SafeAnalysisNodeVisitor extends AbstractNodeVisitor
30
+ {
31
+ protected $data = [];
32
+ protected $safeVars = [];
33
+
34
+ public function setSafeVars($safeVars)
35
+ {
36
+ $this->safeVars = $safeVars;
37
+ }
38
+
39
+ public function getSafe(\Twig_NodeInterface $node)
40
+ {
41
+ $hash = spl_object_hash($node);
42
+ if (!isset($this->data[$hash])) {
43
+ return;
44
+ }
45
+
46
+ foreach ($this->data[$hash] as $bucket) {
47
+ if ($bucket['key'] !== $node) {
48
+ continue;
49
+ }
50
+
51
+ if (\in_array('html_attr', $bucket['value'])) {
52
+ $bucket['value'][] = 'html';
53
+ }
54
+
55
+ return $bucket['value'];
56
+ }
57
+ }
58
+
59
+ protected function setSafe(\Twig_NodeInterface $node, array $safe)
60
+ {
61
+ $hash = spl_object_hash($node);
62
+ if (isset($this->data[$hash])) {
63
+ foreach ($this->data[$hash] as &$bucket) {
64
+ if ($bucket['key'] === $node) {
65
+ $bucket['value'] = $safe;
66
+
67
+ return;
68
+ }
69
+ }
70
+ }
71
+ $this->data[$hash][] = [
72
+ 'key' => $node,
73
+ 'value' => $safe,
74
+ ];
75
+ }
76
+
77
+ protected function doEnterNode(Node $node, Environment $env)
78
+ {
79
+ return $node;
80
+ }
81
+
82
+ protected function doLeaveNode(Node $node, Environment $env)
83
+ {
84
+ if ($node instanceof ConstantExpression) {
85
+ // constants are marked safe for all
86
+ $this->setSafe($node, ['all']);
87
+ } elseif ($node instanceof BlockReferenceExpression) {
88
+ // blocks are safe by definition
89
+ $this->setSafe($node, ['all']);
90
+ } elseif ($node instanceof ParentExpression) {
91
+ // parent block is safe by definition
92
+ $this->setSafe($node, ['all']);
93
+ } elseif ($node instanceof ConditionalExpression) {
94
+ // intersect safeness of both operands
95
+ $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3')));
96
+ $this->setSafe($node, $safe);
97
+ } elseif ($node instanceof FilterExpression) {
98
+ // filter expression is safe when the filter is safe
99
+ $name = $node->getNode('filter')->getAttribute('value');
100
+ $args = $node->getNode('arguments');
101
+ if (false !== $filter = $env->getFilter($name)) {
102
+ $safe = $filter->getSafe($args);
103
+ if (null === $safe) {
104
+ $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety());
105
+ }
106
+ $this->setSafe($node, $safe);
107
+ } else {
108
+ $this->setSafe($node, []);
109
+ }
110
+ } elseif ($node instanceof FunctionExpression) {
111
+ // function expression is safe when the function is safe
112
+ $name = $node->getAttribute('name');
113
+ $args = $node->getNode('arguments');
114
+ $function = $env->getFunction($name);
115
+ if (false !== $function) {
116
+ $this->setSafe($node, $function->getSafe($args));
117
+ } else {
118
+ $this->setSafe($node, []);
119
+ }
120
+ } elseif ($node instanceof MethodCallExpression) {
121
+ if ($node->getAttribute('safe')) {
122
+ $this->setSafe($node, ['all']);
123
+ } else {
124
+ $this->setSafe($node, []);
125
+ }
126
+ } elseif ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression) {
127
+ $name = $node->getNode('node')->getAttribute('name');
128
+ // attributes on template instances are safe
129
+ if ('_self' == $name || \in_array($name, $this->safeVars)) {
130
+ $this->setSafe($node, ['all']);
131
+ } else {
132
+ $this->setSafe($node, []);
133
+ }
134
+ } else {
135
+ $this->setSafe($node, []);
136
+ }
137
+
138
+ return $node;
139
+ }
140
+
141
+ protected function intersectSafe(array $a = null, array $b = null)
142
+ {
143
+ if (null === $a || null === $b) {
144
+ return [];
145
+ }
146
+
147
+ if (\in_array('all', $a)) {
148
+ return $b;
149
+ }
150
+
151
+ if (\in_array('all', $b)) {
152
+ return $a;
153
+ }
154
+
155
+ return array_intersect($a, $b);
156
+ }
157
+
158
+ public function getPriority()
159
+ {
160
+ return 0;
161
+ }
162
+ }
163
+
164
+ class_alias('Twig\NodeVisitor\SafeAnalysisNodeVisitor', 'Twig_NodeVisitor_SafeAnalysis');
vendor/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\NodeVisitor;
13
+
14
+ use Twig\Environment;
15
+ use Twig\Node\CheckSecurityNode;
16
+ use Twig\Node\CheckToStringNode;
17
+ use Twig\Node\Expression\Binary\ConcatBinary;
18
+ use Twig\Node\Expression\Binary\RangeBinary;
19
+ use Twig\Node\Expression\FilterExpression;
20
+ use Twig\Node\Expression\FunctionExpression;
21
+ use Twig\Node\Expression\GetAttrExpression;
22
+ use Twig\Node\Expression\NameExpression;
23
+ use Twig\Node\ModuleNode;
24
+ use Twig\Node\Node;
25
+ use Twig\Node\PrintNode;
26
+ use Twig\Node\SetNode;
27
+
28
+ /**
29
+ * @final
30
+ *
31
+ * @author Fabien Potencier <fabien@symfony.com>
32
+ */
33
+ class SandboxNodeVisitor extends AbstractNodeVisitor
34
+ {
35
+ protected $inAModule = false;
36
+ protected $tags;
37
+ protected $filters;
38
+ protected $functions;
39
+
40
+ private $needsToStringWrap = false;
41
+
42
+ protected function doEnterNode(Node $node, Environment $env)
43
+ {
44
+ if ($node instanceof ModuleNode) {
45
+ $this->inAModule = true;
46
+ $this->tags = [];
47
+ $this->filters = [];
48
+ $this->functions = [];
49
+
50
+ return $node;
51
+ } elseif ($this->inAModule) {
52
+ // look for tags
53
+ if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) {
54
+ $this->tags[$node->getNodeTag()] = $node;
55
+ }
56
+
57
+ // look for filters
58
+ if ($node instanceof FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) {
59
+ $this->filters[$node->getNode('filter')->getAttribute('value')] = $node;
60
+ }
61
+
62
+ // look for functions
63
+ if ($node instanceof FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) {
64
+ $this->functions[$node->getAttribute('name')] = $node;
65
+ }
66
+
67
+ // the .. operator is equivalent to the range() function
68
+ if ($node instanceof RangeBinary && !isset($this->functions['range'])) {
69
+ $this->functions['range'] = $node;
70
+ }
71
+
72
+ if ($node instanceof PrintNode) {
73
+ $this->needsToStringWrap = true;
74
+ $this->wrapNode($node, 'expr');
75
+ }
76
+
77
+ if ($node instanceof SetNode && !$node->getAttribute('capture')) {
78
+ $this->needsToStringWrap = true;
79
+ }
80
+
81
+ // wrap outer nodes that can implicitly call __toString()
82
+ if ($this->needsToStringWrap) {
83
+ if ($node instanceof ConcatBinary) {
84
+ $this->wrapNode($node, 'left');
85
+ $this->wrapNode($node, 'right');
86
+ }
87
+ if ($node instanceof FilterExpression) {
88
+ $this->wrapNode($node, 'node');
89
+ $this->wrapArrayNode($node, 'arguments');
90
+ }
91
+ if ($node instanceof FunctionExpression) {
92
+ $this->wrapArrayNode($node, 'arguments');
93
+ }
94
+ }
95
+ }
96
+
97
+ return $node;
98
+ }
99
+
100
+ protected function doLeaveNode(Node $node, Environment $env)
101
+ {
102
+ if ($node instanceof ModuleNode) {
103
+ $this->inAModule = false;
104
+
105
+ $node->getNode('constructor_end')->setNode('_security_check', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')]));
106
+ } elseif ($this->inAModule) {
107
+ if ($node instanceof PrintNode || $node instanceof SetNode) {
108
+ $this->needsToStringWrap = false;
109
+ }
110
+ }
111
+
112
+ return $node;
113
+ }
114
+
115
+ private function wrapNode(Node $node, $name)
116
+ {
117
+ $expr = $node->getNode($name);
118
+ if ($expr instanceof NameExpression || $expr instanceof GetAttrExpression) {
119
+ $node->setNode($name, new CheckToStringNode($expr));
120
+ }
121
+ }
122
+
123
+ private function wrapArrayNode(Node $node, $name)
124
+ {
125
+ $args = $node->getNode($name);
126
+ foreach ($args as $name => $_) {
127
+ $this->wrapNode($args, $name);
128
+ }
129
+ }
130
+
131
+ public function getPriority()
132
+ {
133
+ return 0;
134
+ }
135
+ }
136
+
137
+ class_alias('Twig\NodeVisitor\SandboxNodeVisitor', 'Twig_NodeVisitor_Sandbox');
vendor/twig/twig/src/Parser.php ADDED
@@ -0,0 +1,439 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig;
14
+
15
+ use Twig\Error\SyntaxError;
16
+ use Twig\Node\BlockNode;
17
+ use Twig\Node\BlockReferenceNode;
18
+ use Twig\Node\BodyNode;
19
+ use Twig\Node\Expression\AbstractExpression;
20
+ use Twig\Node\MacroNode;
21
+ use Twig\Node\ModuleNode;
22
+ use Twig\Node\Node;
23
+ use Twig\Node\NodeCaptureInterface;
24
+ use Twig\Node\NodeOutputInterface;
25
+ use Twig\Node\PrintNode;
26
+ use Twig\Node\TextNode;
27
+ use Twig\NodeVisitor\NodeVisitorInterface;
28
+ use Twig\TokenParser\TokenParserInterface;
29
+
30
+ /**
31
+ * Default parser implementation.
32
+ *
33
+ * @author Fabien Potencier <fabien@symfony.com>
34
+ */
35
+ class Parser implements \Twig_ParserInterface
36
+ {
37
+ protected $stack = [];
38
+ protected $stream;
39
+ protected $parent;
40
+ protected $handlers;
41
+ protected $visitors;
42
+ protected $expressionParser;
43
+ protected $blocks;
44
+ protected $blockStack;
45
+ protected $macros;
46
+ protected $env;
47
+ protected $reservedMacroNames;
48
+ protected $importedSymbols;
49
+ protected $traits;
50
+ protected $embeddedTemplates = [];
51
+ private $varNameSalt = 0;
52
+
53
+ public function __construct(Environment $env)
54
+ {
55
+ $this->env = $env;
56
+ }
57
+
58
+ /**
59
+ * @deprecated since 1.27 (to be removed in 2.0)
60
+ */
61
+ public function getEnvironment()
62
+ {
63
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED);
64
+
65
+ return $this->env;
66
+ }
67
+
68
+ public function getVarName()
69
+ {
70
+ return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->stream->getSourceContext()->getCode().$this->varNameSalt++));
71
+ }
72
+
73
+ /**
74
+ * @deprecated since 1.27 (to be removed in 2.0). Use $parser->getStream()->getSourceContext()->getPath() instead.
75
+ */
76
+ public function getFilename()
77
+ {
78
+ @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use $parser->getStream()->getSourceContext()->getPath() instead.', __METHOD__), E_USER_DEPRECATED);
79
+
80
+ return $this->stream->getSourceContext()->getName();
81
+ }
82
+
83
+ public function parse(TokenStream $stream, $test = null, $dropNeedle = false)
84
+ {
85
+ // push all variables into the stack to keep the current state of the parser
86
+ // using get_object_vars() instead of foreach would lead to https://bugs.php.net/71336
87
+ // This hack can be removed when min version if PHP 7.0
88
+ $vars = [];
89
+ foreach ($this as $k => $v) {
90
+ $vars[$k] = $v;
91
+ }
92
+
93
+ unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']);
94
+ $this->stack[] = $vars;
95
+
96
+ // tag handlers
97
+ if (null === $this->handlers) {
98
+ $this->handlers = $this->env->getTokenParsers();
99
+ $this->handlers->setParser($this);
100
+ }
101
+
102
+ // node visitors
103
+ if (null === $this->visitors) {
104
+ $this->visitors = $this->env->getNodeVisitors();
105
+ }
106
+
107
+ if (null === $this->expressionParser) {
108
+ $this->expressionParser = new ExpressionParser($this, $this->env);
109
+ }
110
+
111
+ $this->stream = $stream;
112
+ $this->parent = null;
113
+ $this->blocks = [];
114
+ $this->macros = [];
115
+ $this->traits = [];
116
+ $this->blockStack = [];
117
+ $this->importedSymbols = [[]];
118
+ $this->embeddedTemplates = [];
119
+ $this->varNameSalt = 0;
120
+
121
+ try {
122
+ $body = $this->subparse($test, $dropNeedle);
123
+
124
+ if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) {
125
+ $body = new Node();
126
+ }
127
+ } catch (SyntaxError $e) {
128
+ if (!$e->getSourceContext()) {
129
+ $e->setSourceContext($this->stream->getSourceContext());
130
+ }
131
+
132
+ if (!$e->getTemplateLine()) {
133
+ $e->setTemplateLine($this->stream->getCurrent()->getLine());
134
+ }
135
+
136
+ throw $e;
137
+ }
138
+
139
+ $node = new ModuleNode(new BodyNode([$body]), $this->parent, new Node($this->blocks), new Node($this->macros), new Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext());
140
+
141
+ $traverser = new NodeTraverser($this->env, $this->visitors);
142
+
143
+ $node = $traverser->traverse($node);
144
+
145
+ // restore previous stack so previous parse() call can resume working
146
+ foreach (array_pop($this->stack) as $key => $val) {
147
+ $this->$key = $val;
148
+ }
149
+
150
+ return $node;
151
+ }
152
+
153
+ public function subparse($test, $dropNeedle = false)
154
+ {
155
+ $lineno = $this->getCurrentToken()->getLine();
156
+ $rv = [];
157
+ while (!$this->stream->isEOF()) {
158
+ switch ($this->getCurrentToken()->getType()) {
159
+ case Token::TEXT_TYPE:
160
+ $token = $this->stream->next();
161
+ $rv[] = new TextNode($token->getValue(), $token->getLine());
162
+ break;
163
+
164
+ case Token::VAR_START_TYPE:
165
+ $token = $this->stream->next();
166
+ $expr = $this->expressionParser->parseExpression();
167
+ $this->stream->expect(Token::VAR_END_TYPE);
168
+ $rv[] = new PrintNode($expr, $token->getLine());
169
+ break;
170
+
171
+ case Token::BLOCK_START_TYPE:
172
+ $this->stream->next();
173
+ $token = $this->getCurrentToken();
174
+
175
+ if (Token::NAME_TYPE !== $token->getType()) {
176
+ throw new SyntaxError('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext());
177
+ }
178
+
179
+ if (null !== $test && \call_user_func($test, $token)) {
180
+ if ($dropNeedle) {
181
+ $this->stream->next();
182
+ }
183
+
184
+ if (1 === \count($rv)) {
185
+ return $rv[0];
186
+ }
187
+
188
+ return new Node($rv, [], $lineno);
189
+ }
190
+
191
+ $subparser = $this->handlers->getTokenParser($token->getValue());
192
+ if (null === $subparser) {
193
+ if (null !== $test) {
194
+ $e = new SyntaxError(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext());
195
+
196
+ if (\is_array($test) && isset($test[0]) && $test[0] instanceof TokenParserInterface) {
197
+ $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno));
198
+ }
199
+ } else {
200
+ $e = new SyntaxError(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext());
201
+ $e->addSuggestions($token->getValue(), array_keys($this->env->getTags()));
202
+ }
203
+
204
+ throw $e;
205
+ }
206
+
207
+ $this->stream->next();
208
+
209
+ $node = $subparser->parse($token);
210
+ if (null !== $node) {
211
+ $rv[] = $node;
212
+ }
213
+ break;
214
+
215
+ default:
216
+ throw new SyntaxError('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext());
217
+ }
218
+ }
219
+
220
+ if (1 === \count($rv)) {
221
+ return $rv[0];
222
+ }
223
+
224
+ return new Node($rv, [], $lineno);
225
+ }
226
+
227
+ /**
228
+ * @deprecated since 1.27 (to be removed in 2.0)
229
+ */
230
+ public function addHandler($name, $class)
231
+ {
232
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED);
233
+
234
+ $this->handlers[$name] = $class;
235
+ }
236
+
237
+ /**
238
+ * @deprecated since 1.27 (to be removed in 2.0)
239
+ */
240
+ public function addNodeVisitor(NodeVisitorInterface $visitor)
241
+ {
242
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED);
243
+
244
+ $this->visitors[] = $visitor;
245
+ }
246
+
247
+ public function getBlockStack()
248
+ {
249
+ return $this->blockStack;
250
+ }
251
+
252
+ public function peekBlockStack()
253
+ {
254
+ return isset($this->blockStack[\count($this->blockStack) - 1]) ? $this->blockStack[\count($this->blockStack) - 1] : null;
255
+ }
256
+
257
+ public function popBlockStack()
258
+ {
259
+ array_pop($this->blockStack);
260
+ }
261
+
262
+ public function pushBlockStack($name)
263
+ {
264
+ $this->blockStack[] = $name;
265
+ }
266
+
267
+ public function hasBlock($name)
268
+ {
269
+ return isset($this->blocks[$name]);
270
+ }
271
+
272
+ public function getBlock($name)
273
+ {
274
+ return $this->blocks[$name];
275
+ }
276
+
277
+ public function setBlock($name, BlockNode $value)
278
+ {
279
+ $this->blocks[$name] = new BodyNode([$value], [], $value->getTemplateLine());
280
+ }
281
+
282
+ public function hasMacro($name)
283
+ {
284
+ return isset($this->macros[$name]);
285
+ }
286
+
287
+ public function setMacro($name, MacroNode $node)
288
+ {
289
+ if ($this->isReservedMacroName($name)) {
290
+ throw new SyntaxError(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext());
291
+ }
292
+
293
+ $this->macros[$name] = $node;
294
+ }
295
+
296
+ public function isReservedMacroName($name)
297
+ {
298
+ if (null === $this->reservedMacroNames) {
299
+ $this->reservedMacroNames = [];
300
+ $r = new \ReflectionClass($this->env->getBaseTemplateClass());
301
+ foreach ($r->getMethods() as $method) {
302
+ $methodName = strtolower($method->getName());
303
+
304
+ if ('get' === substr($methodName, 0, 3) && isset($methodName[3])) {
305
+ $this->reservedMacroNames[] = substr($methodName, 3);
306
+ }
307
+ }
308
+ }
309
+
310
+ return \in_array(strtolower($name), $this->reservedMacroNames);
311
+ }
312
+
313
+ public function addTrait($trait)
314
+ {
315
+ $this->traits[] = $trait;
316
+ }
317
+
318
+ public function hasTraits()
319
+ {
320
+ return \count($this->traits) > 0;
321
+ }
322
+
323
+ public function embedTemplate(ModuleNode $template)
324
+ {
325
+ $template->setIndex(mt_rand());
326
+
327
+ $this->embeddedTemplates[] = $template;
328
+ }
329
+
330
+ public function addImportedSymbol($type, $alias, $name = null, AbstractExpression $node = null)
331
+ {
332
+ $this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node];
333
+ }
334
+
335
+ public function getImportedSymbol($type, $alias)
336
+ {
337
+ if (null !== $this->peekBlockStack()) {
338
+ foreach ($this->importedSymbols as $functions) {
339
+ if (isset($functions[$type][$alias])) {
340
+ if (\count($this->blockStack) > 1) {
341
+ return null;
342
+ }
343
+
344
+ return $functions[$type][$alias];
345
+ }
346
+ }
347
+ } else {
348
+ return isset($this->importedSymbols[0][$type][$alias]) ? $this->importedSymbols[0][$type][$alias] : null;
349
+ }
350
+ }
351
+
352
+ public function isMainScope()
353
+ {
354
+ return 1 === \count($this->importedSymbols);
355
+ }
356
+
357
+ public function pushLocalScope()
358
+ {
359
+ array_unshift($this->importedSymbols, []);
360
+ }
361
+
362
+ public function popLocalScope()
363
+ {
364
+ array_shift($this->importedSymbols);
365
+ }
366
+
367
+ /**
368
+ * @return ExpressionParser
369
+ */
370
+ public function getExpressionParser()
371
+ {
372
+ return $this->expressionParser;
373
+ }
374
+
375
+ public function getParent()
376
+ {
377
+ return $this->parent;
378
+ }
379
+
380
+ public function setParent($parent)
381
+ {
382
+ $this->parent = $parent;
383
+ }
384
+
385
+ /**
386
+ * @return TokenStream
387
+ */
388
+ public function getStream()
389
+ {
390
+ return $this->stream;
391
+ }
392
+
393
+ /**
394
+ * @return Token
395
+ */
396
+ public function getCurrentToken()
397
+ {
398
+ return $this->stream->getCurrent();
399
+ }
400
+
401
+ protected function filterBodyNodes(\Twig_NodeInterface $node)
402
+ {
403
+ // check that the body does not contain non-empty output nodes
404
+ if (
405
+ ($node instanceof TextNode && !ctype_space($node->getAttribute('data')))
406
+ ||
407
+ (!$node instanceof TextNode && !$node instanceof BlockReferenceNode && $node instanceof NodeOutputInterface)
408
+ ) {
409
+ if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) {
410
+ $t = substr($node->getAttribute('data'), 3);
411
+ if ('' === $t || ctype_space($t)) {
412
+ // bypass empty nodes starting with a BOM
413
+ return;
414
+ }
415
+ }
416
+
417
+ throw new SyntaxError('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext());
418
+ }
419
+
420
+ // bypass nodes that will "capture" the output
421
+ if ($node instanceof NodeCaptureInterface) {
422
+ return $node;
423
+ }
424
+
425
+ if ($node instanceof NodeOutputInterface) {
426
+ return;
427
+ }
428
+
429
+ foreach ($node as $k => $n) {
430
+ if (null !== $n && null === $this->filterBodyNodes($n)) {
431
+ $node->removeNode($k);
432
+ }
433
+ }
434
+
435
+ return $node;
436
+ }
437
+ }
438
+
439
+ class_alias('Twig\Parser', 'Twig_Parser');
vendor/twig/twig/src/Profiler/Dumper/BaseDumper.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Profiler\Dumper;
13
+
14
+ use Twig\Profiler\Profile;
15
+
16
+ /**
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ abstract class BaseDumper
20
+ {
21
+ private $root;
22
+
23
+ public function dump(Profile $profile)
24
+ {
25
+ return $this->dumpProfile($profile);
26
+ }
27
+
28
+ abstract protected function formatTemplate(Profile $profile, $prefix);
29
+
30
+ abstract protected function formatNonTemplate(Profile $profile, $prefix);
31
+
32
+ abstract protected function formatTime(Profile $profile, $percent);
33
+
34
+ private function dumpProfile(Profile $profile, $prefix = '', $sibling = false)
35
+ {
36
+ if ($profile->isRoot()) {
37
+ $this->root = $profile->getDuration();
38
+ $start = $profile->getName();
39
+ } else {
40
+ if ($profile->isTemplate()) {
41
+ $start = $this->formatTemplate($profile, $prefix);
42
+ } else {
43
+ $start = $this->formatNonTemplate($profile, $prefix);
44
+ }
45
+ $prefix .= $sibling ? '│ ' : ' ';
46
+ }
47
+
48
+ $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0;
49
+
50
+ if ($profile->getDuration() * 1000 < 1) {
51
+ $str = $start."\n";
52
+ } else {
53
+ $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent));
54
+ }
55
+
56
+ $nCount = \count($profile->getProfiles());
57
+ foreach ($profile as $i => $p) {
58
+ $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount);
59
+ }
60
+
61
+ return $str;
62
+ }
63
+ }
64
+
65
+ class_alias('Twig\Profiler\Dumper\BaseDumper', 'Twig_Profiler_Dumper_Base');
vendor/twig/twig/src/Profiler/Dumper/BlackfireDumper.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Profiler\Dumper;
13
+
14
+ use Twig\Profiler\Profile;
15
+
16
+ /**
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ *
19
+ * @final
20
+ */
21
+ class BlackfireDumper
22
+ {
23
+ public function dump(Profile $profile)
24
+ {
25
+ $data = [];
26
+ $this->dumpProfile('main()', $profile, $data);
27
+ $this->dumpChildren('main()', $profile, $data);
28
+
29
+ $start = sprintf('%f', microtime(true));
30
+ $str = <<<EOF
31
+ file-format: BlackfireProbe
32
+ cost-dimensions: wt mu pmu
33
+ request-start: {$start}
34
+
35
+
36
+ EOF;
37
+
38
+ foreach ($data as $name => $values) {
39
+ $str .= "{$name}//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n";
40
+ }
41
+
42
+ return $str;
43
+ }
44
+
45
+ private function dumpChildren($parent, Profile $profile, &$data)
46
+ {
47
+ foreach ($profile as $p) {
48
+ if ($p->isTemplate()) {
49
+ $name = $p->getTemplate();
50
+ } else {
51
+ $name = sprintf('%s::%s(%s)', $p->getTemplate(), $p->getType(), $p->getName());
52
+ }
53
+ $this->dumpProfile(sprintf('%s==>%s', $parent, $name), $p, $data);
54
+ $this->dumpChildren($name, $p, $data);
55
+ }
56
+ }
57
+
58
+ private function dumpProfile($edge, Profile $profile, &$data)
59
+ {
60
+ if (isset($data[$edge])) {
61
+ ++$data[$edge]['ct'];
62
+ $data[$edge]['wt'] += floor($profile->getDuration() * 1000000);
63
+ $data[$edge]['mu'] += $profile->getMemoryUsage();
64
+ $data[$edge]['pmu'] += $profile->getPeakMemoryUsage();
65
+ } else {
66
+ $data[$edge] = [
67
+ 'ct' => 1,
68
+ 'wt' => floor($profile->getDuration() * 1000000),
69
+ 'mu' => $profile->getMemoryUsage(),
70
+ 'pmu' => $profile->getPeakMemoryUsage(),
71
+ ];
72
+ }
73
+ }
74
+ }
75
+
76
+ class_alias('Twig\Profiler\Dumper\BlackfireDumper', 'Twig_Profiler_Dumper_Blackfire');
vendor/twig/twig/src/Profiler/Dumper/HtmlDumper.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Profiler\Dumper;
13
+
14
+ use Twig\Profiler\Profile;
15
+
16
+ /**
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ *
19
+ * @final
20
+ */
21
+ class HtmlDumper extends BaseDumper
22
+ {
23
+ private static $colors = [
24
+ 'block' => '#dfd',
25
+ 'macro' => '#ddf',
26
+ 'template' => '#ffd',
27
+ 'big' => '#d44',
28
+ ];
29
+
30
+ public function dump(Profile $profile)
31
+ {
32
+ return '<pre>'.parent::dump($profile).'</pre>';
33
+ }
34
+
35
+ protected function formatTemplate(Profile $profile, $prefix)
36
+ {
37
+ return sprintf('%s└ <span style="background-color: %s">%s</span>', $prefix, self::$colors['template'], $profile->getTemplate());
38
+ }
39
+
40
+ protected function formatNonTemplate(Profile $profile, $prefix)
41
+ {
42
+ return sprintf('%s└ %s::%s(<span style="background-color: %s">%s</span>)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName());
43
+ }
44
+
45
+ protected function formatTime(Profile $profile, $percent)
46
+ {
47
+ return sprintf('<span style="color: %s">%.2fms/%.0f%%</span>', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent);
48
+ }
49
+ }
50
+
51
+ class_alias('Twig\Profiler\Dumper\HtmlDumper', 'Twig_Profiler_Dumper_Html');
vendor/twig/twig/src/Profiler/Dumper/TextDumper.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Profiler\Dumper;
13
+
14
+ use Twig\Profiler\Profile;
15
+
16
+ /**
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ *
19
+ * @final
20
+ */
21
+ class TextDumper extends BaseDumper
22
+ {
23
+ protected function formatTemplate(Profile $profile, $prefix)
24
+ {
25
+ return sprintf('%s└ %s', $prefix, $profile->getTemplate());
26
+ }
27
+
28
+ protected function formatNonTemplate(Profile $profile, $prefix)
29
+ {
30
+ return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName());
31
+ }
32
+
33
+ protected function formatTime(Profile $profile, $percent)
34
+ {
35
+ return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent);
36
+ }
37
+ }
38
+
39
+ class_alias('Twig\Profiler\Dumper\TextDumper', 'Twig_Profiler_Dumper_Text');
vendor/twig/twig/src/Profiler/Node/EnterProfileNode.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Profiler\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Node;
16
+
17
+ /**
18
+ * Represents a profile enter node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class EnterProfileNode extends Node
23
+ {
24
+ public function __construct($extensionName, $type, $name, $varName)
25
+ {
26
+ parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]);
27
+ }
28
+
29
+ public function compile(Compiler $compiler)
30
+ {
31
+ $compiler
32
+ ->write(sprintf('$%s = $this->env->getExtension(', $this->getAttribute('var_name')))
33
+ ->repr($this->getAttribute('extension_name'))
34
+ ->raw(");\n")
35
+ ->write(sprintf('$%s->enter($%s = new \Twig\Profiler\Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof'))
36
+ ->repr($this->getAttribute('type'))
37
+ ->raw(', ')
38
+ ->repr($this->getAttribute('name'))
39
+ ->raw("));\n\n")
40
+ ;
41
+ }
42
+ }
43
+
44
+ class_alias('Twig\Profiler\Node\EnterProfileNode', 'Twig_Profiler_Node_EnterProfile');
vendor/twig/twig/src/Profiler/Node/LeaveProfileNode.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Profiler\Node;
13
+
14
+ use Twig\Compiler;
15
+ use Twig\Node\Node;
16
+
17
+ /**
18
+ * Represents a profile leave node.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ */
22
+ class LeaveProfileNode extends Node
23
+ {
24
+ public function __construct($varName)
25
+ {
26
+ parent::__construct([], ['var_name' => $varName]);
27
+ }
28
+
29
+ public function compile(Compiler $compiler)
30
+ {
31
+ $compiler
32
+ ->write("\n")
33
+ ->write(sprintf("\$%s->leave(\$%s);\n\n", $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof'))
34
+ ;
35
+ }
36
+ }
37
+
38
+ class_alias('Twig\Profiler\Node\LeaveProfileNode', 'Twig_Profiler_Node_LeaveProfile');
vendor/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Profiler\NodeVisitor;
13
+
14
+ use Twig\Environment;
15
+ use Twig\Node\BlockNode;
16
+ use Twig\Node\BodyNode;
17
+ use Twig\Node\MacroNode;
18
+ use Twig\Node\ModuleNode;
19
+ use Twig\Node\Node;
20
+ use Twig\NodeVisitor\AbstractNodeVisitor;
21
+ use Twig\Profiler\Node\EnterProfileNode;
22
+ use Twig\Profiler\Node\LeaveProfileNode;
23
+ use Twig\Profiler\Profile;
24
+
25
+ /**
26
+ * @author Fabien Potencier <fabien@symfony.com>
27
+ *
28
+ * @final
29
+ */
30
+ class ProfilerNodeVisitor extends AbstractNodeVisitor
31
+ {
32
+ private $extensionName;
33
+
34
+ public function __construct($extensionName)
35
+ {
36
+ $this->extensionName = $extensionName;
37
+ }
38
+
39
+ protected function doEnterNode(Node $node, Environment $env)
40
+ {
41
+ return $node;
42
+ }
43
+
44
+ protected function doLeaveNode(Node $node, Environment $env)
45
+ {
46
+ if ($node instanceof ModuleNode) {
47
+ $varName = $this->getVarName();
48
+ $node->setNode('display_start', new Node([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')]));
49
+ $node->setNode('display_end', new Node([new LeaveProfileNode($varName), $node->getNode('display_end')]));
50
+ } elseif ($node instanceof BlockNode) {
51
+ $varName = $this->getVarName();
52
+ $node->setNode('body', new BodyNode([
53
+ new EnterProfileNode($this->extensionName, Profile::BLOCK, $node->getAttribute('name'), $varName),
54
+ $node->getNode('body'),
55
+ new LeaveProfileNode($varName),
56
+ ]));
57
+ } elseif ($node instanceof MacroNode) {
58
+ $varName = $this->getVarName();
59
+ $node->setNode('body', new BodyNode([
60
+ new EnterProfileNode($this->extensionName, Profile::MACRO, $node->getAttribute('name'), $varName),
61
+ $node->getNode('body'),
62
+ new LeaveProfileNode($varName),
63
+ ]));
64
+ }
65
+
66
+ return $node;
67
+ }
68
+
69
+ private function getVarName()
70
+ {
71
+ return sprintf('__internal_%s', hash('sha256', $this->extensionName));
72
+ }
73
+
74
+ public function getPriority()
75
+ {
76
+ return 0;
77
+ }
78
+ }
79
+
80
+ class_alias('Twig\Profiler\NodeVisitor\ProfilerNodeVisitor', 'Twig_Profiler_NodeVisitor_Profiler');
vendor/twig/twig/src/Profiler/Profile.php ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Profiler;
13
+
14
+ /**
15
+ * @author Fabien Potencier <fabien@symfony.com>
16
+ *
17
+ * @final
18
+ */
19
+ class Profile implements \IteratorAggregate, \Serializable
20
+ {
21
+ const ROOT = 'ROOT';
22
+ const BLOCK = 'block';
23
+ const TEMPLATE = 'template';
24
+ const MACRO = 'macro';
25
+
26
+ private $template;
27
+ private $name;
28
+ private $type;
29
+ private $starts = [];
30
+ private $ends = [];
31
+ private $profiles = [];
32
+
33
+ public function __construct($template = 'main', $type = self::ROOT, $name = 'main')
34
+ {
35
+ $this->template = $template;
36
+ $this->type = $type;
37
+ $this->name = 0 === strpos($name, '__internal_') ? 'INTERNAL' : $name;
38
+ $this->enter();
39
+ }
40
+
41
+ public function getTemplate()
42
+ {
43
+ return $this->template;
44
+ }
45
+
46
+ public function getType()
47
+ {
48
+ return $this->type;
49
+ }
50
+
51
+ public function getName()
52
+ {
53
+ return $this->name;
54
+ }
55
+
56
+ public function isRoot()
57
+ {
58
+ return self::ROOT === $this->type;
59
+ }
60
+
61
+ public function isTemplate()
62
+ {
63
+ return self::TEMPLATE === $this->type;
64
+ }
65
+
66
+ public function isBlock()
67
+ {
68
+ return self::BLOCK === $this->type;
69
+ }
70
+
71
+ public function isMacro()
72
+ {
73
+ return self::MACRO === $this->type;
74
+ }
75
+
76
+ public function getProfiles()
77
+ {
78
+ return $this->profiles;
79
+ }
80
+
81
+ public function addProfile(self $profile)
82
+ {
83
+ $this->profiles[] = $profile;
84
+ }
85
+
86
+ /**
87
+ * Returns the duration in microseconds.
88
+ *
89
+ * @return float
90
+ */
91
+ public function getDuration()
92
+ {
93
+ if ($this->isRoot() && $this->profiles) {
94
+ // for the root node with children, duration is the sum of all child durations
95
+ $duration = 0;
96
+ foreach ($this->profiles as $profile) {
97
+ $duration += $profile->getDuration();
98
+ }
99
+
100
+ return $duration;
101
+ }
102
+
103
+ return isset($this->ends['wt']) && isset($this->starts['wt']) ? $this->ends['wt'] - $this->starts['wt'] : 0;
104
+ }
105
+
106
+ /**
107
+ * Returns the memory usage in bytes.
108
+ *
109
+ * @return int
110
+ */
111
+ public function getMemoryUsage()
112
+ {
113
+ return isset($this->ends['mu']) && isset($this->starts['mu']) ? $this->ends['mu'] - $this->starts['mu'] : 0;
114
+ }
115
+
116
+ /**
117
+ * Returns the peak memory usage in bytes.
118
+ *
119
+ * @return int
120
+ */
121
+ public function getPeakMemoryUsage()
122
+ {
123
+ return isset($this->ends['pmu']) && isset($this->starts['pmu']) ? $this->ends['pmu'] - $this->starts['pmu'] : 0;
124
+ }
125
+
126
+ /**
127
+ * Starts the profiling.
128
+ */
129
+ public function enter()
130
+ {
131
+ $this->starts = [
132
+ 'wt' => microtime(true),
133
+ 'mu' => memory_get_usage(),
134
+ 'pmu' => memory_get_peak_usage(),
135
+ ];
136
+ }
137
+
138
+ /**
139
+ * Stops the profiling.
140
+ */
141
+ public function leave()
142
+ {
143
+ $this->ends = [
144
+ 'wt' => microtime(true),
145
+ 'mu' => memory_get_usage(),
146
+ 'pmu' => memory_get_peak_usage(),
147
+ ];
148
+ }
149
+
150
+ public function reset()
151
+ {
152
+ $this->starts = $this->ends = $this->profiles = [];
153
+ $this->enter();
154
+ }
155
+
156
+ public function getIterator()
157
+ {
158
+ return new \ArrayIterator($this->profiles);
159
+ }
160
+
161
+ public function serialize()
162
+ {
163
+ return serialize($this->__serialize());
164
+ }
165
+
166
+ public function unserialize($data)
167
+ {
168
+ $this->__unserialize(unserialize($data));
169
+ }
170
+
171
+ /**
172
+ * @internal
173
+ */
174
+ public function __serialize()
175
+ {
176
+ return [$this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles];
177
+ }
178
+
179
+ /**
180
+ * @internal
181
+ */
182
+ public function __unserialize(array $data)
183
+ {
184
+ list($this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles) = $data;
185
+ }
186
+ }
187
+
188
+ class_alias('Twig\Profiler\Profile', 'Twig_Profiler_Profile');
vendor/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\RuntimeLoader;
13
+
14
+ use Psr\Container\ContainerInterface;
15
+
16
+ /**
17
+ * Lazily loads Twig runtime implementations from a PSR-11 container.
18
+ *
19
+ * Note that the runtime services MUST use their class names as identifiers.
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ * @author Robin Chalas <robin.chalas@gmail.com>
23
+ */
24
+ class ContainerRuntimeLoader implements RuntimeLoaderInterface
25
+ {
26
+ private $container;
27
+
28
+ public function __construct(ContainerInterface $container)
29
+ {
30
+ $this->container = $container;
31
+ }
32
+
33
+ public function load($class)
34
+ {
35
+ if ($this->container->has($class)) {
36
+ return $this->container->get($class);
37
+ }
38
+ }
39
+ }
40
+
41
+ class_alias('Twig\RuntimeLoader\ContainerRuntimeLoader', 'Twig_ContainerRuntimeLoader');
vendor/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\RuntimeLoader;
13
+
14
+ /**
15
+ * Lazy loads the runtime implementations for a Twig element.
16
+ *
17
+ * @author Robin Chalas <robin.chalas@gmail.com>
18
+ */
19
+ class FactoryRuntimeLoader implements RuntimeLoaderInterface
20
+ {
21
+ private $map;
22
+
23
+ /**
24
+ * @param array $map An array where keys are class names and values factory callables
25
+ */
26
+ public function __construct($map = [])
27
+ {
28
+ $this->map = $map;
29
+ }
30
+
31
+ public function load($class)
32
+ {
33
+ if (isset($this->map[$class])) {
34
+ $runtimeFactory = $this->map[$class];
35
+
36
+ return $runtimeFactory();
37
+ }
38
+ }
39
+ }
40
+
41
+ class_alias('Twig\RuntimeLoader\FactoryRuntimeLoader', 'Twig_FactoryRuntimeLoader');
vendor/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\RuntimeLoader;
13
+
14
+ /**
15
+ * Creates runtime implementations for Twig elements (filters/functions/tests).
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ interface RuntimeLoaderInterface
20
+ {
21
+ /**
22
+ * Creates the runtime implementation of a Twig element (filter/function/test).
23
+ *
24
+ * @param string $class A runtime class
25
+ *
26
+ * @return object|null The runtime instance or null if the loader does not know how to create the runtime for this class
27
+ */
28
+ public function load($class);
29
+ }
30
+
31
+ class_alias('Twig\RuntimeLoader\RuntimeLoaderInterface', 'Twig_RuntimeLoaderInterface');
vendor/twig/twig/src/Sandbox/SecurityError.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Sandbox;
13
+
14
+ use Twig\Error\Error;
15
+
16
+ /**
17
+ * Exception thrown when a security error occurs at runtime.
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ class SecurityError extends Error
22
+ {
23
+ }
24
+
25
+ class_alias('Twig\Sandbox\SecurityError', 'Twig_Sandbox_SecurityError');
vendor/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Sandbox;
13
+
14
+ /**
15
+ * Exception thrown when a not allowed filter is used in a template.
16
+ *
17
+ * @author Martin Hasoň <martin.hason@gmail.com>
18
+ */
19
+ class SecurityNotAllowedFilterError extends SecurityError
20
+ {
21
+ private $filterName;
22
+
23
+ public function __construct($message, $functionName, $lineno = -1, $filename = null, \Exception $previous = null)
24
+ {
25
+ parent::__construct($message, $lineno, $filename, $previous);
26
+ $this->filterName = $functionName;
27
+ }
28
+
29
+ public function getFilterName()
30
+ {
31
+ return $this->filterName;
32
+ }
33
+ }
34
+
35
+ class_alias('Twig\Sandbox\SecurityNotAllowedFilterError', 'Twig_Sandbox_SecurityNotAllowedFilterError');
vendor/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Sandbox;
13
+
14
+ /**
15
+ * Exception thrown when a not allowed function is used in a template.
16
+ *
17
+ * @author Martin Hasoň <martin.hason@gmail.com>
18
+ */
19
+ class SecurityNotAllowedFunctionError extends SecurityError
20
+ {
21
+ private $functionName;
22
+
23
+ public function __construct($message, $functionName, $lineno = -1, $filename = null, \Exception $previous = null)
24
+ {
25
+ parent::__construct($message, $lineno, $filename, $previous);
26
+ $this->functionName = $functionName;
27
+ }
28
+
29
+ public function getFunctionName()
30
+ {
31
+ return $this->functionName;
32
+ }
33
+ }
34
+
35
+ class_alias('Twig\Sandbox\SecurityNotAllowedFunctionError', 'Twig_Sandbox_SecurityNotAllowedFunctionError');
vendor/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Sandbox;
13
+
14
+ /**
15
+ * Exception thrown when a not allowed class method is used in a template.
16
+ *
17
+ * @author Kit Burton-Senior <mail@kitbs.com>
18
+ */
19
+ class SecurityNotAllowedMethodError extends SecurityError
20
+ {
21
+ private $className;
22
+ private $methodName;
23
+
24
+ public function __construct($message, $className, $methodName, $lineno = -1, $filename = null, \Exception $previous = null)
25
+ {
26
+ parent::__construct($message, $lineno, $filename, $previous);
27
+ $this->className = $className;
28
+ $this->methodName = $methodName;
29
+ }
30
+
31
+ public function getClassName()
32
+ {
33
+ return $this->className;
34
+ }
35
+
36
+ public function getMethodName()
37
+ {
38
+ return $this->methodName;
39
+ }
40
+ }
41
+
42
+ class_alias('Twig\Sandbox\SecurityNotAllowedMethodError', 'Twig_Sandbox_SecurityNotAllowedMethodError');
vendor/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Sandbox;
13
+
14
+ /**
15
+ * Exception thrown when a not allowed class property is used in a template.
16
+ *
17
+ * @author Kit Burton-Senior <mail@kitbs.com>
18
+ */
19
+ class SecurityNotAllowedPropertyError extends SecurityError
20
+ {
21
+ private $className;
22
+ private $propertyName;
23
+
24
+ public function __construct($message, $className, $propertyName, $lineno = -1, $filename = null, \Exception $previous = null)
25
+ {
26
+ parent::__construct($message, $lineno, $filename, $previous);
27
+ $this->className = $className;
28
+ $this->propertyName = $propertyName;
29
+ }
30
+
31
+ public function getClassName()
32
+ {
33
+ return $this->className;
34
+ }
35
+
36
+ public function getPropertyName()
37
+ {
38
+ return $this->propertyName;
39
+ }
40
+ }
41
+
42
+ class_alias('Twig\Sandbox\SecurityNotAllowedPropertyError', 'Twig_Sandbox_SecurityNotAllowedPropertyError');
vendor/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Sandbox;
13
+
14
+ /**
15
+ * Exception thrown when a not allowed tag is used in a template.
16
+ *
17
+ * @author Martin Hasoň <martin.hason@gmail.com>
18
+ */
19
+ class SecurityNotAllowedTagError extends SecurityError
20
+ {
21
+ private $tagName;
22
+
23
+ public function __construct($message, $tagName, $lineno = -1, $filename = null, \Exception $previous = null)
24
+ {
25
+ parent::__construct($message, $lineno, $filename, $previous);
26
+ $this->tagName = $tagName;
27
+ }
28
+
29
+ public function getTagName()
30
+ {
31
+ return $this->tagName;
32
+ }
33
+ }
34
+
35
+ class_alias('Twig\Sandbox\SecurityNotAllowedTagError', 'Twig_Sandbox_SecurityNotAllowedTagError');
vendor/twig/twig/src/Sandbox/SecurityPolicy.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Sandbox;
13
+
14
+ use Twig\Markup;
15
+
16
+ /**
17
+ * Represents a security policy which need to be enforced when sandbox mode is enabled.
18
+ *
19
+ * @final
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class SecurityPolicy implements SecurityPolicyInterface
24
+ {
25
+ protected $allowedTags;
26
+ protected $allowedFilters;
27
+ protected $allowedMethods;
28
+ protected $allowedProperties;
29
+ protected $allowedFunctions;
30
+
31
+ public function __construct(array $allowedTags = [], array $allowedFilters = [], array $allowedMethods = [], array $allowedProperties = [], array $allowedFunctions = [])
32
+ {
33
+ $this->allowedTags = $allowedTags;
34
+ $this->allowedFilters = $allowedFilters;
35
+ $this->setAllowedMethods($allowedMethods);
36
+ $this->allowedProperties = $allowedProperties;
37
+ $this->allowedFunctions = $allowedFunctions;
38
+ }
39
+
40
+ public function setAllowedTags(array $tags)
41
+ {
42
+ $this->allowedTags = $tags;
43
+ }
44
+
45
+ public function setAllowedFilters(array $filters)
46
+ {
47
+ $this->allowedFilters = $filters;
48
+ }
49
+
50
+ public function setAllowedMethods(array $methods)
51
+ {
52
+ $this->allowedMethods = [];
53
+ foreach ($methods as $class => $m) {
54
+ $this->allowedMethods[$class] = array_map('strtolower', \is_array($m) ? $m : [$m]);
55
+ }
56
+ }
57
+
58
+ public function setAllowedProperties(array $properties)
59
+ {
60
+ $this->allowedProperties = $properties;
61
+ }
62
+
63
+ public function setAllowedFunctions(array $functions)
64
+ {
65
+ $this->allowedFunctions = $functions;
66
+ }
67
+
68
+ public function checkSecurity($tags, $filters, $functions)
69
+ {
70
+ foreach ($tags as $tag) {
71
+ if (!\in_array($tag, $this->allowedTags)) {
72
+ throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag);
73
+ }
74
+ }
75
+
76
+ foreach ($filters as $filter) {
77
+ if (!\in_array($filter, $this->allowedFilters)) {
78
+ throw new SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter);
79
+ }
80
+ }
81
+
82
+ foreach ($functions as $function) {
83
+ if (!\in_array($function, $this->allowedFunctions)) {
84
+ throw new SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function);
85
+ }
86
+ }
87
+ }
88
+
89
+ public function checkMethodAllowed($obj, $method)
90
+ {
91
+ if ($obj instanceof \Twig_TemplateInterface || $obj instanceof Markup) {
92
+ return;
93
+ }
94
+
95
+ $allowed = false;
96
+ $method = strtolower($method);
97
+ foreach ($this->allowedMethods as $class => $methods) {
98
+ if ($obj instanceof $class) {
99
+ $allowed = \in_array($method, $methods);
100
+
101
+ break;
102
+ }
103
+ }
104
+
105
+ if (!$allowed) {
106
+ $class = \get_class($obj);
107
+ throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method);
108
+ }
109
+ }
110
+
111
+ public function checkPropertyAllowed($obj, $property)
112
+ {
113
+ $allowed = false;
114
+ foreach ($this->allowedProperties as $class => $properties) {
115
+ if ($obj instanceof $class) {
116
+ $allowed = \in_array($property, \is_array($properties) ? $properties : [$properties]);
117
+
118
+ break;
119
+ }
120
+ }
121
+
122
+ if (!$allowed) {
123
+ $class = \get_class($obj);
124
+ throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property);
125
+ }
126
+ }
127
+ }
128
+
129
+ class_alias('Twig\Sandbox\SecurityPolicy', 'Twig_Sandbox_SecurityPolicy');
vendor/twig/twig/src/Sandbox/SecurityPolicyInterface.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Sandbox;
13
+
14
+ /**
15
+ * Interface that all security policy classes must implements.
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ interface SecurityPolicyInterface
20
+ {
21
+ public function checkSecurity($tags, $filters, $functions);
22
+
23
+ public function checkMethodAllowed($obj, $method);
24
+
25
+ public function checkPropertyAllowed($obj, $method);
26
+ }
27
+
28
+ class_alias('Twig\Sandbox\SecurityPolicyInterface', 'Twig_Sandbox_SecurityPolicyInterface');
vendor/twig/twig/src/Source.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig;
13
+
14
+ /**
15
+ * Holds information about a non-compiled Twig template.
16
+ *
17
+ * @final
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ class Source
22
+ {
23
+ private $code;
24
+ private $name;
25
+ private $path;
26
+
27
+ /**
28
+ * @param string $code The template source code
29
+ * @param string $name The template logical name
30
+ * @param string $path The filesystem path of the template if any
31
+ */
32
+ public function __construct($code, $name, $path = '')
33
+ {
34
+ $this->code = $code;
35
+ $this->name = $name;
36
+ $this->path = $path;
37
+ }
38
+
39
+ public function getCode()
40
+ {
41
+ return $this->code;
42
+ }
43
+
44
+ public function getName()
45
+ {
46
+ return $this->name;
47
+ }
48
+
49
+ public function getPath()
50
+ {
51
+ return $this->path;
52
+ }
53
+ }
54
+
55
+ class_alias('Twig\Source', 'Twig_Source');
vendor/twig/twig/src/Template.php ADDED
@@ -0,0 +1,733 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig;
14
+
15
+ use Twig\Error\Error;
16
+ use Twig\Error\LoaderError;
17
+ use Twig\Error\RuntimeError;
18
+
19
+ /**
20
+ * Default base class for compiled templates.
21
+ *
22
+ * This class is an implementation detail of how template compilation currently
23
+ * works, which might change. It should never be used directly. Use $twig->load()
24
+ * instead, which returns an instance of \Twig\TemplateWrapper.
25
+ *
26
+ * @author Fabien Potencier <fabien@symfony.com>
27
+ *
28
+ * @internal
29
+ */
30
+ abstract class Template implements \Twig_TemplateInterface
31
+ {
32
+ /**
33
+ * @internal
34
+ */
35
+ protected static $cache = [];
36
+
37
+ protected $parent;
38
+ protected $parents = [];
39
+ protected $env;
40
+ protected $blocks = [];
41
+ protected $traits = [];
42
+ protected $sandbox;
43
+
44
+ public function __construct(Environment $env)
45
+ {
46
+ $this->env = $env;
47
+ }
48
+
49
+ /**
50
+ * @internal this method will be removed in 2.0 and is only used internally to provide an upgrade path from 1.x to 2.0
51
+ */
52
+ public function __toString()
53
+ {
54
+ return $this->getTemplateName();
55
+ }
56
+
57
+ /**
58
+ * Returns the template name.
59
+ *
60
+ * @return string The template name
61
+ */
62
+ abstract public function getTemplateName();
63
+
64
+ /**
65
+ * Returns debug information about the template.
66
+ *
67
+ * @return array Debug information
68
+ */
69
+ public function getDebugInfo()
70
+ {
71
+ return [];
72
+ }
73
+
74
+ /**
75
+ * Returns the template source code.
76
+ *
77
+ * @return string The template source code
78
+ *
79
+ * @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead
80
+ */
81
+ public function getSource()
82
+ {
83
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);
84
+
85
+ return '';
86
+ }
87
+
88
+ /**
89
+ * Returns information about the original template source code.
90
+ *
91
+ * @return Source
92
+ */
93
+ public function getSourceContext()
94
+ {
95
+ return new Source('', $this->getTemplateName());
96
+ }
97
+
98
+ /**
99
+ * @deprecated since 1.20 (to be removed in 2.0)
100
+ */
101
+ public function getEnvironment()
102
+ {
103
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.', E_USER_DEPRECATED);
104
+
105
+ return $this->env;
106
+ }
107
+
108
+ /**
109
+ * Returns the parent template.
110
+ *
111
+ * This method is for internal use only and should never be called
112
+ * directly.
113
+ *
114
+ * @param array $context
115
+ *
116
+ * @return \Twig_TemplateInterface|TemplateWrapper|false The parent template or false if there is no parent
117
+ *
118
+ * @internal
119
+ */
120
+ public function getParent(array $context)
121
+ {
122
+ if (null !== $this->parent) {
123
+ return $this->parent;
124
+ }
125
+
126
+ try {
127
+ $parent = $this->doGetParent($context);
128
+
129
+ if (false === $parent) {
130
+ return false;
131
+ }
132
+
133
+ if ($parent instanceof self || $parent instanceof TemplateWrapper) {
134
+ return $this->parents[$parent->getSourceContext()->getName()] = $parent;
135
+ }
136
+
137
+ if (!isset($this->parents[$parent])) {
138
+ $this->parents[$parent] = $this->loadTemplate($parent);
139
+ }
140
+ } catch (LoaderError $e) {
141
+ $e->setSourceContext(null);
142
+ $e->guess();
143
+
144
+ throw $e;
145
+ }
146
+
147
+ return $this->parents[$parent];
148
+ }
149
+
150
+ protected function doGetParent(array $context)
151
+ {
152
+ return false;
153
+ }
154
+
155
+ public function isTraitable()
156
+ {
157
+ return true;
158
+ }
159
+
160
+ /**
161
+ * Displays a parent block.
162
+ *
163
+ * This method is for internal use only and should never be called
164
+ * directly.
165
+ *
166
+ * @param string $name The block name to display from the parent
167
+ * @param array $context The context
168
+ * @param array $blocks The current set of blocks
169
+ */
170
+ public function displayParentBlock($name, array $context, array $blocks = [])
171
+ {
172
+ $name = (string) $name;
173
+
174
+ if (isset($this->traits[$name])) {
175
+ $this->traits[$name][0]->displayBlock($name, $context, $blocks, false);
176
+ } elseif (false !== $parent = $this->getParent($context)) {
177
+ $parent->displayBlock($name, $context, $blocks, false);
178
+ } else {
179
+ throw new RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext());
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Displays a block.
185
+ *
186
+ * This method is for internal use only and should never be called
187
+ * directly.
188
+ *
189
+ * @param string $name The block name to display
190
+ * @param array $context The context
191
+ * @param array $blocks The current set of blocks
192
+ * @param bool $useBlocks Whether to use the current set of blocks
193
+ */
194
+ public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true)
195
+ {
196
+ $name = (string) $name;
197
+
198
+ if ($useBlocks && isset($blocks[$name])) {
199
+ $template = $blocks[$name][0];
200
+ $block = $blocks[$name][1];
201
+ } elseif (isset($this->blocks[$name])) {
202
+ $template = $this->blocks[$name][0];
203
+ $block = $this->blocks[$name][1];
204
+ } else {
205
+ $template = null;
206
+ $block = null;
207
+ }
208
+
209
+ // avoid RCEs when sandbox is enabled
210
+ if (null !== $template && !$template instanceof self) {
211
+ throw new \LogicException('A block must be a method on a \Twig\Template instance.');
212
+ }
213
+
214
+ if (null !== $template) {
215
+ try {
216
+ $template->$block($context, $blocks);
217
+ } catch (Error $e) {
218
+ if (!$e->getSourceContext()) {
219
+ $e->setSourceContext($template->getSourceContext());
220
+ }
221
+
222
+ // this is mostly useful for \Twig\Error\LoaderError exceptions
223
+ // see \Twig\Error\LoaderError
224
+ if (-1 === $e->getTemplateLine()) {
225
+ $e->guess();
226
+ }
227
+
228
+ throw $e;
229
+ } catch (\Exception $e) {
230
+ $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e);
231
+ $e->guess();
232
+
233
+ throw $e;
234
+ }
235
+ } elseif (false !== $parent = $this->getParent($context)) {
236
+ $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false);
237
+ } else {
238
+ @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), E_USER_DEPRECATED);
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Renders a parent block.
244
+ *
245
+ * This method is for internal use only and should never be called
246
+ * directly.
247
+ *
248
+ * @param string $name The block name to render from the parent
249
+ * @param array $context The context
250
+ * @param array $blocks The current set of blocks
251
+ *
252
+ * @return string The rendered block
253
+ */
254
+ public function renderParentBlock($name, array $context, array $blocks = [])
255
+ {
256
+ if ($this->env->isDebug()) {
257
+ ob_start();
258
+ } else {
259
+ ob_start(function () { return ''; });
260
+ }
261
+ $this->displayParentBlock($name, $context, $blocks);
262
+
263
+ return ob_get_clean();
264
+ }
265
+
266
+ /**
267
+ * Renders a block.
268
+ *
269
+ * This method is for internal use only and should never be called
270
+ * directly.
271
+ *
272
+ * @param string $name The block name to render
273
+ * @param array $context The context
274
+ * @param array $blocks The current set of blocks
275
+ * @param bool $useBlocks Whether to use the current set of blocks
276
+ *
277
+ * @return string The rendered block
278
+ */
279
+ public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true)
280
+ {
281
+ if ($this->env->isDebug()) {
282
+ ob_start();
283
+ } else {
284
+ ob_start(function () { return ''; });
285
+ }
286
+ $this->displayBlock($name, $context, $blocks, $useBlocks);
287
+
288
+ return ob_get_clean();
289
+ }
290
+
291
+ /**
292
+ * Returns whether a block exists or not in the current context of the template.
293
+ *
294
+ * This method checks blocks defined in the current template
295
+ * or defined in "used" traits or defined in parent templates.
296
+ *
297
+ * @param string $name The block name
298
+ * @param array $context The context
299
+ * @param array $blocks The current set of blocks
300
+ *
301
+ * @return bool true if the block exists, false otherwise
302
+ */
303
+ public function hasBlock($name, array $context = null, array $blocks = [])
304
+ {
305
+ if (null === $context) {
306
+ @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED);
307
+
308
+ return isset($this->blocks[(string) $name]);
309
+ }
310
+
311
+ if (isset($blocks[$name])) {
312
+ return $blocks[$name][0] instanceof self;
313
+ }
314
+
315
+ if (isset($this->blocks[$name])) {
316
+ return true;
317
+ }
318
+
319
+ if (false !== $parent = $this->getParent($context)) {
320
+ return $parent->hasBlock($name, $context);
321
+ }
322
+
323
+ return false;
324
+ }
325
+
326
+ /**
327
+ * Returns all block names in the current context of the template.
328
+ *
329
+ * This method checks blocks defined in the current template
330
+ * or defined in "used" traits or defined in parent templates.
331
+ *
332
+ * @param array $context The context
333
+ * @param array $blocks The current set of blocks
334
+ *
335
+ * @return array An array of block names
336
+ */
337
+ public function getBlockNames(array $context = null, array $blocks = [])
338
+ {
339
+ if (null === $context) {
340
+ @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED);
341
+
342
+ return array_keys($this->blocks);
343
+ }
344
+
345
+ $names = array_merge(array_keys($blocks), array_keys($this->blocks));
346
+
347
+ if (false !== $parent = $this->getParent($context)) {
348
+ $names = array_merge($names, $parent->getBlockNames($context));
349
+ }
350
+
351
+ return array_unique($names);
352
+ }
353
+
354
+ /**
355
+ * @return Template|TemplateWrapper
356
+ */
357
+ protected function loadTemplate($template, $templateName = null, $line = null, $index = null)
358
+ {
359
+ try {
360
+ if (\is_array($template)) {
361
+ return $this->env->resolveTemplate($template);
362
+ }
363
+
364
+ if ($template instanceof self || $template instanceof TemplateWrapper) {
365
+ return $template;
366
+ }
367
+
368
+ if ($template === $this->getTemplateName()) {
369
+ $class = \get_class($this);
370
+ if (false !== $pos = strrpos($class, '___', -1)) {
371
+ $class = substr($class, 0, $pos);
372
+ }
373
+
374
+ return $this->env->loadClass($class, $template, $index);
375
+ }
376
+
377
+ return $this->env->loadTemplate($template, $index);
378
+ } catch (Error $e) {
379
+ if (!$e->getSourceContext()) {
380
+ $e->setSourceContext($templateName ? new Source('', $templateName) : $this->getSourceContext());
381
+ }
382
+
383
+ if ($e->getTemplateLine() > 0) {
384
+ throw $e;
385
+ }
386
+
387
+ if (!$line) {
388
+ $e->guess();
389
+ } else {
390
+ $e->setTemplateLine($line);
391
+ }
392
+
393
+ throw $e;
394
+ }
395
+ }
396
+
397
+ /**
398
+ * @internal
399
+ *
400
+ * @return Template
401
+ */
402
+ protected function unwrap()
403
+ {
404
+ return $this;
405
+ }
406
+
407
+ /**
408
+ * Returns all blocks.
409
+ *
410
+ * This method is for internal use only and should never be called
411
+ * directly.
412
+ *
413
+ * @return array An array of blocks
414
+ */
415
+ public function getBlocks()
416
+ {
417
+ return $this->blocks;
418
+ }
419
+
420
+ public function display(array $context, array $blocks = [])
421
+ {
422
+ $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
423
+ }
424
+
425
+ public function render(array $context)
426
+ {
427
+ $level = ob_get_level();
428
+ if ($this->env->isDebug()) {
429
+ ob_start();
430
+ } else {
431
+ ob_start(function () { return ''; });
432
+ }
433
+ try {
434
+ $this->display($context);
435
+ } catch (\Exception $e) {
436
+ while (ob_get_level() > $level) {
437
+ ob_end_clean();
438
+ }
439
+
440
+ throw $e;
441
+ } catch (\Throwable $e) {
442
+ while (ob_get_level() > $level) {
443
+ ob_end_clean();
444
+ }
445
+
446
+ throw $e;
447
+ }
448
+
449
+ return ob_get_clean();
450
+ }
451
+
452
+ protected function displayWithErrorHandling(array $context, array $blocks = [])
453
+ {
454
+ try {
455
+ $this->doDisplay($context, $blocks);
456
+ } catch (Error $e) {
457
+ if (!$e->getSourceContext()) {
458
+ $e->setSourceContext($this->getSourceContext());
459
+ }
460
+
461
+ // this is mostly useful for \Twig\Error\LoaderError exceptions
462
+ // see \Twig\Error\LoaderError
463
+ if (-1 === $e->getTemplateLine()) {
464
+ $e->guess();
465
+ }
466
+
467
+ throw $e;
468
+ } catch (\Exception $e) {
469
+ $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
470
+ $e->guess();
471
+
472
+ throw $e;
473
+ }
474
+ }
475
+
476
+ /**
477
+ * Auto-generated method to display the template with the given context.
478
+ *
479
+ * @param array $context An array of parameters to pass to the template
480
+ * @param array $blocks An array of blocks to pass to the template
481
+ */
482
+ abstract protected function doDisplay(array $context, array $blocks = []);
483
+
484
+ /**
485
+ * Returns a variable from the context.
486
+ *
487
+ * This method is for internal use only and should never be called
488
+ * directly.
489
+ *
490
+ * This method should not be overridden in a sub-class as this is an
491
+ * implementation detail that has been introduced to optimize variable
492
+ * access for versions of PHP before 5.4. This is not a way to override
493
+ * the way to get a variable value.
494
+ *
495
+ * @param array $context The context
496
+ * @param string $item The variable to return from the context
497
+ * @param bool $ignoreStrictCheck Whether to ignore the strict variable check or not
498
+ *
499
+ * @return mixed The content of the context variable
500
+ *
501
+ * @throws RuntimeError if the variable does not exist and Twig is running in strict mode
502
+ *
503
+ * @internal
504
+ */
505
+ final protected function getContext($context, $item, $ignoreStrictCheck = false)
506
+ {
507
+ if (!\array_key_exists($item, $context)) {
508
+ if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
509
+ return;
510
+ }
511
+
512
+ throw new RuntimeError(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext());
513
+ }
514
+
515
+ return $context[$item];
516
+ }
517
+
518
+ /**
519
+ * Returns the attribute value for a given array/object.
520
+ *
521
+ * @param mixed $object The object or array from where to get the item
522
+ * @param mixed $item The item to get from the array or object
523
+ * @param array $arguments An array of arguments to pass if the item is an object method
524
+ * @param string $type The type of attribute (@see \Twig\Template constants)
525
+ * @param bool $isDefinedTest Whether this is only a defined check
526
+ * @param bool $ignoreStrictCheck Whether to ignore the strict attribute check or not
527
+ *
528
+ * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true
529
+ *
530
+ * @throws RuntimeError if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false
531
+ *
532
+ * @internal
533
+ */
534
+ protected function getAttribute($object, $item, array $arguments = [], $type = self::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
535
+ {
536
+ // array
537
+ if (self::METHOD_CALL !== $type) {
538
+ $arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item;
539
+
540
+ if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, $object)))
541
+ || ($object instanceof \ArrayAccess && isset($object[$arrayItem]))
542
+ ) {
543
+ if ($isDefinedTest) {
544
+ return true;
545
+ }
546
+
547
+ return $object[$arrayItem];
548
+ }
549
+
550
+ if (self::ARRAY_CALL === $type || !\is_object($object)) {
551
+ if ($isDefinedTest) {
552
+ return false;
553
+ }
554
+
555
+ if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
556
+ return;
557
+ }
558
+
559
+ if ($object instanceof \ArrayAccess) {
560
+ $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object));
561
+ } elseif (\is_object($object)) {
562
+ $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object));
563
+ } elseif (\is_array($object)) {
564
+ if (empty($object)) {
565
+ $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem);
566
+ } else {
567
+ $message = sprintf('Key "%s" for array with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object)));
568
+ }
569
+ } elseif (self::ARRAY_CALL === $type) {
570
+ if (null === $object) {
571
+ $message = sprintf('Impossible to access a key ("%s") on a null variable.', $item);
572
+ } else {
573
+ $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, \gettype($object), $object);
574
+ }
575
+ } elseif (null === $object) {
576
+ $message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item);
577
+ } else {
578
+ $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, \gettype($object), $object);
579
+ }
580
+
581
+ throw new RuntimeError($message, -1, $this->getSourceContext());
582
+ }
583
+ }
584
+
585
+ if (!\is_object($object)) {
586
+ if ($isDefinedTest) {
587
+ return false;
588
+ }
589
+
590
+ if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
591
+ return;
592
+ }
593
+
594
+ if (null === $object) {
595
+ $message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item);
596
+ } elseif (\is_array($object)) {
597
+ $message = sprintf('Impossible to invoke a method ("%s") on an array.', $item);
598
+ } else {
599
+ $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, \gettype($object), $object);
600
+ }
601
+
602
+ throw new RuntimeError($message, -1, $this->getSourceContext());
603
+ }
604
+
605
+ // object property
606
+ if (self::METHOD_CALL !== $type && !$object instanceof self) { // \Twig\Template does not have public properties, and we don't want to allow access to internal ones
607
+ if (isset($object->$item) || \array_key_exists((string) $item, $object)) {
608
+ if ($isDefinedTest) {
609
+ return true;
610
+ }
611
+
612
+ if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) {
613
+ $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkPropertyAllowed($object, $item);
614
+ }
615
+
616
+ return $object->$item;
617
+ }
618
+ }
619
+
620
+ $class = \get_class($object);
621
+
622
+ // object method
623
+ if (!isset(self::$cache[$class])) {
624
+ // get_class_methods returns all methods accessible in the scope, but we only want public ones to be accessible in templates
625
+ if ($object instanceof self) {
626
+ $ref = new \ReflectionClass($class);
627
+ $methods = [];
628
+
629
+ foreach ($ref->getMethods(\ReflectionMethod::IS_PUBLIC) as $refMethod) {
630
+ // Accessing the environment from templates is forbidden to prevent untrusted changes to the environment
631
+ if ('getenvironment' !== strtolower($refMethod->name)) {
632
+ $methods[] = $refMethod->name;
633
+ }
634
+ }
635
+ } else {
636
+ $methods = get_class_methods($object);
637
+ }
638
+ // sort values to have consistent behavior, so that "get" methods win precedence over "is" methods
639
+ sort($methods);
640
+
641
+ $cache = [];
642
+
643
+ foreach ($methods as $method) {
644
+ $cache[$method] = $method;
645
+ $cache[$lcName = strtolower($method)] = $method;
646
+
647
+ if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) {
648
+ $name = substr($method, 3);
649
+ $lcName = substr($lcName, 3);
650
+ } elseif ('i' === $lcName[0] && 0 === strpos($lcName, 'is')) {
651
+ $name = substr($method, 2);
652
+ $lcName = substr($lcName, 2);
653
+ } else {
654
+ continue;
655
+ }
656
+
657
+ // skip get() and is() methods (in which case, $name is empty)
658
+ if ($name) {
659
+ if (!isset($cache[$name])) {
660
+ $cache[$name] = $method;
661
+ }
662
+ if (!isset($cache[$lcName])) {
663
+ $cache[$lcName] = $method;
664
+ }
665
+ }
666
+ }
667
+ self::$cache[$class] = $cache;
668
+ }
669
+
670
+ $call = false;
671
+ if (isset(self::$cache[$class][$item])) {
672
+ $method = self::$cache[$class][$item];
673
+ } elseif (isset(self::$cache[$class][$lcItem = strtolower($item)])) {
674
+ $method = self::$cache[$class][$lcItem];
675
+ } elseif (isset(self::$cache[$class]['__call'])) {
676
+ $method = $item;
677
+ $call = true;
678
+ } else {
679
+ if ($isDefinedTest) {
680
+ return false;
681
+ }
682
+
683
+ if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
684
+ return;
685
+ }
686
+
687
+ throw new RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext());
688
+ }
689
+
690
+ if ($isDefinedTest) {
691
+ return true;
692
+ }
693
+
694
+ if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) {
695
+ $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkMethodAllowed($object, $method);
696
+ }
697
+
698
+ // Some objects throw exceptions when they have __call, and the method we try
699
+ // to call is not supported. If ignoreStrictCheck is true, we should return null.
700
+ try {
701
+ if (!$arguments) {
702
+ $ret = $object->$method();
703
+ } else {
704
+ $ret = \call_user_func_array([$object, $method], $arguments);
705
+ }
706
+ } catch (\BadMethodCallException $e) {
707
+ if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
708
+ return;
709
+ }
710
+ throw $e;
711
+ }
712
+
713
+ // @deprecated in 1.28
714
+ if ($object instanceof \Twig_TemplateInterface) {
715
+ $self = $object->getTemplateName() === $this->getTemplateName();
716
+ $message = sprintf('Calling "%s" on template "%s" from template "%s" is deprecated since version 1.28 and won\'t be supported anymore in 2.0.', $item, $object->getTemplateName(), $this->getTemplateName());
717
+ if ('renderBlock' === $method || 'displayBlock' === $method) {
718
+ $message .= sprintf(' Use block("%s"%s) instead).', $arguments[0], $self ? '' : ', template');
719
+ } elseif ('hasBlock' === $method) {
720
+ $message .= sprintf(' Use "block("%s"%s) is defined" instead).', $arguments[0], $self ? '' : ', template');
721
+ } elseif ('render' === $method || 'display' === $method) {
722
+ $message .= sprintf(' Use include("%s") instead).', $object->getTemplateName());
723
+ }
724
+ @trigger_error($message, E_USER_DEPRECATED);
725
+
726
+ return '' === $ret ? '' : new Markup($ret, $this->env->getCharset());
727
+ }
728
+
729
+ return $ret;
730
+ }
731
+ }
732
+
733
+ class_alias('Twig\Template', 'Twig_Template');
vendor/twig/twig/src/TemplateWrapper.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig;
13
+
14
+ /**
15
+ * Exposes a template to userland.
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ */
19
+ final class TemplateWrapper
20
+ {
21
+ private $env;
22
+ private $template;
23
+
24
+ /**
25
+ * This method is for internal use only and should never be called
26
+ * directly (use Twig\Environment::load() instead).
27
+ *
28
+ * @internal
29
+ */
30
+ public function __construct(Environment $env, Template $template)
31
+ {
32
+ $this->env = $env;
33
+ $this->template = $template;
34
+ }
35
+
36
+ /**
37
+ * Renders the template.
38
+ *
39
+ * @param array $context An array of parameters to pass to the template
40
+ *
41
+ * @return string The rendered template
42
+ */
43
+ public function render($context = [])
44
+ {
45
+ // using func_get_args() allows to not expose the blocks argument
46
+ // as it should only be used by internal code
47
+ return $this->template->render($context, \func_num_args() > 1 ? func_get_arg(1) : []);
48
+ }
49
+
50
+ /**
51
+ * Displays the template.
52
+ *
53
+ * @param array $context An array of parameters to pass to the template
54
+ */
55
+ public function display($context = [])
56
+ {
57
+ // using func_get_args() allows to not expose the blocks argument
58
+ // as it should only be used by internal code
59
+ $this->template->display($context, \func_num_args() > 1 ? func_get_arg(1) : []);
60
+ }
61
+
62
+ /**
63
+ * Checks if a block is defined.
64
+ *
65
+ * @param string $name The block name
66
+ * @param array $context An array of parameters to pass to the template
67
+ *
68
+ * @return bool
69
+ */
70
+ public function hasBlock($name, $context = [])
71
+ {
72
+ return $this->template->hasBlock($name, $context);
73
+ }
74
+
75
+ /**
76
+ * Returns defined block names in the template.
77
+ *
78
+ * @param array $context An array of parameters to pass to the template
79
+ *
80
+ * @return string[] An array of defined template block names
81
+ */
82
+ public function getBlockNames($context = [])
83
+ {
84
+ return $this->template->getBlockNames($context);
85
+ }
86
+
87
+ /**
88
+ * Renders a template block.
89
+ *
90
+ * @param string $name The block name to render
91
+ * @param array $context An array of parameters to pass to the template
92
+ *
93
+ * @return string The rendered block
94
+ */
95
+ public function renderBlock($name, $context = [])
96
+ {
97
+ $context = $this->env->mergeGlobals($context);
98
+ $level = ob_get_level();
99
+ if ($this->env->isDebug()) {
100
+ ob_start();
101
+ } else {
102
+ ob_start(function () { return ''; });
103
+ }
104
+ try {
105
+ $this->template->displayBlock($name, $context);
106
+ } catch (\Exception $e) {
107
+ while (ob_get_level() > $level) {
108
+ ob_end_clean();
109
+ }
110
+
111
+ throw $e;
112
+ } catch (\Throwable $e) {
113
+ while (ob_get_level() > $level) {
114
+ ob_end_clean();
115
+ }
116
+
117
+ throw $e;
118
+ }
119
+
120
+ return ob_get_clean();
121
+ }
122
+
123
+ /**
124
+ * Displays a template block.
125
+ *
126
+ * @param string $name The block name to render
127
+ * @param array $context An array of parameters to pass to the template
128
+ */
129
+ public function displayBlock($name, $context = [])
130
+ {
131
+ $this->template->displayBlock($name, $this->env->mergeGlobals($context));
132
+ }
133
+
134
+ /**
135
+ * @return Source
136
+ */
137
+ public function getSourceContext()
138
+ {
139
+ return $this->template->getSourceContext();
140
+ }
141
+
142
+ /**
143
+ * @return string
144
+ */
145
+ public function getTemplateName()
146
+ {
147
+ return $this->template->getTemplateName();
148
+ }
149
+
150
+ /**
151
+ * @internal
152
+ *
153
+ * @return Template
154
+ */
155
+ public function unwrap()
156
+ {
157
+ return $this->template;
158
+ }
159
+ }
160
+
161
+ class_alias('Twig\TemplateWrapper', 'Twig_TemplateWrapper');
vendor/twig/twig/src/Test/IntegrationTestCase.php ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Test;
13
+
14
+ use PHPUnit\Framework\TestCase;
15
+ use Twig\Environment;
16
+ use Twig\Error\Error;
17
+ use Twig\Extension\ExtensionInterface;
18
+ use Twig\Loader\ArrayLoader;
19
+ use Twig\Loader\SourceContextLoaderInterface;
20
+ use Twig\RuntimeLoader\RuntimeLoaderInterface;
21
+ use Twig\Source;
22
+ use Twig\TwigFilter;
23
+ use Twig\TwigFunction;
24
+ use Twig\TwigTest;
25
+
26
+ /**
27
+ * Integration test helper.
28
+ *
29
+ * @author Fabien Potencier <fabien@symfony.com>
30
+ * @author Karma Dordrak <drak@zikula.org>
31
+ */
32
+ abstract class IntegrationTestCase extends TestCase
33
+ {
34
+ /**
35
+ * @return string
36
+ */
37
+ abstract protected function getFixturesDir();
38
+
39
+ /**
40
+ * @return RuntimeLoaderInterface[]
41
+ */
42
+ protected function getRuntimeLoaders()
43
+ {
44
+ return [];
45
+ }
46
+
47
+ /**
48
+ * @return ExtensionInterface[]
49
+ */
50
+ protected function getExtensions()
51
+ {
52
+ return [];
53
+ }
54
+
55
+ /**
56
+ * @return TwigFilter[]
57
+ */
58
+ protected function getTwigFilters()
59
+ {
60
+ return [];
61
+ }
62
+
63
+ /**
64
+ * @return TwigFunction[]
65
+ */
66
+ protected function getTwigFunctions()
67
+ {
68
+ return [];
69
+ }
70
+
71
+ /**
72
+ * @return TwigTest[]
73
+ */
74
+ protected function getTwigTests()
75
+ {
76
+ return [];
77
+ }
78
+
79
+ /**
80
+ * @dataProvider getTests
81
+ */
82
+ public function testIntegration($file, $message, $condition, $templates, $exception, $outputs)
83
+ {
84
+ $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs);
85
+ }
86
+
87
+ /**
88
+ * @dataProvider getLegacyTests
89
+ * @group legacy
90
+ */
91
+ public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs)
92
+ {
93
+ $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs);
94
+ }
95
+
96
+ public function getTests($name, $legacyTests = false)
97
+ {
98
+ $fixturesDir = realpath($this->getFixturesDir());
99
+ $tests = [];
100
+
101
+ foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
102
+ if (!preg_match('/\.test$/', $file)) {
103
+ continue;
104
+ }
105
+
106
+ if ($legacyTests xor false !== strpos($file->getRealpath(), '.legacy.test')) {
107
+ continue;
108
+ }
109
+
110
+ $test = file_get_contents($file->getRealpath());
111
+
112
+ if (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) {
113
+ $message = $match[1];
114
+ $condition = $match[2];
115
+ $templates = self::parseTemplates($match[3]);
116
+ $exception = $match[5];
117
+ $outputs = [[null, $match[4], null, '']];
118
+ } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) {
119
+ $message = $match[1];
120
+ $condition = $match[2];
121
+ $templates = self::parseTemplates($match[3]);
122
+ $exception = false;
123
+ preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER);
124
+ } else {
125
+ throw new \InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file)));
126
+ }
127
+
128
+ $tests[] = [str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs];
129
+ }
130
+
131
+ if ($legacyTests && empty($tests)) {
132
+ // add a dummy test to avoid a PHPUnit message
133
+ return [['not', '-', '', [], '', []]];
134
+ }
135
+
136
+ return $tests;
137
+ }
138
+
139
+ public function getLegacyTests()
140
+ {
141
+ return $this->getTests('testLegacyIntegration', true);
142
+ }
143
+
144
+ protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs)
145
+ {
146
+ if (!$outputs) {
147
+ $this->markTestSkipped('no tests to run');
148
+ }
149
+
150
+ if ($condition) {
151
+ eval('$ret = '.$condition.';');
152
+ if (!$ret) {
153
+ $this->markTestSkipped($condition);
154
+ }
155
+ }
156
+
157
+ $loader = new ArrayLoader($templates);
158
+
159
+ foreach ($outputs as $i => $match) {
160
+ $config = array_merge([
161
+ 'cache' => false,
162
+ 'strict_variables' => true,
163
+ ], $match[2] ? eval($match[2].';') : []);
164
+ $twig = new Environment($loader, $config);
165
+ $twig->addGlobal('global', 'global');
166
+ foreach ($this->getRuntimeLoaders() as $runtimeLoader) {
167
+ $twig->addRuntimeLoader($runtimeLoader);
168
+ }
169
+
170
+ foreach ($this->getExtensions() as $extension) {
171
+ $twig->addExtension($extension);
172
+ }
173
+
174
+ foreach ($this->getTwigFilters() as $filter) {
175
+ $twig->addFilter($filter);
176
+ }
177
+
178
+ foreach ($this->getTwigTests() as $test) {
179
+ $twig->addTest($test);
180
+ }
181
+
182
+ foreach ($this->getTwigFunctions() as $function) {
183
+ $twig->addFunction($function);
184
+ }
185
+
186
+ $p = new \ReflectionProperty($twig, 'templateClassPrefix');
187
+ $p->setAccessible(true);
188
+ $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_');
189
+
190
+ try {
191
+ $template = $twig->load('index.twig');
192
+ } catch (\Exception $e) {
193
+ if (false !== $exception) {
194
+ $message = $e->getMessage();
195
+ $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message)));
196
+ $last = substr($message, \strlen($message) - 1);
197
+ $this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.');
198
+
199
+ return;
200
+ }
201
+
202
+ throw new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e);
203
+ }
204
+
205
+ try {
206
+ $output = trim($template->render(eval($match[1].';')), "\n ");
207
+ } catch (\Exception $e) {
208
+ if (false !== $exception) {
209
+ $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $e->getMessage())));
210
+
211
+ return;
212
+ }
213
+
214
+ $e = new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e);
215
+
216
+ $output = trim(sprintf('%s: %s', \get_class($e), $e->getMessage()));
217
+ }
218
+
219
+ if (false !== $exception) {
220
+ list($class) = explode(':', $exception);
221
+ $constraintClass = class_exists('PHPUnit\Framework\Constraint\Exception') ? 'PHPUnit\Framework\Constraint\Exception' : 'PHPUnit_Framework_Constraint_Exception';
222
+ $this->assertThat(null, new $constraintClass($class));
223
+ }
224
+
225
+ $expected = trim($match[3], "\n ");
226
+
227
+ if ($expected !== $output) {
228
+ printf("Compiled templates that failed on case %d:\n", $i + 1);
229
+
230
+ foreach (array_keys($templates) as $name) {
231
+ echo "Template: $name\n";
232
+ $loader = $twig->getLoader();
233
+ if (!$loader instanceof SourceContextLoaderInterface) {
234
+ $source = new Source($loader->getSource($name), $name);
235
+ } else {
236
+ $source = $loader->getSourceContext($name);
237
+ }
238
+ echo $twig->compile($twig->parse($twig->tokenize($source)));
239
+ }
240
+ }
241
+ $this->assertEquals($expected, $output, $message.' (in '.$file.')');
242
+ }
243
+ }
244
+
245
+ protected static function parseTemplates($test)
246
+ {
247
+ $templates = [];
248
+ preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER);
249
+ foreach ($matches as $match) {
250
+ $templates[($match[1] ? $match[1] : 'index.twig')] = $match[2];
251
+ }
252
+
253
+ return $templates;
254
+ }
255
+ }
256
+
257
+ class_alias('Twig\Test\IntegrationTestCase', 'Twig_Test_IntegrationTestCase');
vendor/twig/twig/src/Test/NodeTestCase.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Test;
13
+
14
+ use PHPUnit\Framework\TestCase;
15
+ use Twig\Compiler;
16
+ use Twig\Environment;
17
+ use Twig\Loader\ArrayLoader;
18
+ use Twig\Node\Node;
19
+
20
+ abstract class NodeTestCase extends TestCase
21
+ {
22
+ abstract public function getTests();
23
+
24
+ /**
25
+ * @dataProvider getTests
26
+ */
27
+ public function testCompile($node, $source, $environment = null, $isPattern = false)
28
+ {
29
+ $this->assertNodeCompilation($source, $node, $environment, $isPattern);
30
+ }
31
+
32
+ public function assertNodeCompilation($source, Node $node, Environment $environment = null, $isPattern = false)
33
+ {
34
+ $compiler = $this->getCompiler($environment);
35
+ $compiler->compile($node);
36
+
37
+ if ($isPattern) {
38
+ $this->assertStringMatchesFormat($source, trim($compiler->getSource()));
39
+ } else {
40
+ $this->assertEquals($source, trim($compiler->getSource()));
41
+ }
42
+ }
43
+
44
+ protected function getCompiler(Environment $environment = null)
45
+ {
46
+ return new Compiler(null === $environment ? $this->getEnvironment() : $environment);
47
+ }
48
+
49
+ protected function getEnvironment()
50
+ {
51
+ return new Environment(new ArrayLoader([]));
52
+ }
53
+
54
+ protected function getVariableGetter($name, $line = false)
55
+ {
56
+ $line = $line > 0 ? "// line {$line}\n" : '';
57
+
58
+ if (\PHP_VERSION_ID >= 70000) {
59
+ return sprintf('%s($context["%s"] ?? null)', $line, $name);
60
+ }
61
+
62
+ if (\PHP_VERSION_ID >= 50400) {
63
+ return sprintf('%s(isset($context["%s"]) ? $context["%s"] : null)', $line, $name, $name);
64
+ }
65
+
66
+ return sprintf('%s$this->getContext($context, "%s")', $line, $name);
67
+ }
68
+
69
+ protected function getAttributeGetter()
70
+ {
71
+ if (\function_exists('twig_template_get_attributes')) {
72
+ return 'twig_template_get_attributes($this, ';
73
+ }
74
+
75
+ return '$this->getAttribute(';
76
+ }
77
+ }
78
+
79
+ class_alias('Twig\Test\NodeTestCase', 'Twig_Test_NodeTestCase');
vendor/twig/twig/src/Token.php ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig;
14
+
15
+ /**
16
+ * Represents a Token.
17
+ *
18
+ * @author Fabien Potencier <fabien@symfony.com>
19
+ *
20
+ * @final
21
+ */
22
+ class Token
23
+ {
24
+ protected $value;
25
+ protected $type;
26
+ protected $lineno;
27
+
28
+ const EOF_TYPE = -1;
29
+ const TEXT_TYPE = 0;
30
+ const BLOCK_START_TYPE = 1;
31
+ const VAR_START_TYPE = 2;
32
+ const BLOCK_END_TYPE = 3;
33
+ const VAR_END_TYPE = 4;
34
+ const NAME_TYPE = 5;
35
+ const NUMBER_TYPE = 6;
36
+ const STRING_TYPE = 7;
37
+ const OPERATOR_TYPE = 8;
38
+ const PUNCTUATION_TYPE = 9;
39
+ const INTERPOLATION_START_TYPE = 10;
40
+ const INTERPOLATION_END_TYPE = 11;
41
+ const ARROW_TYPE = 12;
42
+
43
+ /**
44
+ * @param int $type The type of the token
45
+ * @param string $value The token value
46
+ * @param int $lineno The line position in the source
47
+ */
48
+ public function __construct($type, $value, $lineno)
49
+ {
50
+ $this->type = $type;
51
+ $this->value = $value;
52
+ $this->lineno = $lineno;
53
+ }
54
+
55
+ public function __toString()
56
+ {
57
+ return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value);
58
+ }
59
+
60
+ /**
61
+ * Tests the current token for a type and/or a value.
62
+ *
63
+ * Parameters may be:
64
+ * * just type
65
+ * * type and value (or array of possible values)
66
+ * * just value (or array of possible values) (NAME_TYPE is used as type)
67
+ *
68
+ * @param array|string|int $type The type to test
69
+ * @param array|string|null $values The token value
70
+ *
71
+ * @return bool
72
+ */
73
+ public function test($type, $values = null)
74
+ {
75
+ if (null === $values && !\is_int($type)) {
76
+ $values = $type;
77
+ $type = self::NAME_TYPE;
78
+ }
79
+
80
+ return ($this->type === $type) && (
81
+ null === $values ||
82
+ (\is_array($values) && \in_array($this->value, $values)) ||
83
+ $this->value == $values
84
+ );
85
+ }
86
+
87
+ /**
88
+ * @return int
89
+ */
90
+ public function getLine()
91
+ {
92
+ return $this->lineno;
93
+ }
94
+
95
+ /**
96
+ * @return int
97
+ */
98
+ public function getType()
99
+ {
100
+ return $this->type;
101
+ }
102
+
103
+ /**
104
+ * @return string
105
+ */
106
+ public function getValue()
107
+ {
108
+ return $this->value;
109
+ }
110
+
111
+ /**
112
+ * Returns the constant representation (internal) of a given type.
113
+ *
114
+ * @param int $type The type as an integer
115
+ * @param bool $short Whether to return a short representation or not
116
+ *
117
+ * @return string The string representation
118
+ */
119
+ public static function typeToString($type, $short = false)
120
+ {
121
+ switch ($type) {
122
+ case self::EOF_TYPE:
123
+ $name = 'EOF_TYPE';
124
+ break;
125
+ case self::TEXT_TYPE:
126
+ $name = 'TEXT_TYPE';
127
+ break;
128
+ case self::BLOCK_START_TYPE:
129
+ $name = 'BLOCK_START_TYPE';
130
+ break;
131
+ case self::VAR_START_TYPE:
132
+ $name = 'VAR_START_TYPE';
133
+ break;
134
+ case self::BLOCK_END_TYPE:
135
+ $name = 'BLOCK_END_TYPE';
136
+ break;
137
+ case self::VAR_END_TYPE:
138
+ $name = 'VAR_END_TYPE';
139
+ break;
140
+ case self::NAME_TYPE:
141
+ $name = 'NAME_TYPE';
142
+ break;
143
+ case self::NUMBER_TYPE:
144
+ $name = 'NUMBER_TYPE';
145
+ break;
146
+ case self::STRING_TYPE:
147
+ $name = 'STRING_TYPE';
148
+ break;
149
+ case self::OPERATOR_TYPE:
150
+ $name = 'OPERATOR_TYPE';
151
+ break;
152
+ case self::PUNCTUATION_TYPE:
153
+ $name = 'PUNCTUATION_TYPE';
154
+ break;
155
+ case self::INTERPOLATION_START_TYPE:
156
+ $name = 'INTERPOLATION_START_TYPE';
157
+ break;
158
+ case self::INTERPOLATION_END_TYPE:
159
+ $name = 'INTERPOLATION_END_TYPE';
160
+ break;
161
+ case self::ARROW_TYPE:
162
+ $name = 'ARROW_TYPE';
163
+ break;
164
+ default:
165
+ throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type));
166
+ }
167
+
168
+ return $short ? $name : 'Twig\Token::'.$name;
169
+ }
170
+
171
+ /**
172
+ * Returns the English representation of a given type.
173
+ *
174
+ * @param int $type The type as an integer
175
+ *
176
+ * @return string The string representation
177
+ */
178
+ public static function typeToEnglish($type)
179
+ {
180
+ switch ($type) {
181
+ case self::EOF_TYPE:
182
+ return 'end of template';
183
+ case self::TEXT_TYPE:
184
+ return 'text';
185
+ case self::BLOCK_START_TYPE:
186
+ return 'begin of statement block';
187
+ case self::VAR_START_TYPE:
188
+ return 'begin of print statement';
189
+ case self::BLOCK_END_TYPE:
190
+ return 'end of statement block';
191
+ case self::VAR_END_TYPE:
192
+ return 'end of print statement';
193
+ case self::NAME_TYPE:
194
+ return 'name';
195
+ case self::NUMBER_TYPE:
196
+ return 'number';
197
+ case self::STRING_TYPE:
198
+ return 'string';
199
+ case self::OPERATOR_TYPE:
200
+ return 'operator';
201
+ case self::PUNCTUATION_TYPE:
202
+ return 'punctuation';
203
+ case self::INTERPOLATION_START_TYPE:
204
+ return 'begin of string interpolation';
205
+ case self::INTERPOLATION_END_TYPE:
206
+ return 'end of string interpolation';
207
+ case self::ARROW_TYPE:
208
+ return 'arrow function';
209
+ default:
210
+ throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type));
211
+ }
212
+ }
213
+ }
214
+
215
+ class_alias('Twig\Token', 'Twig_Token');
vendor/twig/twig/src/TokenParser/AbstractTokenParser.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Parser;
15
+
16
+ /**
17
+ * Base class for all token parsers.
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ abstract class AbstractTokenParser implements TokenParserInterface
22
+ {
23
+ /**
24
+ * @var Parser
25
+ */
26
+ protected $parser;
27
+
28
+ public function setParser(Parser $parser)
29
+ {
30
+ $this->parser = $parser;
31
+ }
32
+ }
33
+
34
+ class_alias('Twig\TokenParser\AbstractTokenParser', 'Twig_TokenParser');
vendor/twig/twig/src/TokenParser/ApplyTokenParser.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Node\Expression\TempNameExpression;
15
+ use Twig\Node\Node;
16
+ use Twig\Node\PrintNode;
17
+ use Twig\Node\SetNode;
18
+ use Twig\Token;
19
+
20
+ /**
21
+ * Applies filters on a section of a template.
22
+ *
23
+ * {% apply upper %}
24
+ * This text becomes uppercase
25
+ * {% endapplys %}
26
+ */
27
+ final class ApplyTokenParser extends AbstractTokenParser
28
+ {
29
+ public function parse(Token $token)
30
+ {
31
+ $lineno = $token->getLine();
32
+ $name = $this->parser->getVarName();
33
+
34
+ $ref = new TempNameExpression($name, $lineno);
35
+ $ref->setAttribute('always_defined', true);
36
+
37
+ $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
38
+
39
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
40
+ $body = $this->parser->subparse([$this, 'decideApplyEnd'], true);
41
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
42
+
43
+ return new Node([
44
+ new SetNode(true, $ref, $body, $lineno, $this->getTag()),
45
+ new PrintNode($filter, $lineno, $this->getTag()),
46
+ ]);
47
+ }
48
+
49
+ public function decideApplyEnd(Token $token)
50
+ {
51
+ return $token->test('endapply');
52
+ }
53
+
54
+ public function getTag()
55
+ {
56
+ return 'apply';
57
+ }
58
+ }
vendor/twig/twig/src/TokenParser/AutoEscapeTokenParser.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Error\SyntaxError;
15
+ use Twig\Node\AutoEscapeNode;
16
+ use Twig\Node\Expression\ConstantExpression;
17
+ use Twig\Token;
18
+
19
+ /**
20
+ * Marks a section of a template to be escaped or not.
21
+ *
22
+ * {% autoescape true %}
23
+ * Everything will be automatically escaped in this block
24
+ * {% endautoescape %}
25
+ *
26
+ * {% autoescape false %}
27
+ * Everything will be outputed as is in this block
28
+ * {% endautoescape %}
29
+ *
30
+ * {% autoescape true js %}
31
+ * Everything will be automatically escaped in this block
32
+ * using the js escaping strategy
33
+ * {% endautoescape %}
34
+ *
35
+ * @final
36
+ */
37
+ class AutoEscapeTokenParser extends AbstractTokenParser
38
+ {
39
+ public function parse(Token $token)
40
+ {
41
+ $lineno = $token->getLine();
42
+ $stream = $this->parser->getStream();
43
+
44
+ if ($stream->test(Token::BLOCK_END_TYPE)) {
45
+ $value = 'html';
46
+ } else {
47
+ $expr = $this->parser->getExpressionParser()->parseExpression();
48
+ if (!$expr instanceof ConstantExpression) {
49
+ throw new SyntaxError('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
50
+ }
51
+ $value = $expr->getAttribute('value');
52
+
53
+ $compat = true === $value || false === $value;
54
+
55
+ if (true === $value) {
56
+ $value = 'html';
57
+ }
58
+
59
+ if ($compat && $stream->test(Token::NAME_TYPE)) {
60
+ @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED);
61
+
62
+ if (false === $value) {
63
+ throw new SyntaxError('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
64
+ }
65
+
66
+ $value = $stream->next()->getValue();
67
+ }
68
+ }
69
+
70
+ $stream->expect(Token::BLOCK_END_TYPE);
71
+ $body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
72
+ $stream->expect(Token::BLOCK_END_TYPE);
73
+
74
+ return new AutoEscapeNode($value, $body, $lineno, $this->getTag());
75
+ }
76
+
77
+ public function decideBlockEnd(Token $token)
78
+ {
79
+ return $token->test('endautoescape');
80
+ }
81
+
82
+ public function getTag()
83
+ {
84
+ return 'autoescape';
85
+ }
86
+ }
87
+
88
+ class_alias('Twig\TokenParser\AutoEscapeTokenParser', 'Twig_TokenParser_AutoEscape');
vendor/twig/twig/src/TokenParser/BlockTokenParser.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\TokenParser;
14
+
15
+ use Twig\Error\SyntaxError;
16
+ use Twig\Node\BlockNode;
17
+ use Twig\Node\BlockReferenceNode;
18
+ use Twig\Node\Node;
19
+ use Twig\Node\PrintNode;
20
+ use Twig\Token;
21
+
22
+ /**
23
+ * Marks a section of a template as being reusable.
24
+ *
25
+ * {% block head %}
26
+ * <link rel="stylesheet" href="style.css" />
27
+ * <title>{% block title %}{% endblock %} - My Webpage</title>
28
+ * {% endblock %}
29
+ *
30
+ * @final
31
+ */
32
+ class BlockTokenParser extends AbstractTokenParser
33
+ {
34
+ public function parse(Token $token)
35
+ {
36
+ $lineno = $token->getLine();
37
+ $stream = $this->parser->getStream();
38
+ $name = $stream->expect(Token::NAME_TYPE)->getValue();
39
+ if ($this->parser->hasBlock($name)) {
40
+ throw new SyntaxError(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext());
41
+ }
42
+ $this->parser->setBlock($name, $block = new BlockNode($name, new Node([]), $lineno));
43
+ $this->parser->pushLocalScope();
44
+ $this->parser->pushBlockStack($name);
45
+
46
+ if ($stream->nextIf(Token::BLOCK_END_TYPE)) {
47
+ $body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
48
+ if ($token = $stream->nextIf(Token::NAME_TYPE)) {
49
+ $value = $token->getValue();
50
+
51
+ if ($value != $name) {
52
+ throw new SyntaxError(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
53
+ }
54
+ }
55
+ } else {
56
+ $body = new Node([
57
+ new PrintNode($this->parser->getExpressionParser()->parseExpression(), $lineno),
58
+ ]);
59
+ }
60
+ $stream->expect(Token::BLOCK_END_TYPE);
61
+
62
+ $block->setNode('body', $body);
63
+ $this->parser->popBlockStack();
64
+ $this->parser->popLocalScope();
65
+
66
+ return new BlockReferenceNode($name, $lineno, $this->getTag());
67
+ }
68
+
69
+ public function decideBlockEnd(Token $token)
70
+ {
71
+ return $token->test('endblock');
72
+ }
73
+
74
+ public function getTag()
75
+ {
76
+ return 'block';
77
+ }
78
+ }
79
+
80
+ class_alias('Twig\TokenParser\BlockTokenParser', 'Twig_TokenParser_Block');
vendor/twig/twig/src/TokenParser/DeprecatedTokenParser.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Node\DeprecatedNode;
15
+ use Twig\Token;
16
+
17
+ /**
18
+ * Deprecates a section of a template.
19
+ *
20
+ * {% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' %}
21
+ * {% extends 'layout.html.twig' %}
22
+ *
23
+ * @author Yonel Ceruto <yonelceruto@gmail.com>
24
+ *
25
+ * @final
26
+ */
27
+ class DeprecatedTokenParser extends AbstractTokenParser
28
+ {
29
+ public function parse(Token $token)
30
+ {
31
+ $expr = $this->parser->getExpressionParser()->parseExpression();
32
+
33
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
34
+
35
+ return new DeprecatedNode($expr, $token->getLine(), $this->getTag());
36
+ }
37
+
38
+ public function getTag()
39
+ {
40
+ return 'deprecated';
41
+ }
42
+ }
43
+
44
+ class_alias('Twig\TokenParser\DeprecatedTokenParser', 'Twig_TokenParser_Deprecated');
vendor/twig/twig/src/TokenParser/DoTokenParser.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Node\DoNode;
15
+ use Twig\Token;
16
+
17
+ /**
18
+ * Evaluates an expression, discarding the returned value.
19
+ *
20
+ * @final
21
+ */
22
+ class DoTokenParser extends AbstractTokenParser
23
+ {
24
+ public function parse(Token $token)
25
+ {
26
+ $expr = $this->parser->getExpressionParser()->parseExpression();
27
+
28
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
29
+
30
+ return new DoNode($expr, $token->getLine(), $this->getTag());
31
+ }
32
+
33
+ public function getTag()
34
+ {
35
+ return 'do';
36
+ }
37
+ }
38
+
39
+ class_alias('Twig\TokenParser\DoTokenParser', 'Twig_TokenParser_Do');
vendor/twig/twig/src/TokenParser/EmbedTokenParser.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Node\EmbedNode;
15
+ use Twig\Node\Expression\ConstantExpression;
16
+ use Twig\Node\Expression\NameExpression;
17
+ use Twig\Token;
18
+
19
+ /**
20
+ * Embeds a template.
21
+ *
22
+ * @final
23
+ */
24
+ class EmbedTokenParser extends IncludeTokenParser
25
+ {
26
+ public function parse(Token $token)
27
+ {
28
+ $stream = $this->parser->getStream();
29
+
30
+ $parent = $this->parser->getExpressionParser()->parseExpression();
31
+
32
+ list($variables, $only, $ignoreMissing) = $this->parseArguments();
33
+
34
+ $parentToken = $fakeParentToken = new Token(Token::STRING_TYPE, '__parent__', $token->getLine());
35
+ if ($parent instanceof ConstantExpression) {
36
+ $parentToken = new Token(Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine());
37
+ } elseif ($parent instanceof NameExpression) {
38
+ $parentToken = new Token(Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine());
39
+ }
40
+
41
+ // inject a fake parent to make the parent() function work
42
+ $stream->injectTokens([
43
+ new Token(Token::BLOCK_START_TYPE, '', $token->getLine()),
44
+ new Token(Token::NAME_TYPE, 'extends', $token->getLine()),
45
+ $parentToken,
46
+ new Token(Token::BLOCK_END_TYPE, '', $token->getLine()),
47
+ ]);
48
+
49
+ $module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true);
50
+
51
+ // override the parent with the correct one
52
+ if ($fakeParentToken === $parentToken) {
53
+ $module->setNode('parent', $parent);
54
+ }
55
+
56
+ $this->parser->embedTemplate($module);
57
+
58
+ $stream->expect(Token::BLOCK_END_TYPE);
59
+
60
+ return new EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
61
+ }
62
+
63
+ public function decideBlockEnd(Token $token)
64
+ {
65
+ return $token->test('endembed');
66
+ }
67
+
68
+ public function getTag()
69
+ {
70
+ return 'embed';
71
+ }
72
+ }
73
+
74
+ class_alias('Twig\TokenParser\EmbedTokenParser', 'Twig_TokenParser_Embed');
vendor/twig/twig/src/TokenParser/ExtendsTokenParser.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\TokenParser;
14
+
15
+ use Twig\Error\SyntaxError;
16
+ use Twig\Node\Node;
17
+ use Twig\Token;
18
+
19
+ /**
20
+ * Extends a template by another one.
21
+ *
22
+ * {% extends "base.html" %}
23
+ *
24
+ * @final
25
+ */
26
+ class ExtendsTokenParser extends AbstractTokenParser
27
+ {
28
+ public function parse(Token $token)
29
+ {
30
+ $stream = $this->parser->getStream();
31
+
32
+ if ($this->parser->peekBlockStack()) {
33
+ throw new SyntaxError('Cannot use "extend" in a block.', $token->getLine(), $stream->getSourceContext());
34
+ } elseif (!$this->parser->isMainScope()) {
35
+ throw new SyntaxError('Cannot use "extend" in a macro.', $token->getLine(), $stream->getSourceContext());
36
+ }
37
+
38
+ if (null !== $this->parser->getParent()) {
39
+ throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext());
40
+ }
41
+ $this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
42
+
43
+ $stream->expect(Token::BLOCK_END_TYPE);
44
+
45
+ return new Node();
46
+ }
47
+
48
+ public function getTag()
49
+ {
50
+ return 'extends';
51
+ }
52
+ }
53
+
54
+ class_alias('Twig\TokenParser\ExtendsTokenParser', 'Twig_TokenParser_Extends');
vendor/twig/twig/src/TokenParser/FilterTokenParser.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Node\BlockNode;
15
+ use Twig\Node\Expression\BlockReferenceExpression;
16
+ use Twig\Node\Expression\ConstantExpression;
17
+ use Twig\Node\PrintNode;
18
+ use Twig\Token;
19
+
20
+ /**
21
+ * Filters a section of a template by applying filters.
22
+ *
23
+ * {% filter upper %}
24
+ * This text becomes uppercase
25
+ * {% endfilter %}
26
+ *
27
+ * @final
28
+ */
29
+ class FilterTokenParser extends AbstractTokenParser
30
+ {
31
+ public function parse(Token $token)
32
+ {
33
+ $name = $this->parser->getVarName();
34
+ $ref = new BlockReferenceExpression(new ConstantExpression($name, $token->getLine()), null, $token->getLine(), $this->getTag());
35
+
36
+ $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
37
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
38
+
39
+ $body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
40
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
41
+
42
+ $block = new BlockNode($name, $body, $token->getLine());
43
+ $this->parser->setBlock($name, $block);
44
+
45
+ return new PrintNode($filter, $token->getLine(), $this->getTag());
46
+ }
47
+
48
+ public function decideBlockEnd(Token $token)
49
+ {
50
+ return $token->test('endfilter');
51
+ }
52
+
53
+ public function getTag()
54
+ {
55
+ return 'filter';
56
+ }
57
+ }
58
+
59
+ class_alias('Twig\TokenParser\FilterTokenParser', 'Twig_TokenParser_Filter');
vendor/twig/twig/src/TokenParser/FlushTokenParser.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Node\FlushNode;
15
+ use Twig\Token;
16
+
17
+ /**
18
+ * Flushes the output to the client.
19
+ *
20
+ * @see flush()
21
+ *
22
+ * @final
23
+ */
24
+ class FlushTokenParser extends AbstractTokenParser
25
+ {
26
+ public function parse(Token $token)
27
+ {
28
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
29
+
30
+ return new FlushNode($token->getLine(), $this->getTag());
31
+ }
32
+
33
+ public function getTag()
34
+ {
35
+ return 'flush';
36
+ }
37
+ }
38
+
39
+ class_alias('Twig\TokenParser\FlushTokenParser', 'Twig_TokenParser_Flush');
vendor/twig/twig/src/TokenParser/ForTokenParser.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\TokenParser;
14
+
15
+ use Twig\Error\SyntaxError;
16
+ use Twig\Node\Expression\AssignNameExpression;
17
+ use Twig\Node\Expression\ConstantExpression;
18
+ use Twig\Node\Expression\GetAttrExpression;
19
+ use Twig\Node\Expression\NameExpression;
20
+ use Twig\Node\ForNode;
21
+ use Twig\Token;
22
+ use Twig\TokenStream;
23
+
24
+ /**
25
+ * Loops over each item of a sequence.
26
+ *
27
+ * <ul>
28
+ * {% for user in users %}
29
+ * <li>{{ user.username|e }}</li>
30
+ * {% endfor %}
31
+ * </ul>
32
+ *
33
+ * @final
34
+ */
35
+ class ForTokenParser extends AbstractTokenParser
36
+ {
37
+ public function parse(Token $token)
38
+ {
39
+ $lineno = $token->getLine();
40
+ $stream = $this->parser->getStream();
41
+ $targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
42
+ $stream->expect(Token::OPERATOR_TYPE, 'in');
43
+ $seq = $this->parser->getExpressionParser()->parseExpression();
44
+
45
+ $ifexpr = null;
46
+ if ($stream->nextIf(Token::NAME_TYPE, 'if')) {
47
+ $ifexpr = $this->parser->getExpressionParser()->parseExpression();
48
+ }
49
+
50
+ $stream->expect(Token::BLOCK_END_TYPE);
51
+ $body = $this->parser->subparse([$this, 'decideForFork']);
52
+ if ('else' == $stream->next()->getValue()) {
53
+ $stream->expect(Token::BLOCK_END_TYPE);
54
+ $else = $this->parser->subparse([$this, 'decideForEnd'], true);
55
+ } else {
56
+ $else = null;
57
+ }
58
+ $stream->expect(Token::BLOCK_END_TYPE);
59
+
60
+ if (\count($targets) > 1) {
61
+ $keyTarget = $targets->getNode(0);
62
+ $keyTarget = new AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine());
63
+ $valueTarget = $targets->getNode(1);
64
+ $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
65
+ } else {
66
+ $keyTarget = new AssignNameExpression('_key', $lineno);
67
+ $valueTarget = $targets->getNode(0);
68
+ $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
69
+ }
70
+
71
+ if ($ifexpr) {
72
+ $this->checkLoopUsageCondition($stream, $ifexpr);
73
+ $this->checkLoopUsageBody($stream, $body);
74
+ }
75
+
76
+ return new ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag());
77
+ }
78
+
79
+ public function decideForFork(Token $token)
80
+ {
81
+ return $token->test(['else', 'endfor']);
82
+ }
83
+
84
+ public function decideForEnd(Token $token)
85
+ {
86
+ return $token->test('endfor');
87
+ }
88
+
89
+ // the loop variable cannot be used in the condition
90
+ protected function checkLoopUsageCondition(TokenStream $stream, \Twig_NodeInterface $node)
91
+ {
92
+ if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) {
93
+ throw new SyntaxError('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext());
94
+ }
95
+
96
+ foreach ($node as $n) {
97
+ if (!$n) {
98
+ continue;
99
+ }
100
+
101
+ $this->checkLoopUsageCondition($stream, $n);
102
+ }
103
+ }
104
+
105
+ // check usage of non-defined loop-items
106
+ // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include)
107
+ protected function checkLoopUsageBody(TokenStream $stream, \Twig_NodeInterface $node)
108
+ {
109
+ if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) {
110
+ $attribute = $node->getNode('attribute');
111
+ if ($attribute instanceof ConstantExpression && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) {
112
+ throw new SyntaxError(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext());
113
+ }
114
+ }
115
+
116
+ // should check for parent.loop.XXX usage
117
+ if ($node instanceof ForNode) {
118
+ return;
119
+ }
120
+
121
+ foreach ($node as $n) {
122
+ if (!$n) {
123
+ continue;
124
+ }
125
+
126
+ $this->checkLoopUsageBody($stream, $n);
127
+ }
128
+ }
129
+
130
+ public function getTag()
131
+ {
132
+ return 'for';
133
+ }
134
+ }
135
+
136
+ class_alias('Twig\TokenParser\ForTokenParser', 'Twig_TokenParser_For');
vendor/twig/twig/src/TokenParser/FromTokenParser.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Error\SyntaxError;
15
+ use Twig\Node\Expression\AssignNameExpression;
16
+ use Twig\Node\ImportNode;
17
+ use Twig\Token;
18
+
19
+ /**
20
+ * Imports macros.
21
+ *
22
+ * {% from 'forms.html' import forms %}
23
+ *
24
+ * @final
25
+ */
26
+ class FromTokenParser extends AbstractTokenParser
27
+ {
28
+ public function parse(Token $token)
29
+ {
30
+ $macro = $this->parser->getExpressionParser()->parseExpression();
31
+ $stream = $this->parser->getStream();
32
+ $stream->expect(Token::NAME_TYPE, 'import');
33
+
34
+ $targets = [];
35
+ do {
36
+ $name = $stream->expect(Token::NAME_TYPE)->getValue();
37
+
38
+ $alias = $name;
39
+ if ($stream->nextIf('as')) {
40
+ $alias = $stream->expect(Token::NAME_TYPE)->getValue();
41
+ }
42
+
43
+ $targets[$name] = $alias;
44
+
45
+ if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
46
+ break;
47
+ }
48
+ } while (true);
49
+
50
+ $stream->expect(Token::BLOCK_END_TYPE);
51
+
52
+ $var = new AssignNameExpression($this->parser->getVarName(), $token->getLine());
53
+ $node = new ImportNode($macro, $var, $token->getLine(), $this->getTag());
54
+
55
+ foreach ($targets as $name => $alias) {
56
+ if ($this->parser->isReservedMacroName($name)) {
57
+ throw new SyntaxError(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
58
+ }
59
+
60
+ $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $var);
61
+ }
62
+
63
+ return $node;
64
+ }
65
+
66
+ public function getTag()
67
+ {
68
+ return 'from';
69
+ }
70
+ }
71
+
72
+ class_alias('Twig\TokenParser\FromTokenParser', 'Twig_TokenParser_From');
vendor/twig/twig/src/TokenParser/IfTokenParser.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\TokenParser;
14
+
15
+ use Twig\Error\SyntaxError;
16
+ use Twig\Node\IfNode;
17
+ use Twig\Node\Node;
18
+ use Twig\Token;
19
+
20
+ /**
21
+ * Tests a condition.
22
+ *
23
+ * {% if users %}
24
+ * <ul>
25
+ * {% for user in users %}
26
+ * <li>{{ user.username|e }}</li>
27
+ * {% endfor %}
28
+ * </ul>
29
+ * {% endif %}
30
+ *
31
+ * @final
32
+ */
33
+ class IfTokenParser extends AbstractTokenParser
34
+ {
35
+ public function parse(Token $token)
36
+ {
37
+ $lineno = $token->getLine();
38
+ $expr = $this->parser->getExpressionParser()->parseExpression();
39
+ $stream = $this->parser->getStream();
40
+ $stream->expect(Token::BLOCK_END_TYPE);
41
+ $body = $this->parser->subparse([$this, 'decideIfFork']);
42
+ $tests = [$expr, $body];
43
+ $else = null;
44
+
45
+ $end = false;
46
+ while (!$end) {
47
+ switch ($stream->next()->getValue()) {
48
+ case 'else':
49
+ $stream->expect(Token::BLOCK_END_TYPE);
50
+ $else = $this->parser->subparse([$this, 'decideIfEnd']);
51
+ break;
52
+
53
+ case 'elseif':
54
+ $expr = $this->parser->getExpressionParser()->parseExpression();
55
+ $stream->expect(Token::BLOCK_END_TYPE);
56
+ $body = $this->parser->subparse([$this, 'decideIfFork']);
57
+ $tests[] = $expr;
58
+ $tests[] = $body;
59
+ break;
60
+
61
+ case 'endif':
62
+ $end = true;
63
+ break;
64
+
65
+ default:
66
+ throw new SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext());
67
+ }
68
+ }
69
+
70
+ $stream->expect(Token::BLOCK_END_TYPE);
71
+
72
+ return new IfNode(new Node($tests), $else, $lineno, $this->getTag());
73
+ }
74
+
75
+ public function decideIfFork(Token $token)
76
+ {
77
+ return $token->test(['elseif', 'else', 'endif']);
78
+ }
79
+
80
+ public function decideIfEnd(Token $token)
81
+ {
82
+ return $token->test(['endif']);
83
+ }
84
+
85
+ public function getTag()
86
+ {
87
+ return 'if';
88
+ }
89
+ }
90
+
91
+ class_alias('Twig\TokenParser\IfTokenParser', 'Twig_TokenParser_If');
vendor/twig/twig/src/TokenParser/ImportTokenParser.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Node\Expression\AssignNameExpression;
15
+ use Twig\Node\ImportNode;
16
+ use Twig\Token;
17
+
18
+ /**
19
+ * Imports macros.
20
+ *
21
+ * {% import 'forms.html' as forms %}
22
+ *
23
+ * @final
24
+ */
25
+ class ImportTokenParser extends AbstractTokenParser
26
+ {
27
+ public function parse(Token $token)
28
+ {
29
+ $macro = $this->parser->getExpressionParser()->parseExpression();
30
+ $this->parser->getStream()->expect(Token::NAME_TYPE, 'as');
31
+ $var = new AssignNameExpression($this->parser->getStream()->expect(Token::NAME_TYPE)->getValue(), $token->getLine());
32
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
33
+
34
+ $this->parser->addImportedSymbol('template', $var->getAttribute('name'));
35
+
36
+ return new ImportNode($macro, $var, $token->getLine(), $this->getTag());
37
+ }
38
+
39
+ public function getTag()
40
+ {
41
+ return 'import';
42
+ }
43
+ }
44
+
45
+ class_alias('Twig\TokenParser\ImportTokenParser', 'Twig_TokenParser_Import');
vendor/twig/twig/src/TokenParser/IncludeTokenParser.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig\TokenParser;
14
+
15
+ use Twig\Node\IncludeNode;
16
+ use Twig\Token;
17
+
18
+ /**
19
+ * Includes a template.
20
+ *
21
+ * {% include 'header.html' %}
22
+ * Body
23
+ * {% include 'footer.html' %}
24
+ */
25
+ class IncludeTokenParser extends AbstractTokenParser
26
+ {
27
+ public function parse(Token $token)
28
+ {
29
+ $expr = $this->parser->getExpressionParser()->parseExpression();
30
+
31
+ list($variables, $only, $ignoreMissing) = $this->parseArguments();
32
+
33
+ return new IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
34
+ }
35
+
36
+ protected function parseArguments()
37
+ {
38
+ $stream = $this->parser->getStream();
39
+
40
+ $ignoreMissing = false;
41
+ if ($stream->nextIf(Token::NAME_TYPE, 'ignore')) {
42
+ $stream->expect(Token::NAME_TYPE, 'missing');
43
+
44
+ $ignoreMissing = true;
45
+ }
46
+
47
+ $variables = null;
48
+ if ($stream->nextIf(Token::NAME_TYPE, 'with')) {
49
+ $variables = $this->parser->getExpressionParser()->parseExpression();
50
+ }
51
+
52
+ $only = false;
53
+ if ($stream->nextIf(Token::NAME_TYPE, 'only')) {
54
+ $only = true;
55
+ }
56
+
57
+ $stream->expect(Token::BLOCK_END_TYPE);
58
+
59
+ return [$variables, $only, $ignoreMissing];
60
+ }
61
+
62
+ public function getTag()
63
+ {
64
+ return 'include';
65
+ }
66
+ }
67
+
68
+ class_alias('Twig\TokenParser\IncludeTokenParser', 'Twig_TokenParser_Include');
vendor/twig/twig/src/TokenParser/MacroTokenParser.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Error\SyntaxError;
15
+ use Twig\Node\BodyNode;
16
+ use Twig\Node\MacroNode;
17
+ use Twig\Node\Node;
18
+ use Twig\Token;
19
+
20
+ /**
21
+ * Defines a macro.
22
+ *
23
+ * {% macro input(name, value, type, size) %}
24
+ * <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
25
+ * {% endmacro %}
26
+ *
27
+ * @final
28
+ */
29
+ class MacroTokenParser extends AbstractTokenParser
30
+ {
31
+ public function parse(Token $token)
32
+ {
33
+ $lineno = $token->getLine();
34
+ $stream = $this->parser->getStream();
35
+ $name = $stream->expect(Token::NAME_TYPE)->getValue();
36
+
37
+ $arguments = $this->parser->getExpressionParser()->parseArguments(true, true);
38
+
39
+ $stream->expect(Token::BLOCK_END_TYPE);
40
+ $this->parser->pushLocalScope();
41
+ $body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
42
+ if ($token = $stream->nextIf(Token::NAME_TYPE)) {
43
+ $value = $token->getValue();
44
+
45
+ if ($value != $name) {
46
+ throw new SyntaxError(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
47
+ }
48
+ }
49
+ $this->parser->popLocalScope();
50
+ $stream->expect(Token::BLOCK_END_TYPE);
51
+
52
+ $this->parser->setMacro($name, new MacroNode($name, new BodyNode([$body]), $arguments, $lineno, $this->getTag()));
53
+
54
+ return new Node();
55
+ }
56
+
57
+ public function decideBlockEnd(Token $token)
58
+ {
59
+ return $token->test('endmacro');
60
+ }
61
+
62
+ public function getTag()
63
+ {
64
+ return 'macro';
65
+ }
66
+ }
67
+
68
+ class_alias('Twig\TokenParser\MacroTokenParser', 'Twig_TokenParser_Macro');
vendor/twig/twig/src/TokenParser/SandboxTokenParser.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Error\SyntaxError;
15
+ use Twig\Node\IncludeNode;
16
+ use Twig\Node\SandboxNode;
17
+ use Twig\Node\TextNode;
18
+ use Twig\Token;
19
+
20
+ /**
21
+ * Marks a section of a template as untrusted code that must be evaluated in the sandbox mode.
22
+ *
23
+ * {% sandbox %}
24
+ * {% include 'user.html' %}
25
+ * {% endsandbox %}
26
+ *
27
+ * @see https://twig.symfony.com/doc/api.html#sandbox-extension for details
28
+ *
29
+ * @final
30
+ */
31
+ class SandboxTokenParser extends AbstractTokenParser
32
+ {
33
+ public function parse(Token $token)
34
+ {
35
+ $stream = $this->parser->getStream();
36
+ $stream->expect(Token::BLOCK_END_TYPE);
37
+ $body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
38
+ $stream->expect(Token::BLOCK_END_TYPE);
39
+
40
+ // in a sandbox tag, only include tags are allowed
41
+ if (!$body instanceof IncludeNode) {
42
+ foreach ($body as $node) {
43
+ if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) {
44
+ continue;
45
+ }
46
+
47
+ if (!$node instanceof IncludeNode) {
48
+ throw new SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext());
49
+ }
50
+ }
51
+ }
52
+
53
+ return new SandboxNode($body, $token->getLine(), $this->getTag());
54
+ }
55
+
56
+ public function decideBlockEnd(Token $token)
57
+ {
58
+ return $token->test('endsandbox');
59
+ }
60
+
61
+ public function getTag()
62
+ {
63
+ return 'sandbox';
64
+ }
65
+ }
66
+
67
+ class_alias('Twig\TokenParser\SandboxTokenParser', 'Twig_TokenParser_Sandbox');
vendor/twig/twig/src/TokenParser/SetTokenParser.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Error\SyntaxError;
15
+ use Twig\Node\SetNode;
16
+ use Twig\Token;
17
+
18
+ /**
19
+ * Defines a variable.
20
+ *
21
+ * {% set foo = 'foo' %}
22
+ * {% set foo = [1, 2] %}
23
+ * {% set foo = {'foo': 'bar'} %}
24
+ * {% set foo = 'foo' ~ 'bar' %}
25
+ * {% set foo, bar = 'foo', 'bar' %}
26
+ * {% set foo %}Some content{% endset %}
27
+ *
28
+ * @final
29
+ */
30
+ class SetTokenParser extends AbstractTokenParser
31
+ {
32
+ public function parse(Token $token)
33
+ {
34
+ $lineno = $token->getLine();
35
+ $stream = $this->parser->getStream();
36
+ $names = $this->parser->getExpressionParser()->parseAssignmentExpression();
37
+
38
+ $capture = false;
39
+ if ($stream->nextIf(Token::OPERATOR_TYPE, '=')) {
40
+ $values = $this->parser->getExpressionParser()->parseMultitargetExpression();
41
+
42
+ $stream->expect(Token::BLOCK_END_TYPE);
43
+
44
+ if (\count($names) !== \count($values)) {
45
+ throw new SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
46
+ }
47
+ } else {
48
+ $capture = true;
49
+
50
+ if (\count($names) > 1) {
51
+ throw new SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
52
+ }
53
+
54
+ $stream->expect(Token::BLOCK_END_TYPE);
55
+
56
+ $values = $this->parser->subparse([$this, 'decideBlockEnd'], true);
57
+ $stream->expect(Token::BLOCK_END_TYPE);
58
+ }
59
+
60
+ return new SetNode($capture, $names, $values, $lineno, $this->getTag());
61
+ }
62
+
63
+ public function decideBlockEnd(Token $token)
64
+ {
65
+ return $token->test('endset');
66
+ }
67
+
68
+ public function getTag()
69
+ {
70
+ return 'set';
71
+ }
72
+ }
73
+
74
+ class_alias('Twig\TokenParser\SetTokenParser', 'Twig_TokenParser_Set');
vendor/twig/twig/src/TokenParser/SpacelessTokenParser.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Node\SpacelessNode;
15
+ use Twig\Token;
16
+
17
+ /**
18
+ * Remove whitespaces between HTML tags.
19
+ *
20
+ * {% spaceless %}
21
+ * <div>
22
+ * <strong>foo</strong>
23
+ * </div>
24
+ * {% endspaceless %}
25
+ * {# output will be <div><strong>foo</strong></div> #}
26
+ *
27
+ * @final
28
+ */
29
+ class SpacelessTokenParser extends AbstractTokenParser
30
+ {
31
+ public function parse(Token $token)
32
+ {
33
+ $lineno = $token->getLine();
34
+
35
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
36
+ $body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true);
37
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
38
+
39
+ return new SpacelessNode($body, $lineno, $this->getTag());
40
+ }
41
+
42
+ public function decideSpacelessEnd(Token $token)
43
+ {
44
+ return $token->test('endspaceless');
45
+ }
46
+
47
+ public function getTag()
48
+ {
49
+ return 'spaceless';
50
+ }
51
+ }
52
+
53
+ class_alias('Twig\TokenParser\SpacelessTokenParser', 'Twig_TokenParser_Spaceless');
vendor/twig/twig/src/TokenParser/TokenParserInterface.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Error\SyntaxError;
15
+ use Twig\Parser;
16
+ use Twig\Token;
17
+
18
+ /**
19
+ * Interface implemented by token parsers.
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ interface TokenParserInterface
24
+ {
25
+ /**
26
+ * Sets the parser associated with this token parser.
27
+ */
28
+ public function setParser(Parser $parser);
29
+
30
+ /**
31
+ * Parses a token and returns a node.
32
+ *
33
+ * @return \Twig_NodeInterface
34
+ *
35
+ * @throws SyntaxError
36
+ */
37
+ public function parse(Token $token);
38
+
39
+ /**
40
+ * Gets the tag name associated with this token parser.
41
+ *
42
+ * @return string The tag name
43
+ */
44
+ public function getTag();
45
+ }
46
+
47
+ class_alias('Twig\TokenParser\TokenParserInterface', 'Twig_TokenParserInterface');
48
+
49
+ // Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
50
+ class_exists('Twig\Token');
51
+ class_exists('Twig\Parser');
vendor/twig/twig/src/TokenParser/UseTokenParser.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Error\SyntaxError;
15
+ use Twig\Node\Expression\ConstantExpression;
16
+ use Twig\Node\Node;
17
+ use Twig\Token;
18
+
19
+ /**
20
+ * Imports blocks defined in another template into the current template.
21
+ *
22
+ * {% extends "base.html" %}
23
+ *
24
+ * {% use "blocks.html" %}
25
+ *
26
+ * {% block title %}{% endblock %}
27
+ * {% block content %}{% endblock %}
28
+ *
29
+ * @see https://twig.symfony.com/doc/templates.html#horizontal-reuse for details.
30
+ *
31
+ * @final
32
+ */
33
+ class UseTokenParser extends AbstractTokenParser
34
+ {
35
+ public function parse(Token $token)
36
+ {
37
+ $template = $this->parser->getExpressionParser()->parseExpression();
38
+ $stream = $this->parser->getStream();
39
+
40
+ if (!$template instanceof ConstantExpression) {
41
+ throw new SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
42
+ }
43
+
44
+ $targets = [];
45
+ if ($stream->nextIf('with')) {
46
+ do {
47
+ $name = $stream->expect(Token::NAME_TYPE)->getValue();
48
+
49
+ $alias = $name;
50
+ if ($stream->nextIf('as')) {
51
+ $alias = $stream->expect(Token::NAME_TYPE)->getValue();
52
+ }
53
+
54
+ $targets[$name] = new ConstantExpression($alias, -1);
55
+
56
+ if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
57
+ break;
58
+ }
59
+ } while (true);
60
+ }
61
+
62
+ $stream->expect(Token::BLOCK_END_TYPE);
63
+
64
+ $this->parser->addTrait(new Node(['template' => $template, 'targets' => new Node($targets)]));
65
+
66
+ return new Node();
67
+ }
68
+
69
+ public function getTag()
70
+ {
71
+ return 'use';
72
+ }
73
+ }
74
+
75
+ class_alias('Twig\TokenParser\UseTokenParser', 'Twig_TokenParser_Use');
vendor/twig/twig/src/TokenParser/WithTokenParser.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\TokenParser;
13
+
14
+ use Twig\Node\WithNode;
15
+ use Twig\Token;
16
+
17
+ /**
18
+ * Creates a nested scope.
19
+ *
20
+ * @author Fabien Potencier <fabien@symfony.com>
21
+ *
22
+ * @final
23
+ */
24
+ class WithTokenParser extends AbstractTokenParser
25
+ {
26
+ public function parse(Token $token)
27
+ {
28
+ $stream = $this->parser->getStream();
29
+
30
+ $variables = null;
31
+ $only = false;
32
+ if (!$stream->test(Token::BLOCK_END_TYPE)) {
33
+ $variables = $this->parser->getExpressionParser()->parseExpression();
34
+ $only = $stream->nextIf(Token::NAME_TYPE, 'only');
35
+ }
36
+
37
+ $stream->expect(Token::BLOCK_END_TYPE);
38
+
39
+ $body = $this->parser->subparse([$this, 'decideWithEnd'], true);
40
+
41
+ $stream->expect(Token::BLOCK_END_TYPE);
42
+
43
+ return new WithNode($body, $variables, $only, $token->getLine(), $this->getTag());
44
+ }
45
+
46
+ public function decideWithEnd(Token $token)
47
+ {
48
+ return $token->test('endwith');
49
+ }
50
+
51
+ public function getTag()
52
+ {
53
+ return 'with';
54
+ }
55
+ }
56
+
57
+ class_alias('Twig\TokenParser\WithTokenParser', 'Twig_TokenParser_With');
vendor/twig/twig/src/TokenStream.php ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ * (c) Armin Ronacher
8
+ *
9
+ * For the full copyright and license information, please view the LICENSE
10
+ * file that was distributed with this source code.
11
+ */
12
+
13
+ namespace Twig;
14
+
15
+ use Twig\Error\SyntaxError;
16
+
17
+ /**
18
+ * Represents a token stream.
19
+ *
20
+ * @final
21
+ *
22
+ * @author Fabien Potencier <fabien@symfony.com>
23
+ */
24
+ class TokenStream
25
+ {
26
+ protected $tokens;
27
+ protected $current = 0;
28
+ protected $filename;
29
+
30
+ private $source;
31
+
32
+ /**
33
+ * @param array $tokens An array of tokens
34
+ * @param string|null $name The name of the template which tokens are associated with
35
+ * @param string|null $source The source code associated with the tokens
36
+ */
37
+ public function __construct(array $tokens, $name = null, $source = null)
38
+ {
39
+ if (!$name instanceof Source) {
40
+ if (null !== $name || null !== $source) {
41
+ @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED);
42
+ }
43
+ $this->source = new Source($source, $name);
44
+ } else {
45
+ $this->source = $name;
46
+ }
47
+
48
+ $this->tokens = $tokens;
49
+
50
+ // deprecated, not used anymore, to be removed in 2.0
51
+ $this->filename = $this->source->getName();
52
+ }
53
+
54
+ public function __toString()
55
+ {
56
+ return implode("\n", $this->tokens);
57
+ }
58
+
59
+ public function injectTokens(array $tokens)
60
+ {
61
+ $this->tokens = array_merge(\array_slice($this->tokens, 0, $this->current), $tokens, \array_slice($this->tokens, $this->current));
62
+ }
63
+
64
+ /**
65
+ * Sets the pointer to the next token and returns the old one.
66
+ *
67
+ * @return Token
68
+ */
69
+ public function next()
70
+ {
71
+ if (!isset($this->tokens[++$this->current])) {
72
+ throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source);
73
+ }
74
+
75
+ return $this->tokens[$this->current - 1];
76
+ }
77
+
78
+ /**
79
+ * Tests a token, sets the pointer to the next one and returns it or throws a syntax error.
80
+ *
81
+ * @return Token|null The next token if the condition is true, null otherwise
82
+ */
83
+ public function nextIf($primary, $secondary = null)
84
+ {
85
+ if ($this->tokens[$this->current]->test($primary, $secondary)) {
86
+ return $this->next();
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Tests a token and returns it or throws a syntax error.
92
+ *
93
+ * @return Token
94
+ */
95
+ public function expect($type, $value = null, $message = null)
96
+ {
97
+ $token = $this->tokens[$this->current];
98
+ if (!$token->test($type, $value)) {
99
+ $line = $token->getLine();
100
+ throw new SyntaxError(sprintf('%sUnexpected token "%s"%s ("%s" expected%s).',
101
+ $message ? $message.'. ' : '',
102
+ Token::typeToEnglish($token->getType()),
103
+ $token->getValue() ? sprintf(' of value "%s"', $token->getValue()) : '',
104
+ Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''),
105
+ $line,
106
+ $this->source
107
+ );
108
+ }
109
+ $this->next();
110
+
111
+ return $token;
112
+ }
113
+
114
+ /**
115
+ * Looks at the next token.
116
+ *
117
+ * @param int $number
118
+ *
119
+ * @return Token
120
+ */
121
+ public function look($number = 1)
122
+ {
123
+ if (!isset($this->tokens[$this->current + $number])) {
124
+ throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source);
125
+ }
126
+
127
+ return $this->tokens[$this->current + $number];
128
+ }
129
+
130
+ /**
131
+ * Tests the current token.
132
+ *
133
+ * @return bool
134
+ */
135
+ public function test($primary, $secondary = null)
136
+ {
137
+ return $this->tokens[$this->current]->test($primary, $secondary);
138
+ }
139
+
140
+ /**
141
+ * Checks if end of stream was reached.
142
+ *
143
+ * @return bool
144
+ */
145
+ public function isEOF()
146
+ {
147
+ return Token::EOF_TYPE === $this->tokens[$this->current]->getType();
148
+ }
149
+
150
+ /**
151
+ * @return Token
152
+ */
153
+ public function getCurrent()
154
+ {
155
+ return $this->tokens[$this->current];
156
+ }
157
+
158
+ /**
159
+ * Gets the name associated with this stream (null if not defined).
160
+ *
161
+ * @return string|null
162
+ *
163
+ * @deprecated since 1.27 (to be removed in 2.0)
164
+ */
165
+ public function getFilename()
166
+ {
167
+ @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
168
+
169
+ return $this->source->getName();
170
+ }
171
+
172
+ /**
173
+ * Gets the source code associated with this stream.
174
+ *
175
+ * @return string
176
+ *
177
+ * @internal Don't use this as it might be empty depending on the environment configuration
178
+ *
179
+ * @deprecated since 1.27 (to be removed in 2.0)
180
+ */
181
+ public function getSource()
182
+ {
183
+ @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
184
+
185
+ return $this->source->getCode();
186
+ }
187
+
188
+ /**
189
+ * Gets the source associated with this stream.
190
+ *
191
+ * @return Source
192
+ *
193
+ * @internal
194
+ */
195
+ public function getSourceContext()
196
+ {
197
+ return $this->source;
198
+ }
199
+ }
200
+
201
+ class_alias('Twig\TokenStream', 'Twig_TokenStream');
vendor/twig/twig/src/TwigFilter.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig;
13
+
14
+ use Twig\Node\Node;
15
+
16
+ /**
17
+ * Represents a template filter.
18
+ *
19
+ * @final
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class TwigFilter
24
+ {
25
+ protected $name;
26
+ protected $callable;
27
+ protected $options;
28
+ protected $arguments = [];
29
+
30
+ public function __construct($name, $callable, array $options = [])
31
+ {
32
+ $this->name = $name;
33
+ $this->callable = $callable;
34
+ $this->options = array_merge([
35
+ 'needs_environment' => false,
36
+ 'needs_context' => false,
37
+ 'is_variadic' => false,
38
+ 'is_safe' => null,
39
+ 'is_safe_callback' => null,
40
+ 'pre_escape' => null,
41
+ 'preserves_safety' => null,
42
+ 'node_class' => '\Twig\Node\Expression\FilterExpression',
43
+ 'deprecated' => false,
44
+ 'alternative' => null,
45
+ ], $options);
46
+ }
47
+
48
+ public function getName()
49
+ {
50
+ return $this->name;
51
+ }
52
+
53
+ public function getCallable()
54
+ {
55
+ return $this->callable;
56
+ }
57
+
58
+ public function getNodeClass()
59
+ {
60
+ return $this->options['node_class'];
61
+ }
62
+
63
+ public function setArguments($arguments)
64
+ {
65
+ $this->arguments = $arguments;
66
+ }
67
+
68
+ public function getArguments()
69
+ {
70
+ return $this->arguments;
71
+ }
72
+
73
+ public function needsEnvironment()
74
+ {
75
+ return $this->options['needs_environment'];
76
+ }
77
+
78
+ public function needsContext()
79
+ {
80
+ return $this->options['needs_context'];
81
+ }
82
+
83
+ public function getSafe(Node $filterArgs)
84
+ {
85
+ if (null !== $this->options['is_safe']) {
86
+ return $this->options['is_safe'];
87
+ }
88
+
89
+ if (null !== $this->options['is_safe_callback']) {
90
+ return \call_user_func($this->options['is_safe_callback'], $filterArgs);
91
+ }
92
+ }
93
+
94
+ public function getPreservesSafety()
95
+ {
96
+ return $this->options['preserves_safety'];
97
+ }
98
+
99
+ public function getPreEscape()
100
+ {
101
+ return $this->options['pre_escape'];
102
+ }
103
+
104
+ public function isVariadic()
105
+ {
106
+ return $this->options['is_variadic'];
107
+ }
108
+
109
+ public function isDeprecated()
110
+ {
111
+ return (bool) $this->options['deprecated'];
112
+ }
113
+
114
+ public function getDeprecatedVersion()
115
+ {
116
+ return $this->options['deprecated'];
117
+ }
118
+
119
+ public function getAlternative()
120
+ {
121
+ return $this->options['alternative'];
122
+ }
123
+ }
124
+
125
+ class_alias('Twig\TwigFilter', 'Twig_SimpleFilter');
126
+
127
+ // Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
128
+ class_exists('Twig\Node\Node');
vendor/twig/twig/src/TwigFunction.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig;
13
+
14
+ use Twig\Node\Node;
15
+
16
+ /**
17
+ * Represents a template function.
18
+ *
19
+ * @final
20
+ *
21
+ * @author Fabien Potencier <fabien@symfony.com>
22
+ */
23
+ class TwigFunction
24
+ {
25
+ protected $name;
26
+ protected $callable;
27
+ protected $options;
28
+ protected $arguments = [];
29
+
30
+ public function __construct($name, $callable, array $options = [])
31
+ {
32
+ $this->name = $name;
33
+ $this->callable = $callable;
34
+ $this->options = array_merge([
35
+ 'needs_environment' => false,
36
+ 'needs_context' => false,
37
+ 'is_variadic' => false,
38
+ 'is_safe' => null,
39
+ 'is_safe_callback' => null,
40
+ 'node_class' => '\Twig\Node\Expression\FunctionExpression',
41
+ 'deprecated' => false,
42
+ 'alternative' => null,
43
+ ], $options);
44
+ }
45
+
46
+ public function getName()
47
+ {
48
+ return $this->name;
49
+ }
50
+
51
+ public function getCallable()
52
+ {
53
+ return $this->callable;
54
+ }
55
+
56
+ public function getNodeClass()
57
+ {
58
+ return $this->options['node_class'];
59
+ }
60
+
61
+ public function setArguments($arguments)
62
+ {
63
+ $this->arguments = $arguments;
64
+ }
65
+
66
+ public function getArguments()
67
+ {
68
+ return $this->arguments;
69
+ }
70
+
71
+ public function needsEnvironment()
72
+ {
73
+ return $this->options['needs_environment'];
74
+ }
75
+
76
+ public function needsContext()
77
+ {
78
+ return $this->options['needs_context'];
79
+ }
80
+
81
+ public function getSafe(Node $functionArgs)
82
+ {
83
+ if (null !== $this->options['is_safe']) {
84
+ return $this->options['is_safe'];
85
+ }
86
+
87
+ if (null !== $this->options['is_safe_callback']) {
88
+ return \call_user_func($this->options['is_safe_callback'], $functionArgs);
89
+ }
90
+
91
+ return [];
92
+ }
93
+
94
+ public function isVariadic()
95
+ {
96
+ return $this->options['is_variadic'];
97
+ }
98
+
99
+ public function isDeprecated()
100
+ {
101
+ return (bool) $this->options['deprecated'];
102
+ }
103
+
104
+ public function getDeprecatedVersion()
105
+ {
106
+ return $this->options['deprecated'];
107
+ }
108
+
109
+ public function getAlternative()
110
+ {
111
+ return $this->options['alternative'];
112
+ }
113
+ }
114
+
115
+ class_alias('Twig\TwigFunction', 'Twig_SimpleFunction');
116
+
117
+ // Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
118
+ class_exists('Twig\Node\Node');
vendor/twig/twig/src/TwigTest.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig;
13
+
14
+ /**
15
+ * Represents a template test.
16
+ *
17
+ * @final
18
+ *
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ */
21
+ class TwigTest
22
+ {
23
+ protected $name;
24
+ protected $callable;
25
+ protected $options;
26
+
27
+ private $arguments = [];
28
+
29
+ public function __construct($name, $callable, array $options = [])
30
+ {
31
+ $this->name = $name;
32
+ $this->callable = $callable;
33
+ $this->options = array_merge([
34
+ 'is_variadic' => false,
35
+ 'node_class' => '\Twig\Node\Expression\TestExpression',
36
+ 'deprecated' => false,
37
+ 'alternative' => null,
38
+ ], $options);
39
+ }
40
+
41
+ public function getName()
42
+ {
43
+ return $this->name;
44
+ }
45
+
46
+ public function getCallable()
47
+ {
48
+ return $this->callable;
49
+ }
50
+
51
+ public function getNodeClass()
52
+ {
53
+ return $this->options['node_class'];
54
+ }
55
+
56
+ public function isVariadic()
57
+ {
58
+ return $this->options['is_variadic'];
59
+ }
60
+
61
+ public function isDeprecated()
62
+ {
63
+ return (bool) $this->options['deprecated'];
64
+ }
65
+
66
+ public function getDeprecatedVersion()
67
+ {
68
+ return $this->options['deprecated'];
69
+ }
70
+
71
+ public function getAlternative()
72
+ {
73
+ return $this->options['alternative'];
74
+ }
75
+
76
+ public function setArguments($arguments)
77
+ {
78
+ $this->arguments = $arguments;
79
+ }
80
+
81
+ public function getArguments()
82
+ {
83
+ return $this->arguments;
84
+ }
85
+ }
86
+
87
+ class_alias('Twig\TwigTest', 'Twig_SimpleTest');
vendor/twig/twig/src/Util/DeprecationCollector.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Util;
13
+
14
+ use Twig\Environment;
15
+ use Twig\Error\SyntaxError;
16
+ use Twig\Source;
17
+
18
+ /**
19
+ * @author Fabien Potencier <fabien@symfony.com>
20
+ *
21
+ * @final
22
+ */
23
+ class DeprecationCollector
24
+ {
25
+ private $twig;
26
+ private $deprecations;
27
+
28
+ public function __construct(Environment $twig)
29
+ {
30
+ $this->twig = $twig;
31
+ }
32
+
33
+ /**
34
+ * Returns deprecations for templates contained in a directory.
35
+ *
36
+ * @param string $dir A directory where templates are stored
37
+ * @param string $ext Limit the loaded templates by extension
38
+ *
39
+ * @return array An array of deprecations
40
+ */
41
+ public function collectDir($dir, $ext = '.twig')
42
+ {
43
+ $iterator = new \RegexIterator(
44
+ new \RecursiveIteratorIterator(
45
+ new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY
46
+ ), '{'.preg_quote($ext).'$}'
47
+ );
48
+
49
+ return $this->collect(new TemplateDirIterator($iterator));
50
+ }
51
+
52
+ /**
53
+ * Returns deprecations for passed templates.
54
+ *
55
+ * @param \Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template)
56
+ *
57
+ * @return array An array of deprecations
58
+ */
59
+ public function collect(\Traversable $iterator)
60
+ {
61
+ $this->deprecations = [];
62
+
63
+ set_error_handler([$this, 'errorHandler']);
64
+
65
+ foreach ($iterator as $name => $contents) {
66
+ try {
67
+ $this->twig->parse($this->twig->tokenize(new Source($contents, $name)));
68
+ } catch (SyntaxError $e) {
69
+ // ignore templates containing syntax errors
70
+ }
71
+ }
72
+
73
+ restore_error_handler();
74
+
75
+ $deprecations = $this->deprecations;
76
+ $this->deprecations = [];
77
+
78
+ return $deprecations;
79
+ }
80
+
81
+ /**
82
+ * @internal
83
+ */
84
+ public function errorHandler($type, $msg)
85
+ {
86
+ if (E_USER_DEPRECATED === $type) {
87
+ $this->deprecations[] = $msg;
88
+ }
89
+ }
90
+ }
91
+
92
+ class_alias('Twig\Util\DeprecationCollector', 'Twig_Util_DeprecationCollector');
vendor/twig/twig/src/Util/TemplateDirIterator.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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 Twig\Util;
13
+
14
+ /**
15
+ * @author Fabien Potencier <fabien@symfony.com>
16
+ */
17
+ class TemplateDirIterator extends \IteratorIterator
18
+ {
19
+ public function current()
20
+ {
21
+ return file_get_contents(parent::current());
22
+ }
23
+
24
+ public function key()
25
+ {
26
+ return (string) parent::key();
27
+ }
28
+ }
29
+
30
+ class_alias('Twig\Util\TemplateDirIterator', 'Twig_Util_TemplateDirIterator');
vendor/twig/twig/test/Twig/Tests/Fixtures/errors/leak-output.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require __DIR__.'/../../../../../vendor/autoload.php';
4
+
5
+ use Twig\Environment;
6
+ use Twig\Extension\AbstractExtension;
7
+ use Twig\Loader\ArrayLoader;
8
+ use Twig\TwigFilter;
9
+
10
+ class BrokenExtension extends AbstractExtension
11
+ {
12
+ public function getFilters()
13
+ {
14
+ return [
15
+ new TwigFilter('broken', [$this, 'broken']),
16
+ ];
17
+ }
18
+
19
+ public function broken()
20
+ {
21
+ die('OOPS');
22
+ }
23
+ }
24
+
25
+ $loader = new ArrayLoader([
26
+ 'index.html.twig' => 'Hello {{ "world"|broken }}',
27
+ ]);
28
+ $twig = new Environment($loader, ['debug' => isset($argv[1])]);
29
+ $twig->addExtension(new BrokenExtension());
30
+
31
+ echo $twig->render('index.html.twig');
vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/exception_in_extension_extends.test ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Exception thrown from a child for an extension error
3
+ --TEMPLATE--
4
+ {% extends 'base.twig' %}
5
+ --TEMPLATE(base.twig)--
6
+
7
+
8
+ {{ random([]) }}
9
+ --DATA--
10
+ return []
11
+ --EXCEPTION--
12
+ Twig\Error\RuntimeError: The random function cannot pick from an empty array in "base.twig" at line 4.
vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/exception_in_extension_include.test ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Exception thrown from an include for an extension error
3
+ --TEMPLATE--
4
+ {% include 'content.twig' %}
5
+ --TEMPLATE(content.twig)--
6
+
7
+
8
+ {{ random([]) }}
9
+ --DATA--
10
+ return []
11
+ --EXCEPTION--
12
+ Twig\Error\RuntimeError: The random function cannot pick from an empty array in "content.twig" at line 4.
vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/strict_comparison_operator.test ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ --TEST--
2
+ The PHP === strict comparison operator is not supported
3
+ --TEMPLATE--
4
+ {{ 1 === 2 }}
5
+ --EXCEPTION--
6
+ Twig\Error\SyntaxError: Unexpected operator of value "=". Did you try to use "===" or "!==" for strict comparison? Use "is same as(value)" instead in "index.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/call_argument_defined_twice.test ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Argument is defined twice in a call
3
+ --TEMPLATE--
4
+ {{ date(987654, date = 123456) }}
5
+ --DATA--
6
+ return []
7
+ --EXCEPTION--
8
+ Twig\Error\SyntaxError: Argument "date" is defined twice for function "date" in "index.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/call_positional_arg_after_named_arg.test ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Positional arguments after named arguments in a call
3
+ --TEMPLATE--
4
+ {{ date(date = 123456, 'Y-m-d') }}
5
+ --DATA--
6
+ return []
7
+ --EXCEPTION--
8
+ Twig\Error\SyntaxError: Positional arguments cannot be used after named arguments for function "date" in "index.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/floats.test ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Twig compiles floats properly
3
+ --CONDITION--
4
+ version_compare(phpversion(), '7.0.0', '>=')
5
+ --TEMPLATE--
6
+ {% set val2 = 0.0 %}
7
+
8
+ {{ val is same as (0.0) ? 'Yes' : 'No' }}
9
+ {{ val2 is same as (0.0) ? 'Yes' : 'No' }}
10
+ {{ val is same as (val2) ? 'Yes' : 'No' }}
11
+ --DATA--
12
+ return ['val' => 0.0]
13
+ --EXPECT--
14
+ Yes
15
+ Yes
16
+ Yes
vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/not_arrow_fn.test ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ A string in parentheses cannot be confused with an arrow function
3
+ --TEMPLATE--
4
+ {{ ["foo", "bar"]|join(("f")) }}
5
+ --DATA--
6
+ return []
7
+ --EXPECT--
8
+ foofbar
vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/string_operator_as_var_assignment.test ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Twig supports the string operators as variable names in assignments
3
+ --TEMPLATE--
4
+ {% for matches in [1, 2] %}
5
+ {{- matches }}
6
+ {% endfor %}
7
+
8
+ {% set matches = [1, 2] %}
9
+
10
+ OK
11
+ --DATA--
12
+ return []
13
+ --EXPECT--
14
+ 1
15
+ 2
16
+
17
+
18
+ OK
vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_more_elements.test ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "batch" filter
3
+ --TEMPLATE--
4
+ {% for row in items|batch(3, 'fill') %}
5
+ <div class=row>
6
+ {% for key, column in row %}
7
+ <div class={{ key }}>{{ column }}</div>
8
+ {% endfor %}
9
+ </div>
10
+ {% endfor %}
11
+ --DATA--
12
+ return ['items' => ['a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', '123' => 'e']]
13
+ --EXPECT--
14
+ <div class=row>
15
+ <div class=a>a</div>
16
+ <div class=b>b</div>
17
+ <div class=c>c</div>
18
+ </div>
19
+ <div class=row>
20
+ <div class=d>d</div>
21
+ <div class=123>e</div>
22
+ <div class=124>fill</div>
23
+ </div>
vendor/twig/twig/test/Twig/Tests/Fixtures/filters/filter.test ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "filter" filter
3
+ --TEMPLATE--
4
+ {% set offset = 3 %}
5
+
6
+ {% for k, v in [1, 5, 3, 4, 5]|filter((v) => v > offset) -%}
7
+ {{ k }} = {{ v }}
8
+ {% endfor %}
9
+
10
+ {% for k, v in {a: 1, b: 2, c: 5, d: 8}|filter(v => v > offset) -%}
11
+ {{ k }} = {{ v }}
12
+ {% endfor %}
13
+
14
+ {% for k, v in [1, 5, 3, 4, 5]|filter(v => v > offset) -%}
15
+ {{ k }} = {{ v }}
16
+ {% endfor %}
17
+
18
+ {% for k, v in it|filter((v) => v > offset) -%}
19
+ {{ k }} = {{ v }}
20
+ {% endfor %}
21
+
22
+ {% for k, v in ita|filter(v => v > offset) -%}
23
+ {{ k }} = {{ v }}
24
+ {% endfor %}
25
+ --DATA--
26
+ return [
27
+ 'it' => new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8]),
28
+ 'ita' => new IteratorAggregateStub(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8]),
29
+ ]
30
+ --EXPECT--
31
+ 1 = 5
32
+ 3 = 4
33
+ 4 = 5
34
+
35
+ c = 5
36
+ d = 8
37
+
38
+ 1 = 5
39
+ 3 = 4
40
+ 4 = 5
41
+
42
+ c = 5
43
+ d = 8
44
+
45
+ c = 5
46
+ d = 8
vendor/twig/twig/test/Twig/Tests/Fixtures/filters/filter_php_55.test ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "filter" filter (PHP 5.5 required)
3
+ --CONDITION--
4
+ version_compare(phpversion(), '5.5.0', '>=')
5
+ --TEMPLATE--
6
+ {% for k, v in xml|filter(x => true) %}
7
+ {{ k }}/{{ v }}
8
+ {% endfor %}
9
+
10
+ {# we can iterate more than once #}
11
+ {% for k, v in xml|filter(x => true) %}
12
+ {{ k }}/{{ v }}
13
+ {% endfor %}
14
+ --DATA--
15
+ return ['xml' => new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><doc><elem>foo</elem><elem>bar</elem><elem>baz</elem></doc>')]
16
+ --EXPECT--
17
+ elem/foo
18
+ elem/bar
19
+ elem/baz
20
+
21
+ elem/foo
22
+ elem/bar
23
+ elem/baz
vendor/twig/twig/test/Twig/Tests/Fixtures/filters/filter_php_56.test ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "filter" filter (PHP 5.6 required)
3
+ --CONDITION--
4
+ version_compare(phpversion(), '5.6.0', '>=')
5
+ --TEMPLATE--
6
+ {% set offset = 3 %}
7
+
8
+ {% for k, v in {a: 1, b: 2, c: 5, d: 8}|filter((v, k) => (v > offset) and (k != "d")) -%}
9
+ {{ k }} = {{ v }}
10
+ {% endfor %}
11
+
12
+ {% for k, v in it|filter((v, k) => (v > offset) and (k != "d")) -%}
13
+ {{ k }} = {{ v }}
14
+ {% endfor %}
15
+
16
+ {# we can iterate more than once #}
17
+ {% for k, v in it|filter((v, k) => (v > offset) and (k != "d")) -%}
18
+ {{ k }} = {{ v }}
19
+ {% endfor %}
20
+ --DATA--
21
+ return ['it' => new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8])]
22
+ --EXPECT--
23
+ c = 5
24
+
25
+ c = 5
26
+
27
+ c = 5
vendor/twig/twig/test/Twig/Tests/Fixtures/filters/map.test ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "map" filter
3
+ --TEMPLATE--
4
+ {% set offset = 3 %}
5
+
6
+ {% for k, v in [1, 2]|map((item) => item + 2 ) -%}
7
+ {{ k }} = {{ v }}
8
+ {% endfor %}
9
+
10
+ {% for k, v in {a: 1, b: 2}|map((item) => item ~ "*" ) -%}
11
+ {{ k }} = {{ v }}
12
+ {% endfor %}
13
+
14
+ {% for k, v in {a: 1, b: 2}|map((item, k) => item ~ "*" ~ k ) -%}
15
+ {{ k }} = {{ v }}
16
+ {% endfor %}
17
+
18
+ {% for k, v in [1, 2]|map(item => item + 2 ) -%}
19
+ {{ k }} = {{ v }}
20
+ {% endfor %}
21
+
22
+ {% for k, v in it|map(item => item + 2 ) -%}
23
+ {{ k }} = {{ v }}
24
+ {% endfor %}
25
+ --DATA--
26
+ return ['it' => new \ArrayIterator([1, 2])]
27
+ --EXPECT--
28
+ 0 = 3
29
+ 1 = 4
30
+
31
+ a = 1*
32
+ b = 2*
33
+
34
+ a = 1*a
35
+ b = 2*b
36
+
37
+ 0 = 3
38
+ 1 = 4
39
+
40
+ 0 = 3
41
+ 1 = 4
vendor/twig/twig/test/Twig/Tests/Fixtures/filters/reduce.test ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "reduce" filter
3
+ --TEMPLATE--
4
+ {% set offset = 3 %}
5
+
6
+ {{ [1, -1, 4]|reduce((carry, item) => carry + item + offset, 10) }}
7
+
8
+ {{ it|reduce((carry, item) => carry + item + offset, 10) }}
9
+ --DATA--
10
+ return ['it' => new \ArrayIterator([1, -1, 4])]
11
+ --EXPECT--
12
+ 23
13
+
14
+ 23
vendor/twig/twig/test/Twig/Tests/Fixtures/filters/spaceless.test ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "spaceless" filter
3
+ --TEMPLATE--
4
+ {{ " <div> <div> foo </div> </div>"|spaceless }}
5
+ --DATA--
6
+ return []
7
+ --EXPECT--
8
+ <div><div> foo </div></div>
vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/ignore_missing_exists.test ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "include" function
3
+ --TEMPLATE--
4
+ {{ include("included.twig", ignore_missing = true) }}
5
+ NOT DISPLAYED
6
+ --TEMPLATE(included.twig)--
7
+ {{ include("DOES NOT EXIST") }}
8
+ --DATA--
9
+ return []
10
+ --EXCEPTION--
11
+ Twig\Error\LoaderError: Template "DOES NOT EXIST" is not defined in "included.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/include_missing_extends.test ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "include" function
3
+ --TEMPLATE--
4
+ {{ include(['bad.twig', 'good.twig'], ignore_missing = true) }}
5
+ NOT DISPLAYED
6
+ --TEMPLATE(bad.twig)--
7
+ {% extends 'DOES NOT EXIST' %}
8
+ --TEMPLATE(good.twig)--
9
+ NOT DISPLAYED
10
+ --DATA--
11
+ return []
12
+ --EXCEPTION--
13
+ Twig\Error\LoaderError: Template "DOES NOT EXIST" is not defined in "bad.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include_template_from_string.test ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "template_from_string" function works in an "include"
3
+ --TEMPLATE--
4
+ {% set embed = '{% embed "embed.twig" %}{% endembed %}' %}
5
+ {{ include(template_from_string(embed)) }}
6
+ --TEMPLATE(embed.twig)--
7
+ Cool
8
+ --DATA--
9
+ return []
10
+ --EXPECT--
11
+ Cool
vendor/twig/twig/test/Twig/Tests/Fixtures/functions/template_from_string_error.test ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "template_from_string" function
3
+ --TEMPLATE--
4
+ {% include template_from_string("{{ not a Twig template ", "foo.twig") %}
5
+ --DATA--
6
+ return []
7
+ --EXCEPTION--
8
+ Twig\Error\SyntaxError: Unclosed "variable" in "foo.twig (string template 4900163d56b1af4b704c6b0afee7f98ba53418ce7a93d37a3af1882735baf9cd)" at line 1.
vendor/twig/twig/test/Twig/Tests/Fixtures/regression/block_names_unicity.test ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Block names are unique per template
3
+ --TEMPLATE--
4
+ {% extends 'layout' %}
5
+ {% block content -%}
6
+ {% filter title -%}
7
+ second
8
+ {% endfilter %}
9
+ {% endblock %}
10
+ --TEMPLATE(layout)--
11
+ {% filter title -%}
12
+ first
13
+ {% endfilter %}
14
+ {% block content %}{% endblock %}
15
+ --DATA--
16
+ return []
17
+ --EXPECT--
18
+ First
19
+ Second
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/basic.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "apply" tag applies a filter on its children
3
+ --TEMPLATE--
4
+ {% apply upper %}
5
+ Some text with a {{ var }}
6
+ {% endapply %}
7
+ --DATA--
8
+ return ['var' => 'var']
9
+ --EXPECT--
10
+ SOME TEXT WITH A VAR
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/json_encode.test ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "apply" tag applies a filter on its children
3
+ --TEMPLATE--
4
+ {% apply json_encode|raw %}test{% endapply %}
5
+ --DATA--
6
+ return []
7
+ --EXPECT--
8
+ "test"
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/multiple.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "apply" tags accept multiple chained filters
3
+ --TEMPLATE--
4
+ {% apply lower|title %}
5
+ {{ var }}
6
+ {% endapply %}
7
+ --DATA--
8
+ return ['var' => 'VAR']
9
+ --EXPECT--
10
+ Var
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/nested.test ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "apply" tags can be nested at will
3
+ --TEMPLATE--
4
+ {% apply lower|title %}
5
+ {{ var }}
6
+ {% apply upper %}
7
+ {{ var }}
8
+ {% endapply %}
9
+ {{ var }}
10
+ {% endapply %}
11
+ --DATA--
12
+ return ['var' => 'var']
13
+ --EXPECT--
14
+ Var
15
+ Var
16
+ Var
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/scope.test ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "apply" tag does not create a new scope
3
+ --TEMPLATE--
4
+ {% set foo = 'baz' %}
5
+ {% apply spaceless %}
6
+ {% set foo = 'foo' %}
7
+ {% set bar = 'bar' %}
8
+ {% endapply %}
9
+ {{ 'foo' == foo ? 'OK ' ~ foo : 'KO' }}
10
+ {{ 'bar' == bar ? 'OK ' ~ bar : 'KO' }}
11
+ --DATA--
12
+ return []
13
+ --EXPECT--
14
+ OK foo
15
+ OK bar
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/with_for_tag.test ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "apply" tag applies the filter on "for" tags
3
+ --TEMPLATE--
4
+ {% apply upper %}
5
+ {% for item in items %}
6
+ {{ item }}
7
+ {% endfor %}
8
+ {% endapply %}
9
+ --DATA--
10
+ return ['items' => ['a', 'b']]
11
+ --EXPECT--
12
+ A
13
+ B
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/with_if_tag.test ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "apply" tag applies the filter on "if" tags
3
+ --TEMPLATE--
4
+ {% apply upper %}
5
+ {% if items %}
6
+ {{ items|join(', ') }}
7
+ {% endif %}
8
+
9
+ {% if items.3 is defined %}
10
+ FOO
11
+ {% else %}
12
+ {{ items.1 }}
13
+ {% endif %}
14
+
15
+ {% if items.3 is defined %}
16
+ FOO
17
+ {% elseif items.1 %}
18
+ {{ items.0 }}
19
+ {% endif %}
20
+
21
+ {% endapply %}
22
+ --DATA--
23
+ return ['items' => ['a', 'b']]
24
+ --EXPECT--
25
+ A, B
26
+
27
+ B
28
+
29
+ A
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/deprecated/block.legacy.test ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Deprecating a block with "deprecated" tag
3
+ --TEMPLATE--
4
+ {% use 'greeting.twig' %}
5
+
6
+ {{ block('welcome') }}
7
+
8
+ --TEMPLATE(greeting.twig)--
9
+ {% block welcome %}
10
+ {% deprecated 'The "welcome" block is deprecated, use "hello" instead.' %}
11
+ {{ block('hello') }}
12
+ {% endblock %}
13
+
14
+ {% block hello %}
15
+ Hello Fabien
16
+ {% endblock %}
17
+ --DATA--
18
+ return []
19
+ --EXPECT--
20
+ Hello Fabien
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/deprecated/macro.legacy.test ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Deprecating a macro with "deprecated" tag
3
+ --TEMPLATE--
4
+ {% import 'greeting.twig' as greeting %}
5
+
6
+ {{ greeting.welcome('Fabien') }}
7
+
8
+ --TEMPLATE(greeting.twig)--
9
+ {% macro welcome(name) %}
10
+ {% deprecated 'The "welcome" macro is deprecated, use "hello" instead.' %}
11
+ {% import _self as self %}
12
+ {{ self.hello(name) }}
13
+ {% endmacro %}
14
+
15
+ {% macro hello(name) %}
16
+ Hello {{ name }}
17
+ {% endmacro %}
18
+ --DATA--
19
+ return []
20
+ --EXPECT--
21
+ Hello Fabien
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/deprecated/template.legacy.test ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Deprecating a template with "deprecated" tag
3
+ --TEMPLATE--
4
+ {% extends 'greeting.twig' %}
5
+
6
+ {% deprecated 'The "index.twig" template is deprecated, use "greeting.twig" instead.' %}
7
+ --TEMPLATE(greeting.twig)--
8
+ Hello Fabien
9
+ --DATA--
10
+ return []
11
+ --EXPECT--
12
+ Hello Fabien
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/scope.test ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "scope" tag creates a new scope
3
+ --TEMPLATE--
4
+ {% filter spaceless %}
5
+ {% set item = 'foo' %}
6
+ {% endfilter %}
7
+ {{ item }}
8
+ --DATA--
9
+ return []
10
+ --EXCEPTION--
11
+ Twig\Error\RuntimeError: Variable "item" does not exist in "index.twig" at line 5.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/ignore_missing_exists.test ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "include" tag
3
+ --TEMPLATE--
4
+ {% include "included.twig" ignore missing %}
5
+ NOT DISPLAYED
6
+ --TEMPLATE(included.twig)--
7
+ {% include "DOES NOT EXIST" %}
8
+ --DATA--
9
+ return []
10
+ --EXCEPTION--
11
+ Twig\Error\LoaderError: Template "DOES NOT EXIST" is not defined in "included.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/include_missing_extends.test ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "include" tag
3
+ --TEMPLATE--
4
+ {% include ['bad.twig', 'good.twig'] ignore missing %}
5
+ NOT DISPLAYED
6
+ --TEMPLATE(bad.twig)--
7
+ {% extends 'DOES NOT EXIST' %}
8
+ --TEMPLATE(good.twig)--
9
+ NOT DISPLAYED
10
+ --DATA--
11
+ return []
12
+ --EXCEPTION--
13
+ Twig\Error\LoaderError: Template "DOES NOT EXIST" is not defined in "bad.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_in_block.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "extends" tag in a block
3
+ --TEMPLATE--
4
+ {% block foo %}
5
+ {% extends "foo.twig" %}
6
+ {% endblock %}
7
+ --DATA--
8
+ return []
9
+ --EXCEPTION--
10
+ Twig\Error\SyntaxError: Cannot use "extend" in a block in "index.twig" at line 3.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_in_macro.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "extends" tag in a macro
3
+ --TEMPLATE--
4
+ {% macro foo() %}
5
+ {% extends "foo.twig" %}
6
+ {% endmacro %}
7
+ --DATA--
8
+ return []
9
+ --EXCEPTION--
10
+ Twig\Error\SyntaxError: Cannot use "extend" in a macro in "index.twig" at line 3.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_as_template_wrapper.test ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "extends" tag with a parent as a Twig_TemplateWrapper instance
3
+ --TEMPLATE--
4
+ {% extends foo %}
5
+
6
+ {% block content %}New{% endblock %}
7
+ --TEMPLATE(foo.twig)--
8
+ {% block content %}Default{% endblock %}
9
+ --DATA--
10
+ return ['foo' => $twig->load('foo.twig')]
11
+ --EXPECT--
12
+ New
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_in_block_is_local.test ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {% block foo %}
5
+ {%- from _self import input as linput %}
6
+ {% endblock %}
7
+
8
+ {% block bar %}
9
+ {{- linput('username') }}
10
+ {% endblock %}
11
+
12
+ {% macro input(name) -%}
13
+ <input name="{{ name }}">
14
+ {% endmacro %}
15
+ --DATA--
16
+ return []
17
+ --EXCEPTION--
18
+ Twig\Error\SyntaxError: Unknown "linput" function in "index.twig" at line 7.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_local_override.test ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {%- from _self import input %}
5
+
6
+ {% block foo %}
7
+ {%- from "macros" import input %}
8
+ {{- input('username') }}
9
+ {% endblock %}
10
+
11
+ {% block bar %}
12
+ {{- input('username') }}
13
+ {% endblock %}
14
+
15
+ {% macro input(name) -%}
16
+ <input name="{{ name }}">
17
+ {% endmacro %}
18
+ --TEMPLATE(macros)--
19
+ {% macro input(name) %}
20
+ <input name="{{ name }}" value="local">
21
+ {% endmacro %}
22
+ --DATA--
23
+ return []
24
+ --EXPECT--
25
+ <input name="username" value="local">
26
+
27
+
28
+ <input name="username">
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_macro_in_a_macro.test ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "from" tag with syntax error
3
+ --TEMPLATE--
4
+ {% from _self import another, foo %}
5
+
6
+ {{ foo() }}
7
+
8
+ {% macro foo() %}
9
+ {{ another() }}
10
+ {% endmacro %}
11
+
12
+ {% macro another() %}
13
+ OK
14
+ {% endmacro %}
15
+ --DATA--
16
+ return []
17
+ --EXCEPTION--
18
+ Twig\Error\SyntaxError: Unknown "another" function in "index.twig" at line 7.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_nested_blocks.test ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {% block foo %}
5
+ {%- from _self import input as linput %}
6
+
7
+ {% block bar %}
8
+ {{- linput('username') }}
9
+ {% endblock %}
10
+ {% endblock %}
11
+
12
+ {% macro input(name) -%}
13
+ <input name="{{ name }}">
14
+ {% endmacro %}
15
+ --DATA--
16
+ return []
17
+ --EXCEPTION--
18
+ Twig\Error\SyntaxError: Unknown "linput" function in "index.twig" at line 6.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_nested_blocks_with_global_macro.test ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {%- from _self import input %}
5
+
6
+ {% block foo %}
7
+ {% block bar %}
8
+ {{- input('username') }}
9
+ {% endblock %}
10
+ {% endblock %}
11
+
12
+ {% macro input(name) -%}
13
+ <input name="{{ name }}">
14
+ {% endmacro %}
15
+ --DATA--
16
+ return []
17
+ --EXCEPTION--
18
+ Twig\Error\SyntaxError: Unknown "input" function in "index.twig" at line 6.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_syntax_error.test ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "from" tag with syntax error
3
+ --TEMPLATE--
4
+ {% from 'forms.twig' %}
5
+ --DATA--
6
+ return []
7
+ --EXCEPTION--
8
+ Twig\Error\SyntaxError: Unexpected token "end of statement block" ("name" expected with value "import") in "index.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_and_blocks.test ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {% import _self as macros %}
5
+ {% from _self import input %}
6
+
7
+ {% block foo %}
8
+ {{- macros.input('username') }}
9
+ {{- input('username') }}
10
+
11
+ {%- import _self as lmacros %}
12
+ {%- from _self import input as linput %}
13
+
14
+ {{- lmacros.input('username') }}
15
+ {{- linput('username') }}
16
+ {% endblock %}
17
+
18
+ {% block bar %}
19
+ {{- macros.input('username') }}
20
+ {{- input('username') }}
21
+ {% endblock %}
22
+
23
+ {% macro input(name) -%}
24
+ <input name="{{ name }}">
25
+ {% endmacro %}
26
+ --DATA--
27
+ return []
28
+ --EXPECT--
29
+ <input name="username">
30
+ <input name="username">
31
+ <input name="username">
32
+ <input name="username">
33
+
34
+
35
+ <input name="username">
36
+ <input name="username">
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_from_string_template.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "import" tag with a template as string
3
+ --TEMPLATE--
4
+ {% import template_from_string("{% macro test() %}ok{% endmacro %}") as m %}
5
+ {{ m.test() }}
6
+ --TEMPLATE(forms.twig)--
7
+ --DATA--
8
+ return []
9
+ --EXPECT--
10
+ ok
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_in_block_is_local.test ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {% block foo %}
5
+ {%- import _self as lmacros %}
6
+ {% endblock %}
7
+
8
+ {% block bar %}
9
+ {{- lmacros.input('username') }}
10
+ {% endblock %}
11
+
12
+ {% macro input(name) -%}
13
+ <input name="{{ name }}">
14
+ {% endmacro %}
15
+ --DATA--
16
+ return []
17
+ --EXCEPTION--
18
+ Twig\Error\RuntimeError: Variable "lmacros" does not exist in "index.twig" at line 7.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_local_override.test ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {%- import _self as macros %}
5
+
6
+ {% block foo %}
7
+ {%- import "macros" as macros %}
8
+ {{- macros.input('username') }}
9
+ {% endblock %}
10
+
11
+ {% block bar %}
12
+ {{- macros.input('username') }}
13
+ {% endblock %}
14
+
15
+ {% macro input(name) -%}
16
+ <input name="{{ name }}">
17
+ {% endmacro %}
18
+ --TEMPLATE(macros)--
19
+ {% macro input(name) %}
20
+ <input name="{{ name }}" value="local">
21
+ {% endmacro %}
22
+ --DATA--
23
+ return []
24
+ --EXPECT--
25
+ <input name="username" value="local">
26
+
27
+
28
+ <input name="username">
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_macro_in_a_macro.test ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "import" tag with syntax error
3
+ --TEMPLATE--
4
+ {% import _self as foo %}
5
+
6
+ {{ foo.foo() }}
7
+
8
+ {% macro foo() %}
9
+ {{ foo.another() }}
10
+ {% endmacro %}
11
+
12
+ {% macro another() %}
13
+ OK
14
+ {% endmacro %}
15
+ --DATA--
16
+ return []
17
+ --EXCEPTION--
18
+ Twig\Error\RuntimeError: Variable "foo" does not exist in "index.twig" at line 7.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_nested_blocks.legacy.test ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {% block foo %}
5
+ {%- import _self as lmacros %}
6
+
7
+ {% block bar %}
8
+ {{- lmacros.input('username') }}
9
+ {% endblock %}
10
+ {% endblock %}
11
+
12
+ {% macro input(name) -%}
13
+ <input name="{{ name }}">
14
+ {% endmacro %}
15
+ --DATA--
16
+ return []
17
+ --EXPECT--
18
+ <input name="username">
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_nested_blocks_with_global_macro.legacy.test ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {%- import _self as macros %}
5
+
6
+ {% block foo %}
7
+ {% block bar %}
8
+ {{- macros.input('username') }}
9
+ {% endblock %}
10
+ {% endblock %}
11
+
12
+ {% macro input(name) -%}
13
+ <input name="{{ name }}">
14
+ {% endmacro %}
15
+ --DATA--
16
+ return []
17
+ --EXPECT--
18
+ <input name="username">
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_self_parent.test ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "macro" tag
3
+ --TEMPLATE--
4
+ {% extends "parent" %}
5
+ {% import _self as me %}
6
+
7
+ {% block test %}
8
+ {{ me.hello() }}
9
+ {% endblock test %}
10
+ --TEMPLATE(parent)--
11
+ {% import _self as me %}
12
+
13
+ {% block test %}
14
+ Hello
15
+ {% endblock test %}
16
+
17
+ {% macro hello() %}
18
+ Test
19
+ {% endmacro %}
20
+ --DATA--
21
+ return []
22
+ --EXPECT--
23
+ Test
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_syntax_error.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "import" tag with reserved name
3
+ --TEMPLATE--
4
+ {% import 'forms.twig' %}
5
+
6
+ {{ macros.parent() }}
7
+ --DATA--
8
+ return []
9
+ --EXCEPTION--
10
+ Twig\Error\SyntaxError: Unexpected token "end of statement block" ("name" expected with value "as") in "index.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_name.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "from" tag with reserved name
3
+ --TEMPLATE--
4
+ {% import 'forms.twig' as macros %}
5
+
6
+ {{ macros.parent() }}
7
+ --DATA--
8
+ return []
9
+ --EXCEPTION--
10
+ Twig\Error\SyntaxError: "parent" cannot be called as macro as it is a reserved keyword in "index.twig" at line 4.
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/array.test ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ sandbox tag
3
+ --TEMPLATE--
4
+ {%- sandbox %}
5
+ {%- include "foo.twig" %}
6
+ {%- endsandbox %}
7
+ --TEMPLATE(foo.twig)--
8
+ {{ [a][0] }}
9
+ {{ dump([a][0]) }}
10
+ --DATA--
11
+ return ['a' => 'b']
12
+ --CONFIG--
13
+ return ['autoescape' => false, 'debug' => true]
14
+ --EXPECT--
15
+ b
16
+ string(1) "b"
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture_scope.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "set" tag block capture
3
+ --TEMPLATE--
4
+ {% set foo %}{{ foo }}{% endset %}
5
+
6
+ {{ foo }}
7
+ --DATA--
8
+ return ['foo' => 'foo']
9
+ --EXPECT--
10
+ foo
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/inheritance.test ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "set" tag with inheritance
3
+ --TEMPLATE--
4
+ {% extends "layout.twig" %}
5
+
6
+ {% set bar %}bar{% endset %}
7
+
8
+ {% block var_from_child %}
9
+ {{- bar -}}
10
+ {% endblock %}
11
+ --TEMPLATE(layout.twig)--
12
+ {% set foo %}foo{% endset %}
13
+
14
+ {% block var_from_layout %}
15
+ {{- foo -}}
16
+ {% endblock %}
17
+
18
+ {% block var_from_child %}
19
+ {% endblock %}
20
+ --DATA--
21
+ return []
22
+ --EXPECT--
23
+ foo
24
+ bar
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/inheritance_overriding.test ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "set" tag with inheritance
3
+ --TEMPLATE--
4
+ {% extends "layout.twig" %}
5
+
6
+ {% set foo %}bar{% endset %}
7
+
8
+ {% block var_from_child %}
9
+ {{- foo -}}
10
+ {% endblock %}
11
+ --TEMPLATE(layout.twig)--
12
+ {% set foo %}foo{% endset %}
13
+
14
+ {% block var_from_layout %}
15
+ {{- foo -}}
16
+ {% endblock %}
17
+
18
+ {% block var_from_child %}
19
+ {% endblock %}
20
+ --DATA--
21
+ return []
22
+ --EXPECT--
23
+ foo
24
+ foo
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/mutating.test ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "set" tag
3
+ --TEMPLATE--
4
+ {% set foo = "foo" %}
5
+
6
+ {% set bar %}
7
+ {%- set foo = "bar" -%}
8
+ bar
9
+ {% endset %}
10
+
11
+ {{ foo }}
12
+ {{ bar }}
13
+ --DATA--
14
+ return []
15
+ --EXPECT--
16
+ bar
17
+ bar
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/use_with_parent.test ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "use" tag with a parent block
3
+ --TEMPLATE--
4
+ {% extends "parent.twig" %}
5
+
6
+ {% use 'blocks.twig' %}
7
+
8
+ {% block body %}
9
+ {{ parent() -}}
10
+ CHILD
11
+ {{ block('content') }}
12
+ {% endblock %}
13
+ --TEMPLATE(parent.twig)--
14
+ {% block body %}
15
+ PARENT
16
+ {% endblock %}
17
+ --TEMPLATE(blocks.twig)--
18
+ {% block content 'BLOCK' %}
19
+ --DATA--
20
+ return []
21
+ --EXPECT--
22
+ PARENT
23
+ CHILD
24
+ BLOCK
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/with/globals.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "with" tag
3
+ --TEMPLATE--
4
+ {% with [] only %}
5
+ {{ global }}
6
+ {% endwith %}
7
+ --DATA--
8
+ return []
9
+ --EXPECT--
10
+ global
vendor/twig/twig/test/Twig/Tests/Fixtures/tags/with/iterable.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "with" tag with an iterable expression
3
+ --TEMPLATE--
4
+ {% with vars %}
5
+ {{ foo }}{{ bar }}
6
+ {% endwith %}
7
+ --DATA--
8
+ return ['vars' => new ArrayObject(['foo' => 'baz', 'bar' => 'qux'])]
9
+ --EXPECT--
10
+ bazqux
vendor/twig/twig/test/Twig/Tests/Fixtures/tests/defined_on_complex_expr.test ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ "defined" support for "complex" expressions
3
+ --TEMPLATE--
4
+ {{ (1 + 2) is defined ? 'ok' : 'ko' }}
5
+ --DATA--
6
+ return []
7
+ --EXCEPTION--
8
+ Twig\Error\SyntaxError: The "defined" test only works with simple variables in "index.twig" at line 2.
vendor/twig/twig/test/Twig/Tests/Fixtures/tests/dynamic_test.test ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ dynamic test
3
+ --TEMPLATE--
4
+ {{ 'bar' is test_bar ? '1' :'0' }}
5
+ {{ 'foo' is test_foo ? '1' :'0' }}
6
+ {{ 'bar' is test_foo ? '1' :'0' }}
7
+ {{ 'foo' is test_bar ? '1' :'0' }}
8
+ --DATA--
9
+ return []
10
+ --EXPECT--
11
+ 1
12
+ 1
13
+ 0
14
+ 0
vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_block.test ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Whitespace trimming on tags.
3
+ --TEMPLATE--
4
+ Trim on control tag:
5
+ {% for i in range(1, 9) -%}
6
+ {{ i }}
7
+ {%- endfor %}
8
+
9
+
10
+ Trim on output tag:
11
+ {% for i in range(1, 9) %}
12
+ {{- i -}}
13
+ {% endfor %}
14
+
15
+
16
+ Trim comments:
17
+
18
+ {#- Invisible -#}
19
+
20
+ After the comment.
21
+
22
+ Trim leading space:
23
+ {% if leading %}
24
+
25
+ {{- leading }}
26
+ {% endif %}
27
+
28
+ {%- if leading %}
29
+ {{- leading }}
30
+
31
+ {%- endif %}
32
+
33
+
34
+ Trim trailing space:
35
+ {% if trailing -%}
36
+ {{ trailing -}}
37
+
38
+ {% endif -%}
39
+
40
+ Combined:
41
+
42
+ {%- if both -%}
43
+ <ul>
44
+ <li> {{- both -}} </li>
45
+ </ul>
46
+
47
+ {%- endif -%}
48
+
49
+ end
50
+ --DATA--
51
+ return ['leading' => 'leading space', 'trailing' => 'trailing space', 'both' => 'both']
52
+ --EXPECT--
53
+ Trim on control tag:
54
+ 123456789
55
+
56
+ Trim on output tag:
57
+ 123456789
58
+
59
+ Trim comments:After the comment.
60
+
61
+ Trim leading space:
62
+ leading space
63
+ leading space
64
+
65
+ Trim trailing space:
66
+ trailing spaceCombined:<ul>
67
+ <li>both</li>
68
+ </ul>end
vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_delimiter_as_strings.test ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Whitespace trimming as strings.
3
+ --TEMPLATE--
4
+ {{ 5 * '{#-'|length }}
5
+ {{ '{{-'|length * 5 + '{%-'|length }}
6
+ --DATA--
7
+ return []
8
+ --EXPECT--
9
+ 15
10
+ 18
vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_left.test ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Whitespace trimming on tags (left side).
3
+ --TEMPLATE--
4
+ **{% if true %}
5
+ foo
6
+
7
+ {%- endif %}**
8
+
9
+ **
10
+
11
+ {{- 'foo' }}**
12
+
13
+ **
14
+
15
+
16
+ {#- comment #}**
17
+
18
+ **{% verbatim %}
19
+ foo
20
+
21
+ {%- endverbatim %}**
22
+ --DATA--
23
+ return []
24
+ --EXPECT--
25
+ **foo**
26
+
27
+ **foo**
28
+
29
+ ****
30
+
31
+ **
32
+ foo**
vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_line_left.test ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Line whitespace trimming on tags (left side).
3
+ --TEMPLATE--
4
+ **{% if true %}
5
+ foo
6
+ {%~ endif %}**
7
+
8
+ **
9
+ {{~ 'foo' }}**
10
+
11
+ **
12
+ {#~ comment #}**
13
+
14
+ **{% verbatim %}
15
+ foo
16
+
17
+ {%~ endverbatim %}**
18
+ --DATA--
19
+ return []
20
+ --EXPECT--
21
+ **foo
22
+ **
23
+
24
+ **
25
+ foo**
26
+
27
+ **
28
+ **
29
+
30
+ **
31
+ foo
32
+
33
+ **
vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_line_right.test ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Line whitespace trimming on tags (right side).
3
+ --TEMPLATE--
4
+ **{% if true ~%}
5
+ foo{% endif %}**
6
+
7
+ **{{ 'foo' ~}}
8
+ foo
9
+ **
10
+
11
+ **{# comment ~#}
12
+ foo
13
+ **
14
+
15
+ **{% verbatim ~%}
16
+ foo{% endverbatim %}**
17
+ --DATA--
18
+ return []
19
+ --EXPECT--
20
+ **
21
+ foo**
22
+
23
+ **foo
24
+ foo
25
+ **
26
+
27
+ **
28
+ foo
29
+ **
30
+
31
+ **
32
+ foo**
vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_right.test ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --TEST--
2
+ Whitespace trimming on tags (right side).
3
+ --TEMPLATE--
4
+ **{% if true -%}
5
+
6
+ foo{% endif %}**
7
+
8
+ **{{ 'foo' -}}
9
+
10
+ **
11
+
12
+ **{# comment -#}
13
+
14
+ **
15
+
16
+ **{% verbatim -%}
17
+
18
+ foo{% endverbatim %}**
19
+ --DATA--
20
+ return []
21
+ --EXPECT--
22
+ **foo**
23
+
24
+ **foo**
25
+
26
+ ****
27
+
28
+ **foo**
vendor/twig/twig/test/Twig/Tests/Node/DeprecatedTest.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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
+ use Twig\Environment;
13
+ use Twig\Node\DeprecatedNode;
14
+ use Twig\Node\Expression\ConstantExpression;
15
+ use Twig\Node\Expression\FunctionExpression;
16
+ use Twig\Node\IfNode;
17
+ use Twig\Node\Node;
18
+ use Twig\Test\NodeTestCase;
19
+ use Twig\TwigFunction;
20
+
21
+ class Twig_Tests_Node_DeprecatedTest extends NodeTestCase
22
+ {
23
+ public function testConstructor()
24
+ {
25
+ $expr = new ConstantExpression('foo', 1);
26
+ $node = new DeprecatedNode($expr, 1);
27
+
28
+ $this->assertEquals($expr, $node->getNode('expr'));
29
+ }
30
+
31
+ public function getTests()
32
+ {
33
+ $tests = [];
34
+
35
+ $expr = new ConstantExpression('This section is deprecated', 1);
36
+ $node = new DeprecatedNode($expr, 1, 'deprecated');
37
+ $node->setTemplateName('foo.twig');
38
+
39
+ $tests[] = [$node, <<<EOF
40
+ // line 1
41
+ @trigger_error("This section is deprecated"." (\"foo.twig\" at line 1).", E_USER_DEPRECATED);
42
+ EOF
43
+ ];
44
+
45
+ $t = new Node([
46
+ new ConstantExpression(true, 1),
47
+ new DeprecatedNode($expr, 2, 'deprecated'),
48
+ ], [], 1);
49
+ $node = new IfNode($t, null, 1);
50
+ $node->setTemplateName('foo.twig');
51
+
52
+ $tests[] = [$node, <<<EOF
53
+ // line 1
54
+ if (true) {
55
+ // line 2
56
+ @trigger_error("This section is deprecated"." (\"foo.twig\" at line 2).", E_USER_DEPRECATED);
57
+ }
58
+ EOF
59
+ ];
60
+
61
+ $environment = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
62
+ $environment->addFunction(new TwigFunction('foo', 'foo', []));
63
+
64
+ $expr = new FunctionExpression('foo', new Node(), 1);
65
+ $node = new DeprecatedNode($expr, 1, 'deprecated');
66
+ $node->setTemplateName('foo.twig');
67
+
68
+ $compiler = $this->getCompiler($environment);
69
+ $varName = $compiler->getVarName();
70
+
71
+ $tests[] = [$node, <<<EOF
72
+ // line 1
73
+ \$$varName = foo();
74
+ @trigger_error(\$$varName." (\"foo.twig\" at line 1).", E_USER_DEPRECATED);
75
+ EOF
76
+ , $environment];
77
+
78
+ return $tests;
79
+ }
80
+ }
vendor/twig/twig/test/Twig/Tests/NodeTraverserTest.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
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
+ use Twig\Environment;
13
+ use Twig\Node\Node;
14
+ use Twig\NodeTraverser;
15
+ use Twig\NodeVisitor\NodeVisitorInterface;
16
+
17
+ class Twig_Tests_NodeTraverserTest extends \PHPUnit\Framework\TestCase
18
+ {
19
+ /**
20
+ * @group legacy
21
+ */
22
+ public function testNodeIsNullWhenTraversing()
23
+ {
24
+ $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
25
+ $traverser = new NodeTraverser($env, [new IdentityVisitor()]);
26
+ $n = new Node([new Node([]), null, new Node([])]);
27
+ $this->assertCount(3, $traverser->traverse($n));
28
+ }
29
+ }
30
+
31
+ class IdentityVisitor implements NodeVisitorInterface
32
+ {
33
+ public function enterNode(\Twig_NodeInterface $node, Environment $env)
34
+ {
35
+ return $node;
36
+ }
37
+
38
+ public function leaveNode(\Twig_NodeInterface $node, Environment $env)
39
+ {
40
+ return $node;
41
+ }
42
+
43
+ public function getPriority()
44
+ {
45
+ return 0;
46
+ }
47
+ }