@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.
- package/README.md +39 -0
- package/handler.js +9 -0
- package/index.js +138 -0
- package/index.php +173 -0
- package/latte/AssetFilter.php +11 -0
- package/latte/FetchFunction.php +28 -0
- package/latte/IconFilter.php +14 -0
- package/latte/JsonTag.php +64 -0
- package/latte/PlaceholderFunction.php +11 -0
- package/latte/RandomColorFunction.php +14 -0
- package/latte/TelFilter.php +22 -0
- package/package.json +35 -0
- package/vendor/autoload.php +7 -0
- package/vendor/bin/latte-lint +107 -0
- package/vendor/composer/ClassLoader.php +572 -0
- package/vendor/composer/InstalledVersions.php +350 -0
- package/vendor/composer/LICENSE +21 -0
- package/vendor/composer/autoload_classmap.php +183 -0
- package/vendor/composer/autoload_namespaces.php +9 -0
- package/vendor/composer/autoload_psr4.php +9 -0
- package/vendor/composer/autoload_real.php +57 -0
- package/vendor/composer/autoload_static.php +193 -0
- package/vendor/composer/installed.json +93 -0
- package/vendor/composer/installed.php +32 -0
- package/vendor/composer/platform_check.php +26 -0
- package/vendor/latte/latte/bin/latte-lint +29 -0
- package/vendor/latte/latte/composer.json +53 -0
- package/vendor/latte/latte/license.md +60 -0
- package/vendor/latte/latte/ncs.php +14 -0
- package/vendor/latte/latte/ncs.xml +9 -0
- package/vendor/latte/latte/readme.md +21 -0
- package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +114 -0
- package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +99 -0
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.panel.phtml +98 -0
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.tab.phtml +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Block.php +44 -0
- package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +244 -0
- package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +128 -0
- package/vendor/latte/latte/src/Latte/Compiler/Node.php +28 -0
- package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +132 -0
- package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +77 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +27 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +59 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +48 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +46 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +129 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/QuotedValue.php +53 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +21 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +41 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayItemNode.php +52 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +94 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +65 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +73 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureUseNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ErrorSuppressNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallableNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InRangeNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +50 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallableNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NotNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallNode.php +55 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallableNode.php +47 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +50 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +67 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +107 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +89 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +35 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +54 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringNode.php +80 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringPartNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +63 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +70 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +21 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +34 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +227 -0
- package/vendor/latte/latte/src/Latte/Compiler/Position.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +334 -0
- package/vendor/latte/latte/src/Latte/Compiler/Tag.php +117 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +399 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +388 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +580 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +206 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +391 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +448 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +506 -0
- package/vendor/latte/latte/src/Latte/Compiler/Token.php +259 -0
- package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +151 -0
- package/vendor/latte/latte/src/Latte/ContentType.php +22 -0
- package/vendor/latte/latte/src/Latte/Engine.php +591 -0
- package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +160 -0
- package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +232 -0
- package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +232 -0
- package/vendor/latte/latte/src/Latte/Essential/Filters.php +591 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +161 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +98 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +74 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +53 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +134 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +58 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +125 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +60 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +91 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +155 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +141 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +82 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +180 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +140 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +94 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +105 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +54 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +79 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +84 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/PrintNode.php +70 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +46 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SkipNode.php +71 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +62 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +118 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +38 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +35 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +104 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +75 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +106 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Passes.php +115 -0
- package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +28 -0
- package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +16 -0
- package/vendor/latte/latte/src/Latte/Essential/Tracer.php +117 -0
- package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +101 -0
- package/vendor/latte/latte/src/Latte/Extension.php +97 -0
- package/vendor/latte/latte/src/Latte/Helpers.php +96 -0
- package/vendor/latte/latte/src/Latte/Loader.php +37 -0
- package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +95 -0
- package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +76 -0
- package/vendor/latte/latte/src/Latte/Policy.php +24 -0
- package/vendor/latte/latte/src/Latte/PositionAwareException.php +50 -0
- package/vendor/latte/latte/src/Latte/Runtime/Block.php +24 -0
- package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +151 -0
- package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +39 -0
- package/vendor/latte/latte/src/Latte/Runtime/Filters.php +234 -0
- package/vendor/latte/latte/src/Latte/Runtime/Html.php +35 -0
- package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +17 -0
- package/vendor/latte/latte/src/Latte/Runtime/Template.php +381 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallableNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallableNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +73 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallNode.php +31 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallableNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +116 -0
- package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +132 -0
- package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +185 -0
- package/vendor/latte/latte/src/Latte/Strict.php +101 -0
- package/vendor/latte/latte/src/Latte/attributes.php +24 -0
- package/vendor/latte/latte/src/Latte/exceptions.php +69 -0
- package/vendor/latte/latte/src/Tools/Linter.php +175 -0
|
@@ -0,0 +1,128 @@
|
|
|
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;
|
|
11
|
+
|
|
12
|
+
use Latte\Compiler\Nodes\Php\ArgumentNode;
|
|
13
|
+
use Latte\Compiler\Nodes\Php\Expression;
|
|
14
|
+
use Latte\Compiler\Nodes\Php\ExpressionNode;
|
|
15
|
+
use Latte\Compiler\Nodes\Php\IdentifierNode;
|
|
16
|
+
use Latte\Compiler\Nodes\Php\NameNode;
|
|
17
|
+
use Latte\Compiler\Nodes\Php\Scalar;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
final class ExpressionBuilder
|
|
21
|
+
{
|
|
22
|
+
public function __construct(
|
|
23
|
+
private /*readonly*/ ExpressionNode|NameNode $expr,
|
|
24
|
+
) {
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
public static function variable(string $name): self
|
|
29
|
+
{
|
|
30
|
+
return new self(new Expression\VariableNode(ltrim($name, '$')));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
public static function class(string $name): self
|
|
35
|
+
{
|
|
36
|
+
return new self(new NameNode($name));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
public static function function(ExpressionNode|self|string $name, array $args = []): self
|
|
41
|
+
{
|
|
42
|
+
$name = is_string($name)
|
|
43
|
+
? new NameNode($name)
|
|
44
|
+
: ($name instanceof self ? $name->expr : $name);
|
|
45
|
+
return new self(new Expression\FunctionCallNode($name, self::arrayToArgs($args)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
public function property(ExpressionNode|self|string $name): self
|
|
50
|
+
{
|
|
51
|
+
$name = is_string($name)
|
|
52
|
+
? new IdentifierNode($name)
|
|
53
|
+
: ($name instanceof self ? $name->expr : $name);
|
|
54
|
+
return new self(new Expression\PropertyFetchNode($this->expr, $name));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public function method(ExpressionNode|self|string $name, array $args = []): self
|
|
59
|
+
{
|
|
60
|
+
$name = is_string($name)
|
|
61
|
+
? new IdentifierNode($name)
|
|
62
|
+
: ($name instanceof self ? $name->expr : $name);
|
|
63
|
+
return new self(new Expression\MethodCallNode($this->expr, $name, self::arrayToArgs($args)));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
public function staticMethod(ExpressionNode|self|string $name, array $args = []): self
|
|
68
|
+
{
|
|
69
|
+
$name = is_string($name)
|
|
70
|
+
? new IdentifierNode($name)
|
|
71
|
+
: ($name instanceof self ? $name->expr : $name);
|
|
72
|
+
return new self(new Expression\StaticCallNode($this->expr, $name, self::arrayToArgs($args)));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
public function build(): ExpressionNode|NameNode
|
|
77
|
+
{
|
|
78
|
+
return $this->expr;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
public static function valueToNode(bool|int|float|string|array|null|ExpressionNode $value): ExpressionNode
|
|
83
|
+
{
|
|
84
|
+
return match (true) {
|
|
85
|
+
$value === null => new Scalar\NullNode,
|
|
86
|
+
is_bool($value) => new Scalar\BooleanNode($value),
|
|
87
|
+
is_int($value) => new Scalar\IntegerNode($value),
|
|
88
|
+
is_float($value) => new Scalar\FloatNode($value),
|
|
89
|
+
is_string($value) => new Scalar\StringNode($value),
|
|
90
|
+
is_array($value) => self::arrayToNode($value),
|
|
91
|
+
default => $value, // ExpressionNode
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
private static function arrayToNode(array $arr): Expression\ArrayNode
|
|
97
|
+
{
|
|
98
|
+
$node = new Expression\ArrayNode;
|
|
99
|
+
$lastKey = -1;
|
|
100
|
+
foreach ($arr as $key => $val) {
|
|
101
|
+
if ($lastKey !== null && ++$lastKey === $key) {
|
|
102
|
+
$node->items[] = new Expression\ArrayItemNode(self::valueToNode($val));
|
|
103
|
+
} else {
|
|
104
|
+
$lastKey = null;
|
|
105
|
+
$node->items[] = new Expression\ArrayItemNode(self::valueToNode($val), self::valueToNode($key));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return $node;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
/** @return ArgumentNode[] */
|
|
114
|
+
private static function arrayToArgs(array $arr): array
|
|
115
|
+
{
|
|
116
|
+
$args = [];
|
|
117
|
+
foreach ($arr as $key => $arg) {
|
|
118
|
+
$args[] = $arg instanceof ArgumentNode
|
|
119
|
+
? $arg
|
|
120
|
+
: new ArgumentNode(
|
|
121
|
+
self::valueToNode($arg),
|
|
122
|
+
name: is_string($key) ? new IdentifierNode($key) : null,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return $args;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
5
|
+
namespace Latte\Compiler;
|
|
6
|
+
|
|
7
|
+
use Latte;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @implements \IteratorAggregate<Node>
|
|
12
|
+
*/
|
|
13
|
+
abstract class Node implements \IteratorAggregate
|
|
14
|
+
{
|
|
15
|
+
use Latte\Strict;
|
|
16
|
+
|
|
17
|
+
public ?Position $position = null;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
abstract public function print(PrintContext $context): string;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
public function &getIterator(): \Generator
|
|
24
|
+
{
|
|
25
|
+
return;
|
|
26
|
+
yield;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
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;
|
|
11
|
+
|
|
12
|
+
use Latte;
|
|
13
|
+
use Latte\Compiler\Nodes\Php;
|
|
14
|
+
use Latte\Compiler\Nodes\Php\Expression;
|
|
15
|
+
use Latte\Compiler\Nodes\Php\ExpressionNode;
|
|
16
|
+
use Latte\Compiler\Nodes\Php\Scalar;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
final class NodeHelpers
|
|
20
|
+
{
|
|
21
|
+
use Latte\Strict;
|
|
22
|
+
|
|
23
|
+
/** @return Node[] */
|
|
24
|
+
public static function find(Node $node, callable $filter): array
|
|
25
|
+
{
|
|
26
|
+
$found = [];
|
|
27
|
+
(new NodeTraverser)
|
|
28
|
+
->traverse($node, enter: function (Node $node) use ($filter, &$found) {
|
|
29
|
+
if ($filter($node)) {
|
|
30
|
+
$found[] = $node;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return $found;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
public static function findFirst(Node $node, callable $filter): ?Node
|
|
38
|
+
{
|
|
39
|
+
$found = null;
|
|
40
|
+
(new NodeTraverser)
|
|
41
|
+
->traverse($node, enter: function (Node $node) use ($filter, &$found) {
|
|
42
|
+
if ($filter($node)) {
|
|
43
|
+
$found = $node;
|
|
44
|
+
return NodeTraverser::StopTraversal;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return $found;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
public static function clone(Node $node): Node
|
|
52
|
+
{
|
|
53
|
+
return (new NodeTraverser)
|
|
54
|
+
->traverse($node, enter: fn(Node $node) => clone $node);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public static function toValue(ExpressionNode $node, bool $constants = false): mixed
|
|
59
|
+
{
|
|
60
|
+
if ($node instanceof Scalar\BooleanNode
|
|
61
|
+
|| $node instanceof Scalar\FloatNode
|
|
62
|
+
|| $node instanceof Scalar\IntegerNode
|
|
63
|
+
|| $node instanceof Scalar\StringNode
|
|
64
|
+
) {
|
|
65
|
+
return $node->value;
|
|
66
|
+
|
|
67
|
+
} elseif ($node instanceof Scalar\NullNode) {
|
|
68
|
+
return null;
|
|
69
|
+
|
|
70
|
+
} elseif ($node instanceof Expression\ArrayNode) {
|
|
71
|
+
$res = [];
|
|
72
|
+
foreach ($node->items as $item) {
|
|
73
|
+
$value = self::toValue($item->value, $constants);
|
|
74
|
+
if ($item->key) {
|
|
75
|
+
$key = $item->key instanceof Php\IdentifierNode
|
|
76
|
+
? $item->key->name
|
|
77
|
+
: self::toValue($item->key, $constants);
|
|
78
|
+
$res[$key] = $value;
|
|
79
|
+
|
|
80
|
+
} elseif ($item->unpack) {
|
|
81
|
+
$res = array_merge($res, $value);
|
|
82
|
+
|
|
83
|
+
} else {
|
|
84
|
+
$res[] = $value;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return $res;
|
|
89
|
+
|
|
90
|
+
} elseif ($node instanceof Expression\ConstantFetchNode && $constants) {
|
|
91
|
+
$name = $node->name->toCodeString();
|
|
92
|
+
return defined($name)
|
|
93
|
+
? constant($name)
|
|
94
|
+
: throw new \InvalidArgumentException("The constant '$name' is not defined.");
|
|
95
|
+
|
|
96
|
+
} elseif ($node instanceof Expression\ClassConstantFetchNode && $constants) {
|
|
97
|
+
$class = $node->class instanceof Php\NameNode
|
|
98
|
+
? $node->class->toCodeString()
|
|
99
|
+
: self::toValue($node->class, $constants);
|
|
100
|
+
$name = $class . '::' . $node->name->name;
|
|
101
|
+
return defined($name)
|
|
102
|
+
? constant($name)
|
|
103
|
+
: throw new \InvalidArgumentException("The constant '$name' is not defined.");
|
|
104
|
+
|
|
105
|
+
} else {
|
|
106
|
+
throw new \InvalidArgumentException('The expression cannot be converted to PHP value.');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
public static function toText(?Node $node): ?string
|
|
112
|
+
{
|
|
113
|
+
if ($node instanceof Nodes\FragmentNode) {
|
|
114
|
+
$res = '';
|
|
115
|
+
foreach ($node->children as $child) {
|
|
116
|
+
if (($s = self::toText($child)) === null) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
$res .= $s;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return $res;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return match (true) {
|
|
126
|
+
$node instanceof Nodes\TextNode => $node->content,
|
|
127
|
+
$node instanceof Nodes\Html\QuotedValue => self::toText($node->value),
|
|
128
|
+
$node instanceof Nodes\NopNode => '',
|
|
129
|
+
default => null,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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;
|
|
11
|
+
|
|
12
|
+
use Latte;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
final class NodeTraverser
|
|
16
|
+
{
|
|
17
|
+
use Latte\Strict;
|
|
18
|
+
|
|
19
|
+
public const DontTraverseChildren = 1;
|
|
20
|
+
public const StopTraversal = 2;
|
|
21
|
+
|
|
22
|
+
/** @var ?callable(Node): (Node|int|null) */
|
|
23
|
+
private $enter;
|
|
24
|
+
|
|
25
|
+
/** @var ?callable(Node): (Node|int|null) */
|
|
26
|
+
private $leave;
|
|
27
|
+
|
|
28
|
+
private bool $stop;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
public function traverse(Node $node, ?callable $enter = null, ?callable $leave = null): Node
|
|
32
|
+
{
|
|
33
|
+
$this->enter = $enter;
|
|
34
|
+
$this->leave = $leave;
|
|
35
|
+
$this->stop = false;
|
|
36
|
+
return $this->traverseNode($node);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
private function traverseNode(Node $node): Node
|
|
41
|
+
{
|
|
42
|
+
$children = true;
|
|
43
|
+
if ($this->enter) {
|
|
44
|
+
$res = ($this->enter)($node);
|
|
45
|
+
if ($res instanceof Node) {
|
|
46
|
+
$node = $res;
|
|
47
|
+
|
|
48
|
+
} elseif ($res === self::DontTraverseChildren) {
|
|
49
|
+
$children = false;
|
|
50
|
+
|
|
51
|
+
} elseif ($res === self::StopTraversal) {
|
|
52
|
+
$this->stop = true;
|
|
53
|
+
$children = false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if ($children) {
|
|
58
|
+
foreach ($node as &$subnode) {
|
|
59
|
+
$subnode = $this->traverseNode($subnode);
|
|
60
|
+
if ($this->stop) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!$this->stop && $this->leave) {
|
|
67
|
+
$res = ($this->leave)($node);
|
|
68
|
+
if ($res instanceof Node) {
|
|
69
|
+
$node = $res;
|
|
70
|
+
} elseif ($res === self::StopTraversal) {
|
|
71
|
+
$this->stop = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return $node;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -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;
|
|
11
|
+
|
|
12
|
+
use Latte\Compiler\Node;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
abstract class AreaNode extends Node
|
|
16
|
+
{
|
|
17
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 AuxiliaryNode extends AreaNode
|
|
16
|
+
{
|
|
17
|
+
public function __construct(
|
|
18
|
+
public /*readonly*/ \Closure $callable,
|
|
19
|
+
) {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
public function print(PrintContext $context): string
|
|
24
|
+
{
|
|
25
|
+
return ($this->callable)($context);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
final class FragmentNode extends AreaNode
|
|
16
|
+
{
|
|
17
|
+
/** @var AreaNode[] */
|
|
18
|
+
public array $children = [];
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/** @param AreaNode[] $children */
|
|
22
|
+
public function __construct(array $children = [])
|
|
23
|
+
{
|
|
24
|
+
foreach ($children as $child) {
|
|
25
|
+
$this->append($child);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
public function append(AreaNode $node): static
|
|
31
|
+
{
|
|
32
|
+
if ($node instanceof self) {
|
|
33
|
+
$this->children = array_merge($this->children, $node->children);
|
|
34
|
+
} elseif (!$node instanceof NopNode) {
|
|
35
|
+
$this->children[] = $node;
|
|
36
|
+
}
|
|
37
|
+
$this->position ??= $node->position;
|
|
38
|
+
return $this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
public function print(PrintContext $context): string
|
|
43
|
+
{
|
|
44
|
+
$res = '';
|
|
45
|
+
foreach ($this->children as $child) {
|
|
46
|
+
$res .= $child->print($context);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return $res;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
public function &getIterator(): \Generator
|
|
54
|
+
{
|
|
55
|
+
foreach ($this->children as &$item) {
|
|
56
|
+
yield $item;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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\NodeHelpers;
|
|
13
|
+
use Latte\Compiler\Nodes\AreaNode;
|
|
14
|
+
use Latte\Compiler\Position;
|
|
15
|
+
use Latte\Compiler\PrintContext;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AttributeNode extends AreaNode
|
|
19
|
+
{
|
|
20
|
+
public function __construct(
|
|
21
|
+
public AreaNode $name,
|
|
22
|
+
public ?AreaNode $value = null,
|
|
23
|
+
public ?Position $position = null,
|
|
24
|
+
) {
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
public function print(PrintContext $context): string
|
|
29
|
+
{
|
|
30
|
+
$res = $this->name->print($context);
|
|
31
|
+
if ($this->value) {
|
|
32
|
+
$context->beginEscape()->enterHtmlAttribute(NodeHelpers::toText($this->name));
|
|
33
|
+
$res .= "echo '=';";
|
|
34
|
+
$res .= $this->value->print($context);
|
|
35
|
+
$context->restoreEscape();
|
|
36
|
+
}
|
|
37
|
+
return $res;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
public function &getIterator(): \Generator
|
|
42
|
+
{
|
|
43
|
+
yield $this->name;
|
|
44
|
+
if ($this->value) {
|
|
45
|
+
yield $this->value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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\Position;
|
|
14
|
+
use Latte\Compiler\PrintContext;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* HTML bogus tag.
|
|
19
|
+
*/
|
|
20
|
+
class BogusTagNode extends AreaNode
|
|
21
|
+
{
|
|
22
|
+
public function __construct(
|
|
23
|
+
public string $openDelimiter,
|
|
24
|
+
public AreaNode $content,
|
|
25
|
+
public string $endDelimiter,
|
|
26
|
+
public ?Position $position = null,
|
|
27
|
+
) {
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
public function print(PrintContext $context): string
|
|
32
|
+
{
|
|
33
|
+
$res = 'echo ' . var_export($this->openDelimiter, true) . ';';
|
|
34
|
+
$context->beginEscape()->enterHtmlBogusTag();
|
|
35
|
+
$res .= $this->content->print($context);
|
|
36
|
+
$context->restoreEscape();
|
|
37
|
+
$res .= 'echo ' . var_export($this->endDelimiter, true) . ';';
|
|
38
|
+
return $res;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
public function &getIterator(): \Generator
|
|
43
|
+
{
|
|
44
|
+
yield $this->content;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -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\Html;
|
|
11
|
+
|
|
12
|
+
use Latte\Compiler\Nodes\AreaNode;
|
|
13
|
+
use Latte\Compiler\Position;
|
|
14
|
+
use Latte\Compiler\PrintContext;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CommentNode extends AreaNode
|
|
18
|
+
{
|
|
19
|
+
public function __construct(
|
|
20
|
+
public AreaNode $content,
|
|
21
|
+
public ?Position $position = null,
|
|
22
|
+
) {
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
public function print(PrintContext $context): string
|
|
27
|
+
{
|
|
28
|
+
$context->beginEscape()->enterHtmlComment();
|
|
29
|
+
$content = $this->content->print($context);
|
|
30
|
+
$context->restoreEscape();
|
|
31
|
+
return "echo '<!--'; $content echo '-->';";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
public function &getIterator(): \Generator
|
|
36
|
+
{
|
|
37
|
+
yield $this->content;
|
|
38
|
+
}
|
|
39
|
+
}
|