@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,160 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Nette Framework (https://nette.org)
|
|
5
|
+
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential;
|
|
11
|
+
|
|
12
|
+
use Latte;
|
|
13
|
+
use Latte\Runtime\Template;
|
|
14
|
+
use Nette\PhpGenerator as Php;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Generates blueprint of template class.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
final class Blueprint
|
|
22
|
+
{
|
|
23
|
+
use Latte\Strict;
|
|
24
|
+
|
|
25
|
+
public function printClass(Template $template, ?string $name = null): void
|
|
26
|
+
{
|
|
27
|
+
if (!class_exists(Php\ClassType::class)) {
|
|
28
|
+
throw new \LogicException('Nette PhpGenerator is required to print template, install package `nette/php-generator`.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
$name = $name ?: 'Template';
|
|
32
|
+
$namespace = new Php\PhpNamespace(Php\Helpers::extractNamespace($name));
|
|
33
|
+
$class = $namespace->addClass(Php\Helpers::extractShortName($name));
|
|
34
|
+
|
|
35
|
+
$this->addProperties($class, $template->getParameters());
|
|
36
|
+
$functions = array_diff_key((array) $template->global->fn, (new Latte\Essential\CoreExtension)->getFunctions());
|
|
37
|
+
$this->addFunctions($class, $functions);
|
|
38
|
+
|
|
39
|
+
$end = $this->printCanvas();
|
|
40
|
+
$this->printHeader('Native types');
|
|
41
|
+
$this->printCode((string) $namespace);
|
|
42
|
+
echo $end;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param mixed[] $vars
|
|
48
|
+
*/
|
|
49
|
+
public function printVars(array $vars): void
|
|
50
|
+
{
|
|
51
|
+
if (!class_exists(Php\Type::class)) {
|
|
52
|
+
throw new \LogicException('Nette PhpGenerator is required to print template, install package `nette/php-generator`.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
$res = '';
|
|
56
|
+
foreach ($vars as $name => $value) {
|
|
57
|
+
if (str_starts_with($name, 'ʟ_')) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
$type = Php\Type::getType($value) ?: 'mixed';
|
|
62
|
+
$res .= "{varType $type $$name}\n";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
$end = $this->printCanvas();
|
|
66
|
+
$this->printHeader('varPrint');
|
|
67
|
+
$this->printCode($res ?: 'No variables', 'latte');
|
|
68
|
+
echo $end;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param mixed[] $props
|
|
74
|
+
*/
|
|
75
|
+
public function addProperties(Php\ClassType $class, array $props): void
|
|
76
|
+
{
|
|
77
|
+
foreach ($props as $name => $value) {
|
|
78
|
+
$type = Php\Type::getType($value);
|
|
79
|
+
$prop = $class->addProperty($name);
|
|
80
|
+
$prop->setType($type);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param callable[] $funcs
|
|
87
|
+
*/
|
|
88
|
+
public function addFunctions(Php\ClassType $class, array $funcs): void
|
|
89
|
+
{
|
|
90
|
+
foreach ($funcs as $name => $func) {
|
|
91
|
+
$method = (new Php\Factory)->fromCallable($func);
|
|
92
|
+
$type = $this->printType($method->getReturnType(), $method->isReturnNullable(), $class->getNamespace()) ?: 'mixed';
|
|
93
|
+
$class->addComment("@method $type $name" . $this->printParameters($method, $class->getNamespace()));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
private function printType(?string $type, bool $nullable, ?Php\PhpNamespace $namespace): string
|
|
99
|
+
{
|
|
100
|
+
if ($type === null) {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if ($namespace) {
|
|
105
|
+
$type = $namespace->unresolveName($type);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if ($nullable && strcasecmp($type, 'mixed')) {
|
|
109
|
+
$type = str_contains($type, '|')
|
|
110
|
+
? $type . '|null'
|
|
111
|
+
: '?' . $type;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return $type;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
public function printParameters(
|
|
119
|
+
Php\Closure|Php\GlobalFunction|Php\Method $function,
|
|
120
|
+
?Php\PhpNamespace $namespace = null,
|
|
121
|
+
): string {
|
|
122
|
+
$params = [];
|
|
123
|
+
$list = $function->getParameters();
|
|
124
|
+
foreach ($list as $param) {
|
|
125
|
+
$variadic = $function->isVariadic() && $param === end($list);
|
|
126
|
+
$params[] = ltrim($this->printType($param->getType(), $param->isNullable(), $namespace) . ' ')
|
|
127
|
+
. ($param->isReference() ? '&' : '')
|
|
128
|
+
. ($variadic ? '...' : '')
|
|
129
|
+
. '$' . $param->getName()
|
|
130
|
+
. ($param->hasDefaultValue() && !$variadic ? ' = ' . var_export($param->getDefaultValue(), true) : '');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return '(' . implode(', ', $params) . ')';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
public function printCanvas(): string
|
|
138
|
+
{
|
|
139
|
+
echo '<script src="https://nette.github.io/resources/prism/prism.js"></script>';
|
|
140
|
+
echo '<link rel="stylesheet" href="https://nette.github.io/resources/prism/prism.css">';
|
|
141
|
+
echo "<div style='all:initial;position:fixed;overflow:auto;z-index:1000;left:0;right:0;top:0;bottom:0;color:black;background:white;padding:1em'>\n";
|
|
142
|
+
return "</div>\n";
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
public function printHeader(string $string): void
|
|
147
|
+
{
|
|
148
|
+
echo "<h1 style='all:initial;display:block;font-size:2em;margin:1em 0'>",
|
|
149
|
+
htmlspecialchars($string),
|
|
150
|
+
"</h1>\n";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
public function printCode(string $code, string $lang = 'php'): void
|
|
155
|
+
{
|
|
156
|
+
echo '<pre><code class="language-', htmlspecialchars($lang), '">',
|
|
157
|
+
htmlspecialchars($code),
|
|
158
|
+
"</code></pre>\n";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
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\Essential;
|
|
11
|
+
|
|
12
|
+
use Latte;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Smarter caching iterator.
|
|
17
|
+
*
|
|
18
|
+
* @property-read bool $first
|
|
19
|
+
* @property-read bool $last
|
|
20
|
+
* @property-read bool $empty
|
|
21
|
+
* @property-read bool $odd
|
|
22
|
+
* @property-read bool $even
|
|
23
|
+
* @property-read int $counter
|
|
24
|
+
* @property-read int $counter0
|
|
25
|
+
* @property-read mixed $nextKey
|
|
26
|
+
* @property-read mixed $nextValue
|
|
27
|
+
* @property-read ?self $parent
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
class CachingIterator extends \CachingIterator implements \Countable
|
|
31
|
+
{
|
|
32
|
+
use Latte\Strict;
|
|
33
|
+
|
|
34
|
+
private int $counter = 0;
|
|
35
|
+
private ?self $parent = null;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
public function __construct(mixed $iterator, ?self $parent = null)
|
|
39
|
+
{
|
|
40
|
+
if (is_array($iterator) || $iterator instanceof \stdClass) {
|
|
41
|
+
$iterator = new \ArrayIterator($iterator);
|
|
42
|
+
|
|
43
|
+
} elseif ($iterator instanceof \IteratorAggregate) {
|
|
44
|
+
do {
|
|
45
|
+
$iterator = $iterator->getIterator();
|
|
46
|
+
} while (!$iterator instanceof \Iterator);
|
|
47
|
+
} elseif ($iterator instanceof \Traversable) {
|
|
48
|
+
if (!$iterator instanceof \Iterator) {
|
|
49
|
+
$iterator = new \IteratorIterator($iterator);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
throw new \InvalidArgumentException(sprintf('Invalid argument passed to foreach; array or Traversable expected, %s given.', is_object($iterator) ? $iterator::class : gettype($iterator)));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
parent::__construct($iterator, 0);
|
|
56
|
+
$this->parent = $parent;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Is the current element the first one?
|
|
62
|
+
*/
|
|
63
|
+
public function isFirst(?int $width = null): bool
|
|
64
|
+
{
|
|
65
|
+
return $this->counter === 1 || ($width && $this->counter !== 0 && (($this->counter - 1) % $width) === 0);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Is the current element the last one?
|
|
71
|
+
*/
|
|
72
|
+
public function isLast(?int $width = null): bool
|
|
73
|
+
{
|
|
74
|
+
return !$this->hasNext() || ($width && ($this->counter % $width) === 0);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Is the iterator empty?
|
|
80
|
+
*/
|
|
81
|
+
public function isEmpty(): bool
|
|
82
|
+
{
|
|
83
|
+
return $this->counter === 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Is the counter odd?
|
|
89
|
+
*/
|
|
90
|
+
public function isOdd(): bool
|
|
91
|
+
{
|
|
92
|
+
return $this->counter % 2 === 1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Is the counter even?
|
|
98
|
+
*/
|
|
99
|
+
public function isEven(): bool
|
|
100
|
+
{
|
|
101
|
+
return $this->counter % 2 === 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Returns the 1-indexed counter.
|
|
107
|
+
*/
|
|
108
|
+
public function getCounter(): int
|
|
109
|
+
{
|
|
110
|
+
return $this->counter;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Returns the 0-indexed counter.
|
|
116
|
+
*/
|
|
117
|
+
public function getCounter0(): int
|
|
118
|
+
{
|
|
119
|
+
return max(0, $this->counter - 1);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Decrements counter.
|
|
125
|
+
*/
|
|
126
|
+
public function skipRound(): void
|
|
127
|
+
{
|
|
128
|
+
$this->counter = max($this->counter - 1, 0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns the counter as string
|
|
134
|
+
*/
|
|
135
|
+
public function __toString(): string
|
|
136
|
+
{
|
|
137
|
+
return (string) $this->counter;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Returns the count of elements.
|
|
143
|
+
*/
|
|
144
|
+
public function count(): int
|
|
145
|
+
{
|
|
146
|
+
$inner = $this->getInnerIterator();
|
|
147
|
+
if ($inner instanceof \Countable) {
|
|
148
|
+
return $inner->count();
|
|
149
|
+
|
|
150
|
+
} else {
|
|
151
|
+
throw new \LogicException('Iterator is not countable.');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Forwards to the next element.
|
|
158
|
+
*/
|
|
159
|
+
public function next(): void
|
|
160
|
+
{
|
|
161
|
+
parent::next();
|
|
162
|
+
if (parent::valid()) {
|
|
163
|
+
$this->counter++;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Rewinds the Iterator.
|
|
170
|
+
*/
|
|
171
|
+
public function rewind(): void
|
|
172
|
+
{
|
|
173
|
+
parent::rewind();
|
|
174
|
+
$this->counter = parent::valid() ? 1 : 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Returns the next key or null if position is not valid.
|
|
180
|
+
*/
|
|
181
|
+
public function getNextKey(): mixed
|
|
182
|
+
{
|
|
183
|
+
$iterator = $this->getInnerIterator();
|
|
184
|
+
return $iterator->valid() ? $iterator->key() : null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Returns the next element or null if position is not valid.
|
|
190
|
+
*/
|
|
191
|
+
public function getNextValue(): mixed
|
|
192
|
+
{
|
|
193
|
+
$iterator = $this->getInnerIterator();
|
|
194
|
+
return $iterator->valid() ? $iterator->current() : null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Returns the iterator surrounding the current one.
|
|
200
|
+
*/
|
|
201
|
+
public function getParent(): ?self
|
|
202
|
+
{
|
|
203
|
+
return $this->parent;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
/********************* property accessor ****************d*g**/
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Returns property value.
|
|
212
|
+
* @throws \LogicException if the property is not defined.
|
|
213
|
+
*/
|
|
214
|
+
public function &__get(string $name): mixed
|
|
215
|
+
{
|
|
216
|
+
if (method_exists($this, $m = 'get' . $name) || method_exists($this, $m = 'is' . $name)) {
|
|
217
|
+
$ret = $this->$m();
|
|
218
|
+
return $ret;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
throw new \LogicException('Attempt to read undeclared property ' . static::class . "::\$$name.");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Is property defined?
|
|
227
|
+
*/
|
|
228
|
+
public function __isset(string $name): bool
|
|
229
|
+
{
|
|
230
|
+
return method_exists($this, 'get' . $name) || method_exists($this, 'is' . $name);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
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\Essential;
|
|
11
|
+
|
|
12
|
+
use Latte;
|
|
13
|
+
use Latte\Compiler\Nodes\Php\Scalar;
|
|
14
|
+
use Latte\Compiler\Nodes\TemplateNode;
|
|
15
|
+
use Latte\Compiler\Nodes\TextNode;
|
|
16
|
+
use Latte\Compiler\Tag;
|
|
17
|
+
use Latte\Compiler\TemplateParser;
|
|
18
|
+
use Latte\RuntimeException;
|
|
19
|
+
use Nette;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Basic tags and filters for Latte.
|
|
24
|
+
*/
|
|
25
|
+
final class CoreExtension extends Latte\Extension
|
|
26
|
+
{
|
|
27
|
+
use Latte\Strict;
|
|
28
|
+
|
|
29
|
+
private array $functions;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
public function beforeCompile(Latte\Engine $engine): void
|
|
33
|
+
{
|
|
34
|
+
$this->functions = $engine->getFunctions();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
public function getTags(): array
|
|
39
|
+
{
|
|
40
|
+
return [
|
|
41
|
+
'embed' => [Nodes\EmbedNode::class, 'create'],
|
|
42
|
+
'define' => [Nodes\DefineNode::class, 'create'],
|
|
43
|
+
'block' => [Nodes\BlockNode::class, 'create'],
|
|
44
|
+
'layout' => [Nodes\ExtendsNode::class, 'create'],
|
|
45
|
+
'extends' => [Nodes\ExtendsNode::class, 'create'],
|
|
46
|
+
'import' => [Nodes\ImportNode::class, 'create'],
|
|
47
|
+
'include' => \Closure::fromCallable([$this, 'includeSplitter']),
|
|
48
|
+
|
|
49
|
+
'n:attr' => [Nodes\NAttrNode::class, 'create'],
|
|
50
|
+
'n:class' => [Nodes\NClassNode::class, 'create'],
|
|
51
|
+
'n:tag' => [Nodes\NTagNode::class, 'create'],
|
|
52
|
+
|
|
53
|
+
'parameters' => [Nodes\ParametersNode::class, 'create'],
|
|
54
|
+
'varType' => [Nodes\VarTypeNode::class, 'create'],
|
|
55
|
+
'varPrint' => [Nodes\VarPrintNode::class, 'create'],
|
|
56
|
+
'templateType' => [Nodes\TemplateTypeNode::class, 'create'],
|
|
57
|
+
'templatePrint' => [Nodes\TemplatePrintNode::class, 'create'],
|
|
58
|
+
|
|
59
|
+
'=' => [Nodes\PrintNode::class, 'create'],
|
|
60
|
+
'do' => [Nodes\DoNode::class, 'create'],
|
|
61
|
+
'php' => [Nodes\DoNode::class, 'create'], // obsolete
|
|
62
|
+
'contentType' => [Nodes\ContentTypeNode::class, 'create'],
|
|
63
|
+
'spaceless' => [Nodes\SpacelessNode::class, 'create'],
|
|
64
|
+
'capture' => [Nodes\CaptureNode::class, 'create'],
|
|
65
|
+
'l' => fn(Tag $tag) => new TextNode('{', $tag->position),
|
|
66
|
+
'r' => fn(Tag $tag) => new TextNode('}', $tag->position),
|
|
67
|
+
'syntax' => \Closure::fromCallable([$this, 'parseSyntax']),
|
|
68
|
+
|
|
69
|
+
'dump' => [Nodes\DumpNode::class, 'create'],
|
|
70
|
+
'debugbreak' => [Nodes\DebugbreakNode::class, 'create'],
|
|
71
|
+
'trace' => [Nodes\TraceNode::class, 'create'],
|
|
72
|
+
|
|
73
|
+
'var' => [Nodes\VarNode::class, 'create'],
|
|
74
|
+
'default' => [Nodes\VarNode::class, 'create'],
|
|
75
|
+
|
|
76
|
+
'try' => [Nodes\TryNode::class, 'create'],
|
|
77
|
+
'rollback' => [Nodes\RollbackNode::class, 'create'],
|
|
78
|
+
|
|
79
|
+
'foreach' => [Nodes\ForeachNode::class, 'create'],
|
|
80
|
+
'for' => [Nodes\ForNode::class, 'create'],
|
|
81
|
+
'while' => [Nodes\WhileNode::class, 'create'],
|
|
82
|
+
'iterateWhile' => [Nodes\IterateWhileNode::class, 'create'],
|
|
83
|
+
'sep' => [Nodes\FirstLastSepNode::class, 'create'],
|
|
84
|
+
'last' => [Nodes\FirstLastSepNode::class, 'create'],
|
|
85
|
+
'first' => [Nodes\FirstLastSepNode::class, 'create'],
|
|
86
|
+
'skipIf' => [Nodes\SkipNode::class, 'create'],
|
|
87
|
+
'breakIf' => [Nodes\SkipNode::class, 'create'],
|
|
88
|
+
'continueIf' => [Nodes\SkipNode::class, 'create'],
|
|
89
|
+
|
|
90
|
+
'if' => [Nodes\IfNode::class, 'create'],
|
|
91
|
+
'ifset' => [Nodes\IfNode::class, 'create'],
|
|
92
|
+
'ifchanged' => [Nodes\IfChangedNode::class, 'create'],
|
|
93
|
+
'n:ifcontent' => [Nodes\IfContentNode::class, 'create'],
|
|
94
|
+
'switch' => [Nodes\SwitchNode::class, 'create'],
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
public function getFilters(): array
|
|
100
|
+
{
|
|
101
|
+
return [
|
|
102
|
+
'batch' => [Filters::class, 'batch'],
|
|
103
|
+
'breakLines' => [Filters::class, 'breaklines'],
|
|
104
|
+
'breaklines' => [Filters::class, 'breaklines'],
|
|
105
|
+
'bytes' => [Filters::class, 'bytes'],
|
|
106
|
+
'capitalize' => extension_loaded('mbstring')
|
|
107
|
+
? [Filters::class, 'capitalize']
|
|
108
|
+
: function () { throw new RuntimeException('Filter |capitalize requires mbstring extension.'); },
|
|
109
|
+
'ceil' => [Filters::class, 'ceil'],
|
|
110
|
+
'clamp' => [Filters::class, 'clamp'],
|
|
111
|
+
'dataStream' => [Filters::class, 'dataStream'],
|
|
112
|
+
'datastream' => [Filters::class, 'dataStream'],
|
|
113
|
+
'date' => [Filters::class, 'date'],
|
|
114
|
+
'escapeCss' => [Latte\Runtime\Filters::class, 'escapeCss'],
|
|
115
|
+
'escapeHtml' => [Latte\Runtime\Filters::class, 'escapeHtml'],
|
|
116
|
+
'escapeHtmlComment' => [Latte\Runtime\Filters::class, 'escapeHtmlComment'],
|
|
117
|
+
'escapeICal' => [Latte\Runtime\Filters::class, 'escapeICal'],
|
|
118
|
+
'escapeJs' => [Latte\Runtime\Filters::class, 'escapeJs'],
|
|
119
|
+
'escapeUrl' => 'rawurlencode',
|
|
120
|
+
'escapeXml' => [Latte\Runtime\Filters::class, 'escapeXml'],
|
|
121
|
+
'explode' => [Filters::class, 'explode'],
|
|
122
|
+
'first' => [Filters::class, 'first'],
|
|
123
|
+
'firstUpper' => extension_loaded('mbstring')
|
|
124
|
+
? [Filters::class, 'firstUpper']
|
|
125
|
+
: function () { throw new RuntimeException('Filter |firstUpper requires mbstring extension.'); },
|
|
126
|
+
'floor' => [Filters::class, 'floor'],
|
|
127
|
+
'checkUrl' => [Latte\Runtime\Filters::class, 'safeUrl'],
|
|
128
|
+
'implode' => [Filters::class, 'implode'],
|
|
129
|
+
'indent' => [Filters::class, 'indent'],
|
|
130
|
+
'join' => [Filters::class, 'implode'],
|
|
131
|
+
'last' => [Filters::class, 'last'],
|
|
132
|
+
'length' => [Filters::class, 'length'],
|
|
133
|
+
'lower' => extension_loaded('mbstring')
|
|
134
|
+
? [Filters::class, 'lower']
|
|
135
|
+
: function () { throw new RuntimeException('Filter |lower requires mbstring extension.'); },
|
|
136
|
+
'number' => 'number_format',
|
|
137
|
+
'padLeft' => [Filters::class, 'padLeft'],
|
|
138
|
+
'padRight' => [Filters::class, 'padRight'],
|
|
139
|
+
'query' => [Filters::class, 'query'],
|
|
140
|
+
'random' => [Filters::class, 'random'],
|
|
141
|
+
'repeat' => [Filters::class, 'repeat'],
|
|
142
|
+
'replace' => [Filters::class, 'replace'],
|
|
143
|
+
'replaceRe' => [Filters::class, 'replaceRe'],
|
|
144
|
+
'replaceRE' => [Filters::class, 'replaceRe'],
|
|
145
|
+
'reverse' => [Filters::class, 'reverse'],
|
|
146
|
+
'round' => [Filters::class, 'round'],
|
|
147
|
+
'slice' => [Filters::class, 'slice'],
|
|
148
|
+
'sort' => [Filters::class, 'sort'],
|
|
149
|
+
'spaceless' => [Filters::class, 'strip'],
|
|
150
|
+
'split' => [Filters::class, 'explode'],
|
|
151
|
+
'strip' => [Filters::class, 'strip'], // obsolete
|
|
152
|
+
'stripHtml' => [Filters::class, 'stripHtml'],
|
|
153
|
+
'striphtml' => [Filters::class, 'stripHtml'],
|
|
154
|
+
'stripTags' => [Filters::class, 'stripTags'],
|
|
155
|
+
'striptags' => [Filters::class, 'stripTags'],
|
|
156
|
+
'substr' => [Filters::class, 'substring'],
|
|
157
|
+
'trim' => [Filters::class, 'trim'],
|
|
158
|
+
'truncate' => [Filters::class, 'truncate'],
|
|
159
|
+
'upper' => extension_loaded('mbstring')
|
|
160
|
+
? [Filters::class, 'upper']
|
|
161
|
+
: function () { throw new RuntimeException('Filter |upper requires mbstring extension.'); },
|
|
162
|
+
'webalize' => class_exists(Nette\Utils\Strings::class)
|
|
163
|
+
? [Nette\Utils\Strings::class, 'webalize']
|
|
164
|
+
: function () { throw new RuntimeException('Filter |webalize requires nette/utils package.'); },
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
public function getFunctions(): array
|
|
170
|
+
{
|
|
171
|
+
return [
|
|
172
|
+
'clamp' => [Filters::class, 'clamp'],
|
|
173
|
+
'divisibleBy' => [Filters::class, 'divisibleBy'],
|
|
174
|
+
'even' => [Filters::class, 'even'],
|
|
175
|
+
'first' => [Filters::class, 'first'],
|
|
176
|
+
'last' => [Filters::class, 'last'],
|
|
177
|
+
'odd' => [Filters::class, 'odd'],
|
|
178
|
+
'slice' => [Filters::class, 'slice'],
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
public function getPasses(): array
|
|
184
|
+
{
|
|
185
|
+
return [
|
|
186
|
+
'internalVariables' => [Passes::class, 'internalVariablesPass'],
|
|
187
|
+
'overwrittenVariables' => [Passes::class, 'overwrittenVariablesPass'],
|
|
188
|
+
'customFunctions' => fn(TemplateNode $node) => Passes::customFunctionsPass($node, $this->functions),
|
|
189
|
+
'moveTemplatePrintToHead' => [Passes::class, 'moveTemplatePrintToHeadPass'],
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* {include [file] "file" [with blocks] [,] [params]}
|
|
196
|
+
* {include [block] name [,] [params]}
|
|
197
|
+
*/
|
|
198
|
+
private function includeSplitter(Tag $tag, TemplateParser $parser): Nodes\IncludeBlockNode|Nodes\IncludeFileNode
|
|
199
|
+
{
|
|
200
|
+
$tag->expectArguments();
|
|
201
|
+
$mod = $tag->parser->tryConsumeModifier('block', 'file');
|
|
202
|
+
if ($mod) {
|
|
203
|
+
$block = $mod->text === 'block';
|
|
204
|
+
} elseif ($tag->parser->stream->tryConsume('#')) {
|
|
205
|
+
$block = true;
|
|
206
|
+
} else {
|
|
207
|
+
$name = $tag->parser->parseUnquotedStringOrExpression();
|
|
208
|
+
$block = $name instanceof Scalar\StringNode && preg_match('~[\w-]+$~DA', $name->value);
|
|
209
|
+
}
|
|
210
|
+
$tag->parser->stream->seek(0);
|
|
211
|
+
|
|
212
|
+
return $block
|
|
213
|
+
? Nodes\IncludeBlockNode::create($tag, $parser)
|
|
214
|
+
: Nodes\IncludeFileNode::create($tag);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* {syntax ...}
|
|
220
|
+
*/
|
|
221
|
+
private function parseSyntax(Tag $tag, TemplateParser $parser): \Generator
|
|
222
|
+
{
|
|
223
|
+
$tag->expectArguments();
|
|
224
|
+
$token = $tag->parser->stream->consume();
|
|
225
|
+
$lexer = $parser->getLexer();
|
|
226
|
+
$saved = [$lexer->openDelimiter, $lexer->closeDelimiter];
|
|
227
|
+
$lexer->setSyntax($token->text, $tag->isNAttribute() ? null : $tag->name);
|
|
228
|
+
[$inner] = yield;
|
|
229
|
+
[$lexer->openDelimiter, $lexer->closeDelimiter] = $saved;
|
|
230
|
+
return $inner;
|
|
231
|
+
}
|
|
232
|
+
}
|