@vituum/vite-plugin-latte 0.1.8

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 (201) hide show
  1. package/README.md +39 -0
  2. package/handler.js +9 -0
  3. package/index.js +138 -0
  4. package/index.php +173 -0
  5. package/latte/AssetFilter.php +11 -0
  6. package/latte/FetchFunction.php +28 -0
  7. package/latte/IconFilter.php +14 -0
  8. package/latte/JsonTag.php +64 -0
  9. package/latte/PlaceholderFunction.php +11 -0
  10. package/latte/RandomColorFunction.php +14 -0
  11. package/latte/TelFilter.php +22 -0
  12. package/package.json +35 -0
  13. package/vendor/autoload.php +7 -0
  14. package/vendor/bin/latte-lint +107 -0
  15. package/vendor/composer/ClassLoader.php +572 -0
  16. package/vendor/composer/InstalledVersions.php +350 -0
  17. package/vendor/composer/LICENSE +21 -0
  18. package/vendor/composer/autoload_classmap.php +183 -0
  19. package/vendor/composer/autoload_namespaces.php +9 -0
  20. package/vendor/composer/autoload_psr4.php +9 -0
  21. package/vendor/composer/autoload_real.php +57 -0
  22. package/vendor/composer/autoload_static.php +193 -0
  23. package/vendor/composer/installed.json +93 -0
  24. package/vendor/composer/installed.php +32 -0
  25. package/vendor/composer/platform_check.php +26 -0
  26. package/vendor/latte/latte/bin/latte-lint +29 -0
  27. package/vendor/latte/latte/composer.json +53 -0
  28. package/vendor/latte/latte/license.md +60 -0
  29. package/vendor/latte/latte/ncs.php +14 -0
  30. package/vendor/latte/latte/ncs.xml +9 -0
  31. package/vendor/latte/latte/readme.md +21 -0
  32. package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +114 -0
  33. package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +99 -0
  34. package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.panel.phtml +98 -0
  35. package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.tab.phtml +15 -0
  36. package/vendor/latte/latte/src/Latte/Compiler/Block.php +44 -0
  37. package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +244 -0
  38. package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +128 -0
  39. package/vendor/latte/latte/src/Latte/Compiler/Node.php +28 -0
  40. package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +132 -0
  41. package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +77 -0
  42. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +17 -0
  43. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +27 -0
  44. package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +59 -0
  45. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +48 -0
  46. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +46 -0
  47. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +39 -0
  48. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +129 -0
  49. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/QuotedValue.php +53 -0
  50. package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +21 -0
  51. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +45 -0
  52. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +17 -0
  53. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +41 -0
  54. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayItemNode.php +52 -0
  55. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +94 -0
  56. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +39 -0
  57. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +45 -0
  58. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +65 -0
  59. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +43 -0
  60. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +42 -0
  61. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +36 -0
  62. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +73 -0
  63. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureUseNode.php +37 -0
  64. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +37 -0
  65. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +36 -0
  66. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ErrorSuppressNode.php +36 -0
  67. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +39 -0
  68. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +45 -0
  69. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallableNode.php +39 -0
  70. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InRangeNode.php +42 -0
  71. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +40 -0
  72. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +40 -0
  73. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +49 -0
  74. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +50 -0
  75. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallableNode.php +42 -0
  76. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +45 -0
  77. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NotNode.php +36 -0
  78. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +43 -0
  79. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +43 -0
  80. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +42 -0
  81. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallNode.php +55 -0
  82. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallableNode.php +47 -0
  83. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +42 -0
  84. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +50 -0
  85. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +45 -0
  86. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +40 -0
  87. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +17 -0
  88. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +67 -0
  89. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +36 -0
  90. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +39 -0
  91. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +45 -0
  92. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +107 -0
  93. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +89 -0
  94. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +35 -0
  95. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +54 -0
  96. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +30 -0
  97. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringNode.php +80 -0
  98. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringPartNode.php +30 -0
  99. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +63 -0
  100. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +70 -0
  101. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +29 -0
  102. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +40 -0
  103. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +15 -0
  104. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +29 -0
  105. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +39 -0
  106. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +21 -0
  107. package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +15 -0
  108. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +34 -0
  109. package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +37 -0
  110. package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +227 -0
  111. package/vendor/latte/latte/src/Latte/Compiler/Position.php +43 -0
  112. package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +334 -0
  113. package/vendor/latte/latte/src/Latte/Compiler/Tag.php +117 -0
  114. package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +399 -0
  115. package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +388 -0
  116. package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +580 -0
  117. package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +206 -0
  118. package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +391 -0
  119. package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +448 -0
  120. package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +506 -0
  121. package/vendor/latte/latte/src/Latte/Compiler/Token.php +259 -0
  122. package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +151 -0
  123. package/vendor/latte/latte/src/Latte/ContentType.php +22 -0
  124. package/vendor/latte/latte/src/Latte/Engine.php +591 -0
  125. package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +160 -0
  126. package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +232 -0
  127. package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +232 -0
  128. package/vendor/latte/latte/src/Latte/Essential/Filters.php +591 -0
  129. package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +161 -0
  130. package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +98 -0
  131. package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +74 -0
  132. package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +53 -0
  133. package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +134 -0
  134. package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +49 -0
  135. package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +58 -0
  136. package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +125 -0
  137. package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +60 -0
  138. package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +81 -0
  139. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +91 -0
  140. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +155 -0
  141. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +141 -0
  142. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +82 -0
  143. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +180 -0
  144. package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +49 -0
  145. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +140 -0
  146. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +81 -0
  147. package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +94 -0
  148. package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +105 -0
  149. package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +54 -0
  150. package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +79 -0
  151. package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +84 -0
  152. package/vendor/latte/latte/src/Latte/Essential/Nodes/PrintNode.php +70 -0
  153. package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +46 -0
  154. package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +37 -0
  155. package/vendor/latte/latte/src/Latte/Essential/Nodes/SkipNode.php +71 -0
  156. package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +62 -0
  157. package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +118 -0
  158. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +39 -0
  159. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +38 -0
  160. package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +35 -0
  161. package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +104 -0
  162. package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +75 -0
  163. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +106 -0
  164. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +40 -0
  165. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +36 -0
  166. package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +81 -0
  167. package/vendor/latte/latte/src/Latte/Essential/Passes.php +115 -0
  168. package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +28 -0
  169. package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +16 -0
  170. package/vendor/latte/latte/src/Latte/Essential/Tracer.php +117 -0
  171. package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +101 -0
  172. package/vendor/latte/latte/src/Latte/Extension.php +97 -0
  173. package/vendor/latte/latte/src/Latte/Helpers.php +96 -0
  174. package/vendor/latte/latte/src/Latte/Loader.php +37 -0
  175. package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +95 -0
  176. package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +76 -0
  177. package/vendor/latte/latte/src/Latte/Policy.php +24 -0
  178. package/vendor/latte/latte/src/Latte/PositionAwareException.php +50 -0
  179. package/vendor/latte/latte/src/Latte/Runtime/Block.php +24 -0
  180. package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +151 -0
  181. package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +39 -0
  182. package/vendor/latte/latte/src/Latte/Runtime/Filters.php +234 -0
  183. package/vendor/latte/latte/src/Latte/Runtime/Html.php +35 -0
  184. package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +17 -0
  185. package/vendor/latte/latte/src/Latte/Runtime/Template.php +381 -0
  186. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +30 -0
  187. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallableNode.php +29 -0
  188. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +32 -0
  189. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallableNode.php +30 -0
  190. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +32 -0
  191. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +73 -0
  192. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallNode.php +31 -0
  193. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallableNode.php +30 -0
  194. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +32 -0
  195. package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +116 -0
  196. package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +132 -0
  197. package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +185 -0
  198. package/vendor/latte/latte/src/Latte/Strict.php +101 -0
  199. package/vendor/latte/latte/src/Latte/attributes.php +24 -0
  200. package/vendor/latte/latte/src/Latte/exceptions.php +69 -0
  201. package/vendor/latte/latte/src/Tools/Linter.php +175 -0
@@ -0,0 +1,129 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Html;
11
+
12
+ use Latte\Compiler\Node;
13
+ use Latte\Compiler\NodeHelpers;
14
+ use Latte\Compiler\Nodes;
15
+ use Latte\Compiler\Nodes\AreaNode;
16
+ use Latte\Compiler\Nodes\AuxiliaryNode;
17
+ use Latte\Compiler\Nodes\FragmentNode;
18
+ use Latte\Compiler\Position;
19
+ use Latte\Compiler\PrintContext;
20
+ use Latte\Compiler\Tag;
21
+
22
+
23
+ /**
24
+ * HTML element node.
25
+ */
26
+ class ElementNode extends AreaNode
27
+ {
28
+ public ?Node $customName = null;
29
+ public ?FragmentNode $attributes = null;
30
+ public bool $selfClosing = false;
31
+ public ?AreaNode $content = null;
32
+
33
+ /** @var Tag[] */
34
+ public array $nAttributes = [];
35
+
36
+ /** n:tag & n:tag- support */
37
+ public AreaNode $tagNode;
38
+ public bool $captureTagName = false;
39
+ private ?string $endTagVar;
40
+
41
+
42
+ public function __construct(
43
+ public /*readonly*/ string $name,
44
+ public ?Position $position = null,
45
+ public /*readonly*/ ?self $parent = null,
46
+ public ?\stdClass $data = null,
47
+ ) {
48
+ $this->data ??= new \stdClass;
49
+ $this->tagNode = new AuxiliaryNode(\Closure::fromCallable([$this, 'printStartTag']));
50
+ }
51
+
52
+
53
+ public function getAttribute(string $name): string|Node|bool|null
54
+ {
55
+ foreach ($this->attributes?->children as $child) {
56
+ if ($child instanceof AttributeNode
57
+ && $child->name instanceof Nodes\TextNode
58
+ && strcasecmp($name, $child->name->content) === 0
59
+ ) {
60
+ return NodeHelpers::toText($child->value) ?? $child->value ?? true;
61
+ }
62
+ }
63
+
64
+ return null;
65
+ }
66
+
67
+
68
+ public function print(PrintContext $context): string
69
+ {
70
+ $res = $this->endTagVar = null;
71
+ if ($this->captureTagName || $this->customName) {
72
+ $endTag = $this->endTagVar = '$ʟ_tag[' . $context->generateId() . ']';
73
+ $res = "$this->endTagVar = '';";
74
+ } else {
75
+ $endTag = var_export('</' . $this->name . '>', true);
76
+ }
77
+
78
+ $res .= $this->tagNode->print($context); // calls $this->printStartTag()
79
+
80
+ if ($this->content) {
81
+ $context->beginEscape()->enterHtmlText($this);
82
+ $res .= $this->content->print($context);
83
+ $context->restoreEscape();
84
+ $res .= 'echo ' . $endTag . ';';
85
+ }
86
+
87
+ return $res;
88
+ }
89
+
90
+
91
+ private function printStartTag(PrintContext $context): string
92
+ {
93
+ $context->beginEscape()->enterHtmlTag($this->name);
94
+ $res = "echo '<';";
95
+
96
+ $namePhp = var_export($this->name, true);
97
+ if ($this->endTagVar) {
98
+ $res .= 'echo $ʟ_tmp = (' . ($this->customName ? $this->customName->print($context) : $namePhp) . ');';
99
+ $res .= $this->endTagVar . ' = '
100
+ . "'</' . \$ʟ_tmp . '>'"
101
+ . ' . ' . $this->endTagVar . ';';
102
+ } else {
103
+ $res .= 'echo ' . $namePhp . ';';
104
+ }
105
+
106
+ foreach ($this->attributes?->children ?? [] as $attr) {
107
+ $res .= $attr->print($context);
108
+ }
109
+
110
+ $res .= "echo '" . ($this->selfClosing ? '/>' : '>') . "';";
111
+ $context->restoreEscape();
112
+ return $res;
113
+ }
114
+
115
+
116
+ public function &getIterator(): \Generator
117
+ {
118
+ yield $this->tagNode;
119
+ if ($this->customName) {
120
+ yield $this->customName;
121
+ }
122
+ if ($this->attributes) {
123
+ yield $this->attributes;
124
+ }
125
+ if ($this->content) {
126
+ yield $this->content;
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,53 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Html;
11
+
12
+ use Latte\Compiler\Nodes\AreaNode;
13
+ use Latte\Compiler\Nodes\FragmentNode;
14
+ use Latte\Compiler\Position;
15
+ use Latte\Compiler\PrintContext;
16
+
17
+
18
+ class QuotedValue extends AreaNode
19
+ {
20
+ public function __construct(
21
+ public AreaNode $value,
22
+ public string $quote,
23
+ public ?Position $position = null,
24
+ ) {
25
+ }
26
+
27
+
28
+ public function print(PrintContext $context): string
29
+ {
30
+ $res = 'echo ' . var_export($this->quote, true) . ';';
31
+ $escaper = $context->beginEscape();
32
+ $escaper->enterHtmlAttributeQuote($this->quote);
33
+
34
+ if ($this->value instanceof FragmentNode && $escaper->export() === 'html/attr/url') {
35
+ foreach ($this->value->children as $child) {
36
+ $res .= $child->print($context);
37
+ $escaper->enterHtmlAttribute(null, $this->quote);
38
+ }
39
+ } else {
40
+ $res .= $this->value->print($context);
41
+ }
42
+
43
+ $res .= 'echo ' . var_export($this->quote, true) . ';';
44
+ $context->restoreEscape();
45
+ return $res;
46
+ }
47
+
48
+
49
+ public function &getIterator(): \Generator
50
+ {
51
+ yield $this->value;
52
+ }
53
+ }
@@ -0,0 +1,21 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes;
11
+
12
+ use Latte\Compiler\PrintContext;
13
+
14
+
15
+ class NopNode extends AreaNode
16
+ {
17
+ public function print(PrintContext $context): string
18
+ {
19
+ return '';
20
+ }
21
+ }
@@ -0,0 +1,45 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php;
11
+
12
+ use Latte\Compiler\Node;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class ArgumentNode extends Node
18
+ {
19
+ public function __construct(
20
+ public ExpressionNode $value,
21
+ public bool $byRef = false,
22
+ public bool $unpack = false,
23
+ public ?IdentifierNode $name = null,
24
+ public ?Position $position = null,
25
+ ) {
26
+ }
27
+
28
+
29
+ public function print(PrintContext $context): string
30
+ {
31
+ return ($this->name ? $this->name . ': ' : '')
32
+ . ($this->byRef ? '&' : '')
33
+ . ($this->unpack ? '...' : '')
34
+ . $this->value->print($context);
35
+ }
36
+
37
+
38
+ public function &getIterator(): \Generator
39
+ {
40
+ if ($this->name) {
41
+ yield $this->name;
42
+ }
43
+ yield $this->value;
44
+ }
45
+ }
@@ -0,0 +1,17 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php;
11
+
12
+ use Latte\Compiler\Node;
13
+
14
+
15
+ abstract class ComplexTypeNode extends Node
16
+ {
17
+ }
@@ -0,0 +1,41 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Expression;
11
+
12
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class ArrayAccessNode extends ExpressionNode
18
+ {
19
+ public function __construct(
20
+ public ExpressionNode $expr,
21
+ public ?ExpressionNode $index = null,
22
+ public ?Position $position = null,
23
+ ) {
24
+ }
25
+
26
+
27
+ public function print(PrintContext $context): string
28
+ {
29
+ return $context->dereferenceExpr($this->expr)
30
+ . '[' . ($this->index !== null ? $this->index->print($context) : '') . ']';
31
+ }
32
+
33
+
34
+ public function &getIterator(): \Generator
35
+ {
36
+ yield $this->expr;
37
+ if ($this->index) {
38
+ yield $this->index;
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,52 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Expression;
11
+
12
+ use Latte\Compiler\Node;
13
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
14
+ use Latte\Compiler\Nodes\Php\IdentifierNode;
15
+ use Latte\Compiler\Position;
16
+ use Latte\Compiler\PrintContext;
17
+
18
+
19
+ class ArrayItemNode extends Node
20
+ {
21
+ public function __construct(
22
+ public ExpressionNode $value,
23
+ public ExpressionNode|IdentifierNode|null $key = null,
24
+ public bool $byRef = false,
25
+ public bool $unpack = false,
26
+ public ?Position $position = null,
27
+ ) {
28
+ }
29
+
30
+
31
+ public function print(PrintContext $context): string
32
+ {
33
+ $key = match (true) {
34
+ $this->key instanceof ExpressionNode => $this->key->print($context) . ' => ',
35
+ $this->key instanceof IdentifierNode => $context->encodeString($this->key->name) . ' => ',
36
+ $this->key === null => '',
37
+ };
38
+ return $key
39
+ . ($this->byRef ? '&' : '')
40
+ . ($this->unpack ? '...' : '')
41
+ . $this->value->print($context);
42
+ }
43
+
44
+
45
+ public function &getIterator(): \Generator
46
+ {
47
+ if ($this->key) {
48
+ yield $this->key;
49
+ }
50
+ yield $this->value;
51
+ }
52
+ }
@@ -0,0 +1,94 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Expression;
11
+
12
+ use Latte\Compiler\Nodes\Php\ArgumentNode;
13
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
14
+ use Latte\Compiler\Nodes\Php\IdentifierNode;
15
+ use Latte\Compiler\Nodes\Php\Scalar;
16
+ use Latte\Compiler\Position;
17
+ use Latte\Compiler\PrintContext;
18
+
19
+
20
+ class ArrayNode extends ExpressionNode
21
+ {
22
+ public function __construct(
23
+ /** @var array<ArrayItemNode|null> */
24
+ public array $items = [],
25
+ public ?Position $position = null,
26
+ ) {
27
+ (function (?ArrayItemNode ...$args) {})(...$items);
28
+ }
29
+
30
+
31
+ /** @param ArgumentNode[] $args */
32
+ public static function fromArguments(array $args): self
33
+ {
34
+ $node = new self;
35
+ foreach ($args as $arg) {
36
+ $node->items[] = new ArrayItemNode($arg->value, $arg->name, $arg->byRef, $arg->unpack, $arg->position);
37
+ }
38
+
39
+ return $node;
40
+ }
41
+
42
+
43
+ /** @return ArgumentNode[] */
44
+ public function toArguments(): array
45
+ {
46
+ $args = [];
47
+ foreach ($this->items as $item) {
48
+ $key = match (true) {
49
+ $item->key instanceof Scalar\StringNode => new IdentifierNode($item->key->value),
50
+ $item->key instanceof IdentifierNode => $item->key,
51
+ $item->key === null => null,
52
+ default => throw new \InvalidArgumentException('The expression used in the key cannot be converted to an argument.'),
53
+ };
54
+ $args[] = new ArgumentNode($item->value, $item->byRef, $item->unpack, $key, $item->position);
55
+ }
56
+
57
+ return $args;
58
+ }
59
+
60
+
61
+ public function print(PrintContext $context): string
62
+ {
63
+ // Converts [...$var] -> $var, because PHP 8.0 doesn't support unpacking with string keys
64
+ if (PHP_VERSION_ID < 80100) {
65
+ $res = '[';
66
+ $merge = false;
67
+ foreach ($this->items as $item) {
68
+ if ($item === null) {
69
+ $res .= ', ';
70
+ } elseif ($item->unpack) {
71
+ $res .= '], ' . $item->value->print($context) . ', [';
72
+ $merge = true;
73
+ } else {
74
+ $res .= $item->print($context) . ', ';
75
+ }
76
+ }
77
+
78
+ $res = str_ends_with($res, ', ') ? substr($res, 0, -2) : $res;
79
+ return $merge ? "array_merge($res])" : $res . ']';
80
+ }
81
+
82
+ return '[' . $context->implode($this->items) . ']';
83
+ }
84
+
85
+
86
+ public function &getIterator(): \Generator
87
+ {
88
+ foreach ($this->items as &$item) {
89
+ if ($item) {
90
+ yield $item;
91
+ }
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,39 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Expression;
11
+
12
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class AssignNode extends ExpressionNode
18
+ {
19
+ public function __construct(
20
+ public ExpressionNode $var,
21
+ public ExpressionNode $expr,
22
+ public bool $byRef = false,
23
+ public ?Position $position = null,
24
+ ) {
25
+ }
26
+
27
+
28
+ public function print(PrintContext $context): string
29
+ {
30
+ return $context->infixOp($this, $this->var, $this->byRef ? ' = &' : ' = ', $this->expr);
31
+ }
32
+
33
+
34
+ public function &getIterator(): \Generator
35
+ {
36
+ yield $this->var;
37
+ yield $this->expr;
38
+ }
39
+ }
@@ -0,0 +1,45 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Expression;
11
+
12
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class AssignOpNode extends ExpressionNode
18
+ {
19
+ private const Ops = ['+', '-', '*', '/', '.', '%', '&', '|', '^', '<<', '>>', '**', '??'];
20
+
21
+
22
+ public function __construct(
23
+ public ExpressionNode $var,
24
+ public /*readonly*/ string $operator,
25
+ public ExpressionNode $expr,
26
+ public ?Position $position = null,
27
+ ) {
28
+ if (!in_array($this->operator, self::Ops, true)) {
29
+ throw new \InvalidArgumentException("Unexpected operator '$this->operator'");
30
+ }
31
+ }
32
+
33
+
34
+ public function print(PrintContext $context): string
35
+ {
36
+ return $context->infixOp($this, $this->var, ' ' . $this->operator . '= ', $this->expr);
37
+ }
38
+
39
+
40
+ public function &getIterator(): \Generator
41
+ {
42
+ yield $this->var;
43
+ yield $this->expr;
44
+ }
45
+ }
@@ -0,0 +1,65 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Expression;
11
+
12
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class BinaryOpNode extends ExpressionNode
18
+ {
19
+ private const Ops = ['||', '&&', 'or', 'and', 'xor', '&', '^', '.', '+', '-', '*', '/', '%', '<<', '>>', '**',
20
+ '==', '!=', '===', '!==', '<=>', '<', '<=', '>', '>=', '??', ];
21
+
22
+
23
+ public function __construct(
24
+ public ExpressionNode $left,
25
+ public /*readonly*/ string $operator,
26
+ public ExpressionNode $right,
27
+ public ?Position $position = null,
28
+ ) {
29
+ if (!in_array(strtolower($this->operator), self::Ops, true)) {
30
+ throw new \InvalidArgumentException("Unexpected operator '$this->operator'");
31
+ }
32
+ }
33
+
34
+
35
+ /**
36
+ * Creates nested BinaryOp nodes from a list of expressions.
37
+ */
38
+ public static function nest(string $operator, ExpressionNode ...$exprs): ExpressionNode
39
+ {
40
+ $count = count($exprs);
41
+ if ($count < 2) {
42
+ return $exprs[0];
43
+ }
44
+
45
+ $last = $exprs[0];
46
+ for ($i = 1; $i < $count; $i++) {
47
+ $last = new static($last, $operator, $exprs[$i]);
48
+ }
49
+
50
+ return $last;
51
+ }
52
+
53
+
54
+ public function print(PrintContext $context): string
55
+ {
56
+ return $context->infixOp($this, $this->left, ' ' . $this->operator . ' ', $this->right);
57
+ }
58
+
59
+
60
+ public function &getIterator(): \Generator
61
+ {
62
+ yield $this->left;
63
+ yield $this->right;
64
+ }
65
+ }
@@ -0,0 +1,43 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Expression;
11
+
12
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
13
+ use Latte\Compiler\Position;
14
+ use Latte\Compiler\PrintContext;
15
+
16
+
17
+ class CastNode extends ExpressionNode
18
+ {
19
+ private const Types = ['int' => 1, 'float' => 1, 'string' => 1, 'array' => 1, 'object' => 1, 'bool' => 1];
20
+
21
+
22
+ public function __construct(
23
+ public /*readonly*/ string $type,
24
+ public ExpressionNode $expr,
25
+ public ?Position $position = null,
26
+ ) {
27
+ if (!isset(self::Types[strtolower($this->type)])) {
28
+ throw new \InvalidArgumentException("Unexpected type '$this->type'");
29
+ }
30
+ }
31
+
32
+
33
+ public function print(PrintContext $context): string
34
+ {
35
+ return $context->prefixOp($this, '(' . $this->type . ') ', $this->expr);
36
+ }
37
+
38
+
39
+ public function &getIterator(): \Generator
40
+ {
41
+ yield $this->expr;
42
+ }
43
+ }
@@ -0,0 +1,42 @@
1
+ <?php
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
+ declare(strict_types=1);
9
+
10
+ namespace Latte\Compiler\Nodes\Php\Expression;
11
+
12
+ use Latte\Compiler\Nodes\Php\ExpressionNode;
13
+ use Latte\Compiler\Nodes\Php\IdentifierNode;
14
+ use Latte\Compiler\Nodes\Php\NameNode;
15
+ use Latte\Compiler\Position;
16
+ use Latte\Compiler\PrintContext;
17
+
18
+
19
+ class ClassConstantFetchNode extends ExpressionNode
20
+ {
21
+ public function __construct(
22
+ public NameNode|ExpressionNode $class,
23
+ public IdentifierNode $name,
24
+ public ?Position $position = null,
25
+ ) {
26
+ }
27
+
28
+
29
+ public function print(PrintContext $context): string
30
+ {
31
+ return $context->dereferenceExpr($this->class)
32
+ . '::'
33
+ . $this->name->print($context);
34
+ }
35
+
36
+
37
+ public function &getIterator(): \Generator
38
+ {
39
+ yield $this->class;
40
+ yield $this->name;
41
+ }
42
+ }