@vituum/vite-plugin-latte 2.0.0-next.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/README.md +1 -1
  2. package/index.js +4 -2
  3. package/package.json +11 -9
  4. package/types/index.d.ts +1 -1
  5. package/vendor/autoload.php +1 -4
  6. package/vendor/composer/InstalledVersions.php +36 -2
  7. package/vendor/composer/autoload_classmap.php +14 -15
  8. package/vendor/composer/autoload_psr4.php +2 -0
  9. package/vendor/composer/autoload_static.php +38 -15
  10. package/vendor/composer/installed.json +32 -22
  11. package/vendor/composer/installed.php +12 -12
  12. package/vendor/composer/platform_check.php +4 -5
  13. package/vendor/latte/latte/bin/latte-lint +10 -3
  14. package/vendor/latte/latte/composer.json +16 -6
  15. package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +13 -38
  16. package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +9 -7
  17. package/vendor/latte/latte/src/Bridges/Tracy/TracyExtension.php +2 -4
  18. package/vendor/latte/latte/src/Bridges/Tracy/dist/panel.phtml +94 -0
  19. package/vendor/latte/latte/src/Bridges/Tracy/dist/tab.phtml +10 -0
  20. package/vendor/latte/latte/src/Latte/Compiler/Block.php +4 -6
  21. package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +67 -86
  22. package/vendor/latte/latte/src/Latte/Compiler/Node.php +6 -3
  23. package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +16 -6
  24. package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +25 -12
  25. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +7 -3
  26. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +5 -4
  27. package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +8 -4
  28. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +7 -15
  29. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +4 -6
  30. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +4 -3
  31. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +37 -67
  32. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ExpressionAttributeNode.php +60 -0
  33. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/TagNode.php +70 -0
  34. package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +4 -3
  35. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +4 -3
  36. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArrayItemNode.php +4 -15
  37. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ClosureUseNode.php +4 -3
  38. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +4 -3
  39. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +4 -3
  40. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +6 -22
  41. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +18 -5
  42. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +18 -7
  43. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AuxiliaryNode.php +5 -4
  44. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +38 -9
  45. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +14 -6
  46. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +4 -3
  47. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +12 -4
  48. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +10 -6
  49. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +7 -6
  50. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +4 -3
  51. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +10 -4
  52. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +14 -5
  53. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InNode.php +4 -3
  54. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +14 -5
  55. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +6 -3
  56. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +6 -3
  57. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +18 -5
  58. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +14 -4
  59. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +14 -6
  60. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +14 -6
  61. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +4 -3
  62. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticMethodCallNode.php +14 -15
  63. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +4 -3
  64. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TemporaryNode.php +7 -6
  65. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +16 -11
  66. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +19 -9
  67. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +4 -3
  68. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +4 -3
  69. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +33 -8
  70. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +4 -3
  71. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/InterpolatedStringPartNode.php +4 -3
  72. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +6 -3
  73. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListItemNode.php +4 -3
  74. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListNode.php +4 -3
  75. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +6 -3
  76. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +29 -41
  77. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +9 -4
  78. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +4 -3
  79. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/OperatorNode.php +27 -0
  80. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +4 -3
  81. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +4 -3
  82. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +9 -6
  83. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +8 -6
  84. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/InterpolatedStringNode.php +9 -5
  85. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +4 -3
  86. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +6 -4
  87. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +4 -3
  88. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +4 -3
  89. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +6 -3
  90. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +4 -3
  91. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/{Expression/NotNode.php → VariadicPlaceholderNode.php} +9 -9
  92. package/vendor/latte/latte/src/Latte/{Essential → Compiler}/Nodes/PrintNode.php +9 -15
  93. package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +7 -3
  94. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +4 -3
  95. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +6 -4
  96. package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +32 -18
  97. package/vendor/latte/latte/src/Latte/Compiler/Position.php +7 -7
  98. package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +72 -104
  99. package/vendor/latte/latte/src/Latte/Compiler/Tag.php +17 -16
  100. package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +11 -8
  101. package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +28 -23
  102. package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +360 -336
  103. package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +49 -38
  104. package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +37 -12
  105. package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +35 -21
  106. package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +121 -71
  107. package/vendor/latte/latte/src/Latte/Compiler/Token.php +79 -70
  108. package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +21 -14
  109. package/vendor/latte/latte/src/Latte/ContentType.php +4 -3
  110. package/vendor/latte/latte/src/Latte/Engine.php +147 -188
  111. package/vendor/latte/latte/src/Latte/Essential/AuxiliaryIterator.php +5 -7
  112. package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +5 -5
  113. package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +5 -4
  114. package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +155 -127
  115. package/vendor/latte/latte/src/Latte/Essential/Filters.php +99 -44
  116. package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +14 -13
  117. package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +5 -6
  118. package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +3 -4
  119. package/vendor/latte/latte/src/Latte/Essential/Nodes/CustomFunctionCallNode.php +46 -0
  120. package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +2 -3
  121. package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +10 -7
  122. package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +3 -4
  123. package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +2 -3
  124. package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +8 -9
  125. package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +3 -5
  126. package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +4 -7
  127. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +6 -5
  128. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +7 -7
  129. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +4 -5
  130. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +7 -6
  131. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +11 -11
  132. package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +5 -6
  133. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +26 -27
  134. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +7 -10
  135. package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +6 -6
  136. package/vendor/latte/latte/src/Latte/Essential/Nodes/JumpNode.php +4 -8
  137. package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +35 -47
  138. package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +4 -5
  139. package/vendor/latte/latte/src/Latte/Essential/Nodes/NElseNode.php +69 -34
  140. package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +9 -33
  141. package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +7 -4
  142. package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +3 -4
  143. package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +2 -3
  144. package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +4 -5
  145. package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +9 -7
  146. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +4 -4
  147. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +3 -4
  148. package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +2 -3
  149. package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +5 -5
  150. package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +4 -5
  151. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +10 -6
  152. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +2 -3
  153. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +3 -4
  154. package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +5 -5
  155. package/vendor/latte/latte/src/Latte/Essential/Passes.php +82 -21
  156. package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +2 -4
  157. package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +1 -3
  158. package/vendor/latte/latte/src/Latte/Essential/Tracer.php +24 -28
  159. package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +14 -14
  160. package/vendor/latte/latte/src/Latte/Extension.php +12 -6
  161. package/vendor/latte/latte/src/Latte/Feature.php +24 -0
  162. package/vendor/latte/latte/src/Latte/Helpers.php +65 -15
  163. package/vendor/latte/latte/src/Latte/Loader.php +1 -9
  164. package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +11 -17
  165. package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +7 -21
  166. package/vendor/latte/latte/src/Latte/Policy.php +4 -3
  167. package/vendor/latte/latte/src/Latte/Runtime/Block.php +2 -4
  168. package/vendor/latte/latte/src/Latte/Runtime/Cache.php +143 -0
  169. package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +5 -6
  170. package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +11 -11
  171. package/vendor/latte/latte/src/Latte/Runtime/FunctionExecutor.php +5 -6
  172. package/vendor/latte/latte/src/Latte/Runtime/Helpers.php +91 -0
  173. package/vendor/latte/latte/src/Latte/Runtime/Html.php +3 -5
  174. package/vendor/latte/latte/src/Latte/Runtime/HtmlHelpers.php +374 -0
  175. package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +1 -3
  176. package/vendor/latte/latte/src/Latte/Runtime/Template.php +162 -182
  177. package/vendor/latte/latte/src/Latte/Runtime/XmlHelpers.php +108 -0
  178. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +12 -4
  179. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +15 -5
  180. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +4 -3
  181. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +5 -6
  182. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticMethodCallNode.php +14 -4
  183. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +4 -3
  184. package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +8 -6
  185. package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +16 -12
  186. package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +18 -16
  187. package/vendor/latte/latte/src/Latte/attributes.php +7 -3
  188. package/vendor/latte/latte/src/Latte/exceptions.php +52 -6
  189. package/vendor/latte/latte/src/Tools/Linter.php +74 -28
  190. package/vendor/latte/latte/src/Tools/LinterExtension.php +176 -0
  191. package/vendor/nette/utils/composer.json +15 -5
  192. package/vendor/nette/utils/readme.md +1 -1
  193. package/vendor/nette/utils/src/HtmlStringable.php +4 -1
  194. package/vendor/nette/utils/src/Iterators/CachingIterator.php +10 -25
  195. package/vendor/nette/utils/src/Iterators/Mapper.php +2 -3
  196. package/vendor/nette/utils/src/SmartObject.php +3 -0
  197. package/vendor/nette/utils/src/StaticClass.php +1 -11
  198. package/vendor/nette/utils/src/Translator.php +1 -1
  199. package/vendor/nette/utils/src/Utils/ArrayHash.php +6 -10
  200. package/vendor/nette/utils/src/Utils/ArrayList.php +8 -12
  201. package/vendor/nette/utils/src/Utils/Arrays.php +38 -18
  202. package/vendor/nette/utils/src/Utils/Callback.php +13 -8
  203. package/vendor/nette/utils/src/Utils/DateTime.php +95 -26
  204. package/vendor/nette/utils/src/Utils/FileInfo.php +6 -7
  205. package/vendor/nette/utils/src/Utils/FileSystem.php +10 -5
  206. package/vendor/nette/utils/src/Utils/Finder.php +31 -12
  207. package/vendor/nette/utils/src/Utils/Floats.php +1 -0
  208. package/vendor/nette/utils/src/Utils/Helpers.php +22 -2
  209. package/vendor/nette/utils/src/Utils/Html.php +130 -127
  210. package/vendor/nette/utils/src/Utils/Image.php +80 -60
  211. package/vendor/nette/utils/src/Utils/ImageColor.php +5 -0
  212. package/vendor/nette/utils/src/Utils/ImageType.php +2 -0
  213. package/vendor/nette/utils/src/Utils/Iterables.php +41 -7
  214. package/vendor/nette/utils/src/Utils/Json.php +2 -0
  215. package/vendor/nette/utils/src/Utils/ObjectHelpers.php +2 -0
  216. package/vendor/nette/utils/src/Utils/Paginator.php +10 -43
  217. package/vendor/nette/utils/src/Utils/Random.php +2 -0
  218. package/vendor/nette/utils/src/Utils/Reflection.php +22 -15
  219. package/vendor/nette/utils/src/Utils/ReflectionMethod.php +6 -1
  220. package/vendor/nette/utils/src/Utils/Strings.php +62 -57
  221. package/vendor/nette/utils/src/Utils/Type.php +91 -42
  222. package/vendor/nette/utils/src/Utils/Validators.php +9 -7
  223. package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.panel.phtml +0 -101
  224. package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.tab.phtml +0 -15
  225. package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +0 -129
  226. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ErrorSuppressNode.php +0 -36
  227. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallableNode.php +0 -39
  228. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallableNode.php +0 -42
  229. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticMethodCallableNode.php +0 -57
  230. package/vendor/latte/latte/src/Latte/PositionAwareException.php +0 -47
  231. package/vendor/latte/latte/src/Latte/Runtime/Filters.php +0 -283
  232. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallableNode.php +0 -29
  233. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallableNode.php +0 -30
  234. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticMethodCallableNode.php +0 -30
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Essential;
11
9
 
12
10
  use Latte;
@@ -14,7 +12,8 @@ use Latte\ContentType;
14
12
  use Latte\Runtime\FilterInfo;
15
13
  use Latte\Runtime\Html;
16
14
  use Stringable;
17
- use function is_array, is_string, count, strlen;
15
+ use function abs, array_combine, array_fill_keys, array_key_last, array_map, array_rand, array_reverse, array_search, array_slice, base64_encode, ceil, count, end, explode, extension_loaded, finfo_buffer, finfo_open, floor, func_num_args, htmlspecialchars, http_build_query, iconv, iconv_strlen, iconv_substr, implode, is_array, is_int, is_numeric, is_string, iterator_count, iterator_to_array, key, ltrim, max, mb_convert_case, mb_strlen, mb_strtolower, mb_strtoupper, mb_substr, min, nl2br, number_format, preg_last_error, preg_last_error_msg, preg_match, preg_quote, preg_replace, preg_replace_callback, preg_split, reset, round, rtrim, str_repeat, str_replace, strip_tags, strlen, strrev, strtr, substr, trim, uasort, uksort, urlencode, utf8_decode;
16
+ use const ENT_NOQUOTES, ENT_SUBSTITUTE, FILEINFO_MIME_TYPE, MB_CASE_TITLE, PHP_OUTPUT_HANDLER_FINAL, PHP_OUTPUT_HANDLER_START, PREG_SPLIT_NO_EMPTY;
18
17
 
19
18
 
20
19
  /**
@@ -29,18 +28,18 @@ final class Filters
29
28
  /**
30
29
  * Converts HTML to plain text.
31
30
  */
32
- public static function stripHtml(FilterInfo $info, $s): string
31
+ public static function stripHtml(FilterInfo $info, string|Stringable|null $s): string
33
32
  {
34
33
  $info->validate([null, 'html', 'html/attr', 'xml', 'xml/attr'], __FUNCTION__);
35
34
  $info->contentType = ContentType::Text;
36
- return Latte\Runtime\Filters::convertHtmlToText((string) $s);
35
+ return Latte\Runtime\HtmlHelpers::convertHtmlToText((string) $s);
37
36
  }
38
37
 
39
38
 
40
39
  /**
41
40
  * Removes tags from HTML (but remains HTML entities).
42
41
  */
43
- public static function stripTags(FilterInfo $info, $s): string
42
+ public static function stripTags(FilterInfo $info, string|Stringable|null $s): string
44
43
  {
45
44
  $info->contentType ??= ContentType::Html;
46
45
  $info->validate(['html', 'html/attr', 'xml', 'xml/attr'], __FUNCTION__);
@@ -148,6 +147,7 @@ final class Filters
148
147
 
149
148
  /**
150
149
  * Splits a string by a string.
150
+ * @return list<string>
151
151
  */
152
152
  public static function explode(string $value, string $separator = ''): array
153
153
  {
@@ -160,7 +160,7 @@ final class Filters
160
160
  /**
161
161
  * Repeats text.
162
162
  */
163
- public static function repeat(FilterInfo $info, $s, int $count): string
163
+ public static function repeat(FilterInfo $info, string|Stringable|null $s, int $count): string
164
164
  {
165
165
  return str_repeat((string) $s, $count);
166
166
  }
@@ -169,9 +169,11 @@ final class Filters
169
169
  /**
170
170
  * Date/time formatting.
171
171
  */
172
- public static function date(string|int|\DateTimeInterface|\DateInterval|null $time, ?string $format = null): ?string
172
+ public static function date(
173
+ string|int|\DateTimeInterface|\DateInterval|null $time,
174
+ string $format = "j.\u{a0}n.\u{a0}Y",
175
+ ): ?string
173
176
  {
174
- $format ??= Latte\Runtime\Filters::$dateFormat;
175
177
  if ($time == null) { // intentionally ==
176
178
  return null;
177
179
  } elseif ($time instanceof \DateInterval) {
@@ -182,14 +184,6 @@ final class Filters
182
184
  $time = new \DateTime($time);
183
185
  }
184
186
 
185
- if (str_contains($format, '%')) {
186
- if (PHP_VERSION_ID >= 80100) {
187
- trigger_error("Function strftime() used by filter |date is deprecated since PHP 8.1, use format without % characters like 'Y-m-d'.", E_USER_DEPRECATED);
188
- }
189
-
190
- return @strftime($format, $time->format('U') + 0);
191
- }
192
-
193
187
  return $time->format($format);
194
188
  }
195
189
 
@@ -221,7 +215,8 @@ final class Filters
221
215
  if ($format === null) {
222
216
  $xlt = ['' => \IntlDateFormatter::NONE, 'full' => \IntlDateFormatter::FULL, 'long' => \IntlDateFormatter::LONG, 'medium' => \IntlDateFormatter::MEDIUM, 'short' => \IntlDateFormatter::SHORT,
223
217
  'relative-full' => \IntlDateFormatter::RELATIVE_FULL, 'relative-long' => \IntlDateFormatter::RELATIVE_LONG, 'relative-medium' => \IntlDateFormatter::RELATIVE_MEDIUM, 'relative-short' => \IntlDateFormatter::RELATIVE_SHORT];
224
- $date ??= $time === null ? 'long' : null;
218
+ $time ??= '';
219
+ $date ??= $time === '' ? 'long' : '';
225
220
  $formatter = new \IntlDateFormatter($this->locale, $xlt[$date], $xlt[$time]);
226
221
  } else {
227
222
  $formatter = new \IntlDateFormatter($this->locale, pattern: (new \IntlDatePatternGenerator($this->locale))->getBestPattern($format));
@@ -246,6 +241,9 @@ final class Filters
246
241
  if (is_int($patternOrDecimals) && $patternOrDecimals < 0) {
247
242
  throw new Latte\RuntimeException('Filter |number: the number of decimal must not be negative');
248
243
  } elseif ($this->locale === null || func_num_args() > 2) {
244
+ if (is_string($patternOrDecimals)) {
245
+ throw new Latte\RuntimeException('Filter |number: using a pattern requires setting a locale via Engine::setLocale().');
246
+ }
249
247
  return number_format($number, $patternOrDecimals, $decimalSeparator, $thousandsSeparator);
250
248
  }
251
249
 
@@ -288,15 +286,16 @@ final class Filters
288
286
 
289
287
  /**
290
288
  * Performs a search and replace.
289
+ * @param string|array<string, string>|array<string> $search
290
+ * @param string|array<string>|null $replace
291
291
  */
292
292
  public static function replace(
293
293
  FilterInfo $info,
294
- string|array $subject,
294
+ string $subject,
295
295
  string|array $search,
296
296
  string|array|null $replace = null,
297
297
  ): string
298
298
  {
299
- $subject = (string) $subject;
300
299
  if (is_array($search)) {
301
300
  if (is_array($replace)) {
302
301
  return strtr($subject, array_combine($search, $replace));
@@ -317,7 +316,7 @@ final class Filters
317
316
  public static function replaceRe(string $subject, string $pattern, string $replacement = ''): string
318
317
  {
319
318
  $res = preg_replace($pattern, $replacement, $subject);
320
- if (preg_last_error()) {
319
+ if (preg_last_error() || $res === null) {
321
320
  throw new Latte\RuntimeException(preg_last_error_msg());
322
321
  }
323
322
 
@@ -330,15 +329,23 @@ final class Filters
330
329
  */
331
330
  public static function dataStream(string $data, ?string $type = null): string
332
331
  {
333
- $type ??= finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);
332
+ if ($type === null) {
333
+ $finfo = finfo_open(FILEINFO_MIME_TYPE);
334
+ if ($finfo) {
335
+ $type = finfo_buffer($finfo, $data) ?: null;
336
+ }
337
+ }
334
338
  return 'data:' . ($type ? "$type;" : '') . 'base64,' . base64_encode($data);
335
339
  }
336
340
 
337
341
 
342
+ /**
343
+ * Converts newlines to HTML <br> tags.
344
+ */
338
345
  public static function breaklines(string|Stringable|null $s): Html
339
346
  {
340
347
  $s = htmlspecialchars((string) $s, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
341
- return new Html(nl2br($s, false));
348
+ return new Html(nl2br($s, use_xhtml: false));
342
349
  }
343
350
 
344
351
 
@@ -350,7 +357,7 @@ final class Filters
350
357
  $s = (string) $s;
351
358
  return match (true) {
352
359
  extension_loaded('mbstring') => mb_substr($s, $start, $length, 'UTF-8'),
353
- extension_loaded('iconv') => iconv_substr($s, $start, $length, 'UTF-8'),
360
+ extension_loaded('iconv') => (string) iconv_substr($s, $start, $length, 'UTF-8'),
354
361
  default => throw new Latte\RuntimeException("Filter |substr requires 'mbstring' or 'iconv' extension."),
355
362
  };
356
363
  }
@@ -382,7 +389,7 @@ final class Filters
382
389
  /**
383
390
  * Convert to lower case.
384
391
  */
385
- public static function lower($s): string
392
+ public static function lower(string|Stringable|null $s): string
386
393
  {
387
394
  return mb_strtolower((string) $s, 'UTF-8');
388
395
  }
@@ -391,16 +398,26 @@ final class Filters
391
398
  /**
392
399
  * Convert to upper case.
393
400
  */
394
- public static function upper($s): string
401
+ public static function upper(string|Stringable|null $s): string
395
402
  {
396
403
  return mb_strtoupper((string) $s, 'UTF-8');
397
404
  }
398
405
 
399
406
 
407
+ /**
408
+ * Convert first character to lower case.
409
+ */
410
+ public static function firstLower(string|Stringable|null $s): string
411
+ {
412
+ $s = (string) $s;
413
+ return self::lower(self::substring($s, 0, 1)) . self::substring($s, 1);
414
+ }
415
+
416
+
400
417
  /**
401
418
  * Convert first character to upper case.
402
419
  */
403
- public static function firstUpper($s): string
420
+ public static function firstUpper(string|Stringable|null $s): string
404
421
  {
405
422
  $s = (string) $s;
406
423
  return self::upper(self::substring($s, 0, 1)) . self::substring($s, 1);
@@ -410,7 +427,7 @@ final class Filters
410
427
  /**
411
428
  * Capitalize string.
412
429
  */
413
- public static function capitalize($s): string
430
+ public static function capitalize(string|Stringable|null $s): string
414
431
  {
415
432
  return mb_convert_case((string) $s, MB_CASE_TITLE, 'UTF-8');
416
433
  }
@@ -418,10 +435,11 @@ final class Filters
418
435
 
419
436
  /**
420
437
  * Returns length of string or iterable.
438
+ * @param array<mixed>|\Countable|\Traversable<mixed>|string $val
421
439
  */
422
440
  public static function length(array|\Countable|\Traversable|string $val): int
423
441
  {
424
- if (is_array($val) || $val instanceof \Countable) {
442
+ if (is_countable($val)) {
425
443
  return count($val);
426
444
  } elseif ($val instanceof \Traversable) {
427
445
  return iterator_count($val);
@@ -435,7 +453,7 @@ final class Filters
435
453
  {
436
454
  return match (true) {
437
455
  extension_loaded('mbstring') => mb_strlen($s, 'UTF-8'),
438
- extension_loaded('iconv') => iconv_strlen($s, 'UTF-8'),
456
+ extension_loaded('iconv') => (int) iconv_strlen($s, 'UTF-8'),
439
457
  default => strlen(@utf8_decode($s)), // deprecated
440
458
  };
441
459
  }
@@ -448,7 +466,7 @@ final class Filters
448
466
  {
449
467
  $charlist = preg_quote($charlist, '#');
450
468
  $s = preg_replace('#^[' . $charlist . ']+|[' . $charlist . ']+$#Du', '', (string) $s);
451
- if (preg_last_error()) {
469
+ if (preg_last_error() || $s === null) {
452
470
  throw new Latte\RuntimeException(preg_last_error_msg());
453
471
  }
454
472
 
@@ -459,7 +477,7 @@ final class Filters
459
477
  /**
460
478
  * Pad a string to a certain length with another string.
461
479
  */
462
- public static function padLeft($s, int $length, string $append = ' '): string
480
+ public static function padLeft(string|Stringable|null $s, int $length, string $append = ' '): string
463
481
  {
464
482
  $s = (string) $s;
465
483
  $length = max(0, $length - self::strLength($s));
@@ -471,7 +489,7 @@ final class Filters
471
489
  /**
472
490
  * Pad a string to a certain length with another string.
473
491
  */
474
- public static function padRight($s, int $length, string $append = ' '): string
492
+ public static function padRight(string|Stringable|null $s, int $length, string $append = ' '): string
475
493
  {
476
494
  $s = (string) $s;
477
495
  $length = max(0, $length - self::strLength($s));
@@ -482,23 +500,25 @@ final class Filters
482
500
 
483
501
  /**
484
502
  * Reverses string or array.
503
+ * @template K
504
+ * @template V
505
+ * @param iterable<K, V>|string $val
506
+ * @return ($val is string ? string : array<K, V>)
485
507
  */
486
508
  public static function reverse(string|iterable $val, bool $preserveKeys = false): string|array
487
509
  {
488
- if (is_array($val)) {
489
- return array_reverse($val, $preserveKeys);
490
- } elseif ($val instanceof \Traversable) {
491
- return array_reverse(iterator_to_array($val), $preserveKeys);
492
- } else {
493
- return iconv('UTF-32LE', 'UTF-8', strrev(iconv('UTF-8', 'UTF-32BE', (string) $val)));
494
- }
510
+ return is_string($val)
511
+ ? (string) iconv('UTF-32LE', 'UTF-8', strrev((string) iconv('UTF-8', 'UTF-32BE', $val)))
512
+ : array_reverse(iterator_to_array($val), $preserveKeys);
495
513
  }
496
514
 
497
515
 
498
516
  /**
499
517
  * Chunks items by returning an array of arrays with the given number of items.
518
+ * @param iterable<mixed> $list
519
+ * @return \Generator<int, array<mixed>>
500
520
  */
501
- public static function batch(iterable $list, int $length, $rest = null): \Generator
521
+ public static function batch(iterable $list, int $length, mixed $rest = null): \Generator
502
522
  {
503
523
  $batch = [];
504
524
  foreach ($list as $key => $value) {
@@ -526,6 +546,9 @@ final class Filters
526
546
  * @template K
527
547
  * @template V
528
548
  * @param iterable<K, V> $data
549
+ * @param ?(\Closure(V, V): int) $comparison
550
+ * @param string|int|(\Closure(V): mixed)|null $by
551
+ * @param string|int|(\Closure(K): mixed)|bool $byKey
529
552
  * @return iterable<K, V>
530
553
  */
531
554
  public function sort(
@@ -578,6 +601,7 @@ final class Filters
578
601
  * @template K
579
602
  * @template V
580
603
  * @param iterable<K, V> $data
604
+ * @param string|int|(\Closure(V, K): mixed) $by
581
605
  * @return iterable<iterable<K, V>>
582
606
  */
583
607
  public static function group(iterable $data, string|int|\Closure $by): iterable
@@ -588,7 +612,7 @@ final class Filters
588
612
  foreach ($data as $k => $v) {
589
613
  $groupKey = $fn($v, $k);
590
614
  if (!$groups || $prevKey !== $groupKey) {
591
- $index = array_search($groupKey, $keys, true);
615
+ $index = array_search($groupKey, $keys, strict: true);
592
616
  if ($index === false) {
593
617
  $index = count($keys);
594
618
  $keys[$index] = $groupKey;
@@ -639,6 +663,7 @@ final class Filters
639
663
 
640
664
  /**
641
665
  * Generates URL-encoded query string
666
+ * @param string|array<mixed> $data
642
667
  */
643
668
  public static function query(string|array $data): string
644
669
  {
@@ -677,6 +702,8 @@ final class Filters
677
702
 
678
703
  /**
679
704
  * Returns the first element in an array or character in a string, or null if none.
705
+ * @param string|iterable<mixed> $value
706
+ * @return ($value is string ? string : mixed)
680
707
  */
681
708
  public static function first(string|iterable $value): mixed
682
709
  {
@@ -694,17 +721,21 @@ final class Filters
694
721
 
695
722
  /**
696
723
  * Returns the last element in an array or character in a string, or null if none.
724
+ * @param string|array<mixed> $value
725
+ * @return ($value is string ? string : mixed)
697
726
  */
698
727
  public static function last(string|array $value): mixed
699
728
  {
700
729
  return is_array($value)
701
- ? ($value[array_key_last($value)] ?? null)
730
+ ? ($value ? $value[array_key_last($value)] : null)
702
731
  : self::substring($value, -1);
703
732
  }
704
733
 
705
734
 
706
735
  /**
707
736
  * Extracts a slice of an array or string.
737
+ * @param string|array<mixed> $value
738
+ * @return ($value is string ? string : array<mixed>)
708
739
  */
709
740
  public static function slice(
710
741
  string|array $value,
@@ -719,18 +750,27 @@ final class Filters
719
750
  }
720
751
 
721
752
 
753
+ /**
754
+ * Rounds number to specified precision.
755
+ */
722
756
  public static function round(float $value, int $precision = 0): float
723
757
  {
724
758
  return round($value, $precision);
725
759
  }
726
760
 
727
761
 
762
+ /**
763
+ * Rounds number down to specified precision.
764
+ */
728
765
  public static function floor(float $value, int $precision = 0): float
729
766
  {
730
767
  return floor($value * 10 ** $precision) / 10 ** $precision;
731
768
  }
732
769
 
733
770
 
771
+ /**
772
+ * Rounds number up to specified precision.
773
+ */
734
774
  public static function ceil(float $value, int $precision = 0): float
735
775
  {
736
776
  return ceil($value * 10 ** $precision) / 10 ** $precision;
@@ -739,6 +779,8 @@ final class Filters
739
779
 
740
780
  /**
741
781
  * Picks random element/char.
782
+ * @param string|array<mixed> $values
783
+ * @return ($values is string ? string : mixed)
742
784
  */
743
785
  public static function random(string|array $values): mixed
744
786
  {
@@ -750,4 +792,17 @@ final class Filters
750
792
  ? $values[array_rand($values, 1)]
751
793
  : null;
752
794
  }
795
+
796
+
797
+ /**
798
+ * Sanitizes string for use inside href attribute.
799
+ */
800
+ public static function checkUrl(mixed $s): string
801
+ {
802
+ $s = $s instanceof Latte\Runtime\HtmlStringable
803
+ ? Latte\Runtime\HtmlHelpers::convertHtmlToText((string) $s)
804
+ : (string) $s;
805
+
806
+ return preg_match('~^(?:(?:https?|ftp)://[^@]+(?:/.*)?|(?:mailto|tel|sms):.+|[/?#].*|[^:]+)$~Di', $s) ? $s : '';
807
+ }
753
808
  }
@@ -1,20 +1,16 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Essential\Nodes;
11
9
 
12
10
  use Latte\CompileException;
13
11
  use Latte\Compiler\Block;
14
12
  use Latte\Compiler\Escaper;
15
13
  use Latte\Compiler\Nodes\AreaNode;
16
- use Latte\Compiler\Nodes\Php\Expression\AssignNode;
17
- use Latte\Compiler\Nodes\Php\Expression\VariableNode;
18
14
  use Latte\Compiler\Nodes\Php\ModifierNode;
19
15
  use Latte\Compiler\Nodes\Php\Scalar;
20
16
  use Latte\Compiler\Nodes\StatementNode;
@@ -26,7 +22,8 @@ use Latte\Runtime\Template;
26
22
 
27
23
 
28
24
  /**
29
- * {block [local] [name]}
25
+ * {block [local] name} ... {/block}
26
+ * {block|filter} ... {/block} (anonymous filter block)
30
27
  */
31
28
  class BlockNode extends StatementNode
32
29
  {
@@ -35,12 +32,13 @@ class BlockNode extends StatementNode
35
32
  public AreaNode $content;
36
33
 
37
34
 
38
- /** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static|AreaNode> */
35
+ /** @return \Generator<int, ?list<string>, array{AreaNode, ?Tag}, static> */
39
36
  public static function create(Tag $tag, TemplateParser $parser): \Generator
40
37
  {
41
38
  $tag->outputMode = $tag::OutputRemoveIndentation;
42
39
  $stream = $tag->parser->stream;
43
40
  $node = $tag->node = new static;
41
+ $name = null;
44
42
 
45
43
  if (!$stream->is('|', Token::End)) {
46
44
  $layer = $tag->parser->tryConsumeTokenBeforeUnquotedString('local')
@@ -56,10 +54,11 @@ class BlockNode extends StatementNode
56
54
  }
57
55
 
58
56
  $node->modifier = $tag->parser->parseModifier();
59
- $node->modifier->escape = (bool) $node->modifier->filters;
60
- if ($node->modifier->hasFilter('noescape') && count($node->modifier->filters) === 1) {
57
+ $noEscape = $node->modifier->removeFilter('noescape');
58
+ if ($noEscape && !$node->modifier->filters) {
61
59
  throw new CompileException('Filter |noescape is not expected here.', $tag->position);
62
60
  }
61
+ $node->modifier->escape = $node->modifier->filters && !$noEscape;
63
62
 
64
63
  [$node->content, $endTag] = yield;
65
64
 
@@ -109,17 +108,18 @@ class BlockNode extends StatementNode
109
108
 
110
109
  private function printStatic(PrintContext $context): string
111
110
  {
111
+ assert($this->block !== null);
112
112
  $this->modifier->escape = $this->modifier->escape || $context->getEscaper()->getState() === Escaper::HtmlAttribute;
113
113
  $context->addBlock($this->block);
114
114
  $this->block->content = $this->content->print($context); // must be compiled after is added
115
115
 
116
116
  return $context->format(
117
- '$this->renderBlock(%node, get_defined_vars()'
117
+ '$this->renderBlock(%raw, get_defined_vars()'
118
118
  . ($this->modifier->filters || $this->modifier->escape
119
119
  ? ', function ($s, $type) { $ʟ_fi = new LR\FilterInfo($type); return %modifyContent($s); }'
120
120
  : '')
121
121
  . ') %2.line;',
122
- $this->block->name,
122
+ $context->ensureString($this->block->name, 'Block name'),
123
123
  $this->modifier,
124
124
  $this->position,
125
125
  );
@@ -128,19 +128,20 @@ class BlockNode extends StatementNode
128
128
 
129
129
  private function printDynamic(PrintContext $context): string
130
130
  {
131
+ assert($this->block !== null);
131
132
  $context->addBlock($this->block);
132
133
  $this->block->content = $this->content->print($context); // must be compiled after is added
133
134
  $escaper = $context->getEscaper();
134
135
  $this->modifier->escape = $this->modifier->escape || $escaper->getState() === Escaper::HtmlAttribute;
135
136
 
136
137
  return $context->format(
137
- '$this->addBlock(%node, %dump, [[$this, %dump]], %dump);
138
+ '$this->addBlock($ʟ_nm = %raw, %dump, [$this->%raw(...)], %dump);
138
139
  $this->renderBlock($ʟ_nm, get_defined_vars()'
139
140
  . ($this->modifier->filters || $this->modifier->escape
140
141
  ? ', function ($s, $type) { $ʟ_fi = new LR\FilterInfo($type); return %modifyContent($s); }'
141
142
  : '')
142
143
  . ');',
143
- new AssignNode(new VariableNode('ʟ_nm'), $this->block->name),
144
+ $context->ensureString($this->block->name, 'Block name'),
144
145
  $escaper->export(),
145
146
  $this->block->method,
146
147
  $this->block->layer,
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Essential\Nodes;
11
9
 
12
10
  use Latte\CompileException;
@@ -20,7 +18,8 @@ use Latte\Compiler\Tag;
20
18
 
21
19
 
22
20
  /**
23
- * {capture $variable}
21
+ * {capture $var} ... {/capture}
22
+ * Captures block output into variable.
24
23
  */
25
24
  class CaptureNode extends StatementNode
26
25
  {
@@ -29,7 +28,7 @@ class CaptureNode extends StatementNode
29
28
  public AreaNode $content;
30
29
 
31
30
 
32
- /** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static> */
31
+ /** @return \Generator<int, ?list<string>, array{AreaNode, ?Tag}, static> */
33
32
  public static function create(Tag $tag): \Generator
34
33
  {
35
34
  $tag->expectArguments();
@@ -37,7 +36,7 @@ class CaptureNode extends StatementNode
37
36
  if (!$variable->isWritable()) {
38
37
  $text = '';
39
38
  $i = 0;
40
- while ($token = $tag->parser->stream->peek(--$i)) {
39
+ while ($token = $tag->parser->stream->tryPeek(--$i)) {
41
40
  $text = $token->text . $text;
42
41
  }
43
42
 
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Essential\Nodes;
11
9
 
12
10
  use Latte\CompileException;
@@ -18,7 +16,8 @@ use Latte\ContentType;
18
16
 
19
17
 
20
18
  /**
21
- * {contentType ...}
19
+ * {contentType html|xml|js|css|text|...}
20
+ * Switches escaping mode and optionally sends HTTP header.
22
21
  */
23
22
  class ContentTypeNode extends StatementNode
24
23
  {
@@ -0,0 +1,46 @@
1
+ <?php declare(strict_types=1);
2
+
3
+ /**
4
+ * This file is part of the Latte (https://latte.nette.org)
5
+ * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
+ */
7
+
8
+ namespace Latte\Essential\Nodes;
9
+
10
+ use Latte\Compiler\Nodes\Php;
11
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
12
+ use Latte\Compiler\Position;
13
+ use Latte\Compiler\PrintContext;
14
+ use Latte\Helpers;
15
+
16
+
17
+ /**
18
+ * Wrapper for custom function calls in Latte expressions.
19
+ */
20
+ class CustomFunctionCallNode extends ExpressionNode
21
+ {
22
+ public function __construct(
23
+ public Php\NameNode $name,
24
+ /** @var array<Php\ArgumentNode> */
25
+ public array $args = [],
26
+ public ?Position $position = null,
27
+ ) {
28
+ (function (Php\ArgumentNode ...$args) {})(...$args);
29
+ }
30
+
31
+
32
+ public function print(PrintContext $context): string
33
+ {
34
+ return '($this->global->fn->' . $this->name . ')($this, ' . $context->implode($this->args) . ')';
35
+ }
36
+
37
+
38
+ public function &getIterator(): \Generator
39
+ {
40
+ yield $this->name;
41
+ foreach ($this->args as &$item) {
42
+ yield $item;
43
+ }
44
+ Helpers::removeNulls($this->args);
45
+ }
46
+ }
@@ -1,12 +1,10 @@
1
- <?php
1
+ <?php declare(strict_types=1);
2
2
 
3
3
  /**
4
4
  * This file is part of the Latte (https://latte.nette.org)
5
5
  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
6
  */
7
7
 
8
- declare(strict_types=1);
9
-
10
8
  namespace Latte\Essential\Nodes;
11
9
 
12
10
  use Latte\Compiler\Nodes\Php\ExpressionNode;
@@ -17,6 +15,7 @@ use Latte\Compiler\Tag;
17
15
 
18
16
  /**
19
17
  * {debugbreak [$cond]}
18
+ * Triggers debugger breakpoint.
20
19
  */
21
20
  class DebugbreakNode extends StatementNode
22
21
  {