@vituum/vite-plugin-latte 2.0.0-next.5 → 2.0.1
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 +1 -1
- package/index.js +2 -1
- package/package.json +20 -10
- package/vendor/composer/autoload_classmap.php +3 -2
- package/vendor/composer/autoload_static.php +3 -2
- package/vendor/composer/installed.json +21 -17
- package/vendor/composer/installed.php +8 -8
- package/vendor/latte/latte/composer.json +9 -2
- package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +7 -7
- package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +5 -4
- package/vendor/latte/latte/src/Bridges/Tracy/TracyExtension.php +2 -4
- package/vendor/latte/latte/src/Bridges/Tracy/dist/panel.phtml +2 -4
- package/vendor/latte/latte/src/Bridges/Tracy/dist/tab.phtml +2 -4
- package/vendor/latte/latte/src/Latte/Compiler/Block.php +1 -3
- package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +4 -8
- package/vendor/latte/latte/src/Latte/Compiler/Node.php +6 -3
- package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +15 -6
- package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +14 -9
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +7 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +6 -5
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +4 -6
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +5 -7
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ExpressionAttributeNode.php +6 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/TagNode.php +1 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArrayItemNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ClosureUseNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AuxiliaryNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +7 -6
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticMethodCallNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TemporaryNode.php +7 -6
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/InterpolatedStringPartNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListItemNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/OperatorNode.php +1 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/InterpolatedStringNode.php +6 -5
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VariadicPlaceholderNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/PrintNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +7 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +23 -15
- package/vendor/latte/latte/src/Latte/Compiler/Position.php +5 -7
- package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +30 -9
- package/vendor/latte/latte/src/Latte/Compiler/Tag.php +6 -6
- package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +4 -6
- package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +14 -11
- package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +2 -4
- package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +13 -11
- package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +21 -7
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +32 -19
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +28 -21
- package/vendor/latte/latte/src/Latte/Compiler/Token.php +10 -9
- package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +20 -14
- package/vendor/latte/latte/src/Latte/ContentType.php +4 -3
- package/vendor/latte/latte/src/Latte/Engine.php +64 -35
- package/vendor/latte/latte/src/Latte/Essential/AuxiliaryIterator.php +3 -7
- package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +4 -5
- package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +2 -3
- package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +1 -3
- package/vendor/latte/latte/src/Latte/Essential/Filters.php +65 -32
- package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +8 -6
- package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +5 -6
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/CustomFunctionCallNode.php +2 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +2 -3
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +6 -6
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +2 -3
- package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +3 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +3 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +4 -7
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +3 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +7 -8
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +4 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +7 -6
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +6 -9
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +8 -7
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +2 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +6 -6
- package/vendor/latte/latte/src/Latte/Essential/Nodes/JumpNode.php +4 -8
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +3 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NElseNode.php +8 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +4 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +4 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +2 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +2 -3
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +4 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +9 -7
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +2 -3
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +4 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +8 -7
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +2 -3
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +5 -5
- package/vendor/latte/latte/src/Latte/Essential/Passes.php +26 -15
- package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +1 -3
- package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +1 -3
- package/vendor/latte/latte/src/Latte/Essential/Tracer.php +20 -13
- package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +9 -10
- package/vendor/latte/latte/src/Latte/Extension.php +10 -6
- package/vendor/latte/latte/src/Latte/Feature.php +24 -0
- package/vendor/latte/latte/src/Latte/Helpers.php +18 -10
- package/vendor/latte/latte/src/Latte/Loader.php +1 -3
- package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +8 -5
- package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +5 -13
- package/vendor/latte/latte/src/Latte/Policy.php +4 -3
- package/vendor/latte/latte/src/Latte/Runtime/Block.php +2 -4
- package/vendor/latte/latte/src/Latte/{Cache.php → Runtime/Cache.php} +12 -11
- package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +3 -5
- package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +10 -11
- package/vendor/latte/latte/src/Latte/Runtime/FunctionExecutor.php +4 -6
- package/vendor/latte/latte/src/Latte/Runtime/Helpers.php +5 -7
- package/vendor/latte/latte/src/Latte/Runtime/Html.php +3 -5
- package/vendor/latte/latte/src/Latte/Runtime/HtmlHelpers.php +18 -18
- package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +1 -3
- package/vendor/latte/latte/src/Latte/Runtime/Template.php +23 -42
- package/vendor/latte/latte/src/Latte/Runtime/XmlHelpers.php +5 -7
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +14 -8
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +17 -11
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +3 -4
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticMethodCallNode.php +16 -10
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +6 -5
- package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +5 -4
- package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +17 -16
- package/vendor/latte/latte/src/Latte/attributes.php +7 -3
- package/vendor/latte/latte/src/Latte/exceptions.php +38 -3
- package/vendor/latte/latte/src/Tools/Linter.php +20 -14
- package/vendor/latte/latte/src/Tools/LinterExtension.php +26 -7
- package/vendor/nette/utils/composer.json +8 -1
- package/vendor/nette/utils/src/HtmlStringable.php +4 -1
- package/vendor/nette/utils/src/Iterators/CachingIterator.php +9 -24
- package/vendor/nette/utils/src/Iterators/Mapper.php +2 -3
- package/vendor/nette/utils/src/SmartObject.php +3 -0
- package/vendor/nette/utils/src/StaticClass.php +1 -1
- package/vendor/nette/utils/src/Translator.php +1 -1
- package/vendor/nette/utils/src/Utils/ArrayHash.php +1 -5
- package/vendor/nette/utils/src/Utils/ArrayList.php +3 -6
- package/vendor/nette/utils/src/Utils/Arrays.php +33 -10
- package/vendor/nette/utils/src/Utils/Callback.php +12 -7
- package/vendor/nette/utils/src/Utils/DateTime.php +1 -1
- package/vendor/nette/utils/src/Utils/FileInfo.php +5 -7
- package/vendor/nette/utils/src/Utils/FileSystem.php +5 -2
- package/vendor/nette/utils/src/Utils/Finder.php +27 -8
- package/vendor/nette/utils/src/Utils/Helpers.php +7 -1
- package/vendor/nette/utils/src/Utils/Html.php +123 -118
- package/vendor/nette/utils/src/Utils/Image.php +72 -54
- package/vendor/nette/utils/src/Utils/ImageColor.php +4 -0
- package/vendor/nette/utils/src/Utils/Iterables.php +16 -8
- package/vendor/nette/utils/src/Utils/Paginator.php +10 -43
- package/vendor/nette/utils/src/Utils/Reflection.php +17 -7
- package/vendor/nette/utils/src/Utils/ReflectionMethod.php +4 -1
- package/vendor/nette/utils/src/Utils/Strings.php +48 -15
- package/vendor/nette/utils/src/Utils/Type.php +41 -27
- package/vendor/nette/utils/src/Utils/Validators.php +8 -7
- package/vendor/latte/latte/src/Bridges/Tracy/panel.latte +0 -94
- package/vendor/latte/latte/src/Bridges/Tracy/tab.latte +0 -8
- package/vendor/latte/latte/src/Latte/PositionAwareException.php +0 -47
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte;
|
|
11
9
|
|
|
12
10
|
use function array_filter, array_keys, array_search, array_slice, array_unique, count, is_array, is_object, is_string, levenshtein, max, min, strlen, strpos;
|
|
@@ -39,7 +37,7 @@ class Helpers
|
|
|
39
37
|
|
|
40
38
|
|
|
41
39
|
/** intentionally without callable typehint, because it generates bad error messages */
|
|
42
|
-
public static function toReflection($callable): \ReflectionFunctionAbstract
|
|
40
|
+
public static function toReflection(mixed $callable): \ReflectionFunctionAbstract
|
|
43
41
|
{
|
|
44
42
|
if (is_string($callable) && strpos($callable, '::')) {
|
|
45
43
|
return PHP_VERSION_ID < 80300
|
|
@@ -55,6 +53,10 @@ class Helpers
|
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @param array<string, mixed|\stdClass> $list
|
|
58
|
+
* @return array<string, mixed|\stdClass>
|
|
59
|
+
*/
|
|
58
60
|
public static function sortBeforeAfter(array $list): array
|
|
59
61
|
{
|
|
60
62
|
foreach ($list as $name => $info) {
|
|
@@ -70,7 +72,7 @@ class Helpers
|
|
|
70
72
|
if ($target === '*') {
|
|
71
73
|
$best = 0;
|
|
72
74
|
} elseif (isset($list[$target])) {
|
|
73
|
-
$pos = array_search($target, $names, true);
|
|
75
|
+
$pos = (int) array_search($target, $names, strict: true);
|
|
74
76
|
$best = min($pos, $best ?? $pos);
|
|
75
77
|
}
|
|
76
78
|
}
|
|
@@ -79,20 +81,22 @@ class Helpers
|
|
|
79
81
|
if ($target === '*') {
|
|
80
82
|
$best = count($names);
|
|
81
83
|
} elseif (isset($list[$target])) {
|
|
82
|
-
$pos = array_search($target, $names, true);
|
|
84
|
+
$pos = (int) array_search($target, $names, strict: true);
|
|
83
85
|
$best = max($pos + 1, $best);
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
$
|
|
89
|
+
$best ??= count($names);
|
|
90
|
+
$list = array_slice($list, 0, $best, preserve_keys: true)
|
|
88
91
|
+ [$name => $info]
|
|
89
|
-
+ array_slice($list, $best, null, true);
|
|
92
|
+
+ array_slice($list, $best, null, preserve_keys: true);
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
return $list;
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
|
|
99
|
+
/** @param mixed[] $items */
|
|
96
100
|
public static function removeNulls(array &$items): void
|
|
97
101
|
{
|
|
98
102
|
$items = array_values(array_filter($items, fn($item) => $item !== null));
|
|
@@ -101,14 +105,18 @@ class Helpers
|
|
|
101
105
|
|
|
102
106
|
/**
|
|
103
107
|
* Attempts to map the compiled template to the source.
|
|
108
|
+
* @return array{name: ?string, line: ?int, column: ?int}|null
|
|
104
109
|
*/
|
|
105
110
|
public static function mapCompiledToSource(string $compiledFile, ?int $compiledLine = null): ?array
|
|
106
111
|
{
|
|
107
|
-
if (!Cache::isCacheFile($compiledFile)) {
|
|
112
|
+
if (!Runtime\Cache::isCacheFile($compiledFile)) {
|
|
108
113
|
return null;
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
$content = file_get_contents($compiledFile);
|
|
117
|
+
if ($content === false) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
112
120
|
$name = preg_match('#^/\*\* source: (\S.+) \*/#m', $content, $m) ? $m[1] : null;
|
|
113
121
|
$compiledLine && preg_match('~/\* pos (\d+)(?::(\d+))? \*/~', explode("\n", $content)[$compiledLine - 1], $pos);
|
|
114
122
|
$line = isset($pos[1]) ? (int) $pos[1] : null;
|
|
@@ -124,7 +132,7 @@ class Helpers
|
|
|
124
132
|
{
|
|
125
133
|
$trace = debug_backtrace();
|
|
126
134
|
foreach ($trace as $item) {
|
|
127
|
-
if (isset($item['file']) && ($source = self::mapCompiledToSource($item['file'], $item['line']))) {
|
|
135
|
+
if (isset($item['file']) && ($source = self::mapCompiledToSource($item['file'], $item['line'] ?? null))) {
|
|
128
136
|
$res = [];
|
|
129
137
|
if ($source['name'] && is_file($source['name'])) {
|
|
130
138
|
$res[] = "in '" . str_replace(dirname($source['name'], 2), '...', $source['name']) . "'";
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte\Loaders;
|
|
11
9
|
|
|
12
10
|
use Latte;
|
|
@@ -15,7 +13,7 @@ use const DIRECTORY_SEPARATOR;
|
|
|
15
13
|
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
16
|
+
* Loads templates from filesystem.
|
|
19
17
|
*/
|
|
20
18
|
class FileLoader implements Latte\Loader
|
|
21
19
|
{
|
|
@@ -41,7 +39,12 @@ class FileLoader implements Latte\Loader
|
|
|
41
39
|
throw new Latte\TemplateNotFoundException("Missing template file '$file'.");
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
$content = file_get_contents($file);
|
|
43
|
+
if ($content === false) {
|
|
44
|
+
throw new Latte\RuntimeException("Unable to read file '$file'.");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return $content;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte\Loaders;
|
|
11
9
|
|
|
12
10
|
use Latte;
|
|
@@ -17,16 +15,10 @@ use Latte;
|
|
|
17
15
|
*/
|
|
18
16
|
class StringLoader implements Latte\Loader
|
|
19
17
|
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @param string[] $templates
|
|
26
|
-
*/
|
|
27
|
-
public function __construct(?array $templates = null)
|
|
28
|
-
{
|
|
29
|
-
$this->templates = $templates;
|
|
18
|
+
public function __construct(
|
|
19
|
+
/** @var array<string, string>|null */
|
|
20
|
+
private ?array $templates = null,
|
|
21
|
+
) {
|
|
30
22
|
}
|
|
31
23
|
|
|
32
24
|
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte;
|
|
11
9
|
|
|
12
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Security policy for sandbox mode.
|
|
13
|
+
*/
|
|
13
14
|
interface Policy
|
|
14
15
|
{
|
|
15
16
|
function isTagAllowed(string $tag): bool;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte\Runtime;
|
|
11
9
|
|
|
12
10
|
|
|
@@ -15,6 +13,6 @@ final class Block
|
|
|
15
13
|
{
|
|
16
14
|
public ?string $contentType = null;
|
|
17
15
|
|
|
18
|
-
/** @var
|
|
16
|
+
/** @var \Closure[] */
|
|
19
17
|
public array $functions = [];
|
|
20
18
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
namespace Latte;
|
|
8
|
+
namespace Latte\Runtime;
|
|
11
9
|
|
|
10
|
+
use Latte\Engine;
|
|
11
|
+
use Latte\RuntimeException;
|
|
12
12
|
use function array_map, defined, dirname, file_put_contents, filemtime, flock, fopen, fseek, ftell, ftruncate, function_exists, fwrite, is_dir, is_file, mkdir, preg_match, preg_replace, rename, serialize, stream_get_contents, strlen, substr, unlink;
|
|
13
13
|
use const LOCK_EX, LOCK_SH, LOCK_UN;
|
|
14
14
|
|
|
@@ -42,7 +42,7 @@ final class Cache
|
|
|
42
42
|
: null;
|
|
43
43
|
|
|
44
44
|
if (
|
|
45
|
-
!($signature && $signature !== stream_get_contents($lock))
|
|
45
|
+
!($signature && $lock && $signature !== stream_get_contents($lock))
|
|
46
46
|
&& (@include $file) !== false // @ - file may not exist
|
|
47
47
|
) {
|
|
48
48
|
return;
|
|
@@ -68,10 +68,10 @@ final class Cache
|
|
|
68
68
|
|
|
69
69
|
fseek($lock, 0);
|
|
70
70
|
fwrite($lock, $signature ?? hash('xxh128', serialize($this->generateRefreshSignature($engine, $name))));
|
|
71
|
-
ftruncate($lock, ftell($lock));
|
|
71
|
+
ftruncate($lock, (int) ftell($lock));
|
|
72
72
|
|
|
73
73
|
if (function_exists('opcache_invalidate')) {
|
|
74
|
-
@opcache_invalidate($file, true); // @ can be restricted
|
|
74
|
+
@opcache_invalidate($file, force: true); // @ can be restricted
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -88,14 +88,14 @@ final class Cache
|
|
|
88
88
|
{
|
|
89
89
|
$dir = dirname($file);
|
|
90
90
|
if (!is_dir($dir) && !@mkdir($dir) && !is_dir($dir)) { // @ - dir may already exist
|
|
91
|
-
throw new RuntimeException("Unable to create directory '$dir'. " . error_get_last()['message']);
|
|
91
|
+
throw new RuntimeException("Unable to create directory '$dir'. " . (error_get_last()['message'] ?? ''));
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
$handle = @fopen($file, 'c+'); // @ is escalated to exception
|
|
95
95
|
if (!$handle) {
|
|
96
|
-
throw new RuntimeException("Unable to create file '$file'. " . error_get_last()['message']);
|
|
96
|
+
throw new RuntimeException("Unable to create file '$file'. " . (error_get_last()['message'] ?? ''));
|
|
97
97
|
} elseif (!@flock($handle, $mode)) { // @ is escalated to exception
|
|
98
|
-
throw new RuntimeException('Unable to acquire ' . ($mode & LOCK_EX ? 'exclusive' : 'shared') . " lock on file '$file'. " . error_get_last()['message']);
|
|
98
|
+
throw new RuntimeException('Unable to acquire ' . ($mode & LOCK_EX ? 'exclusive' : 'shared') . " lock on file '$file'. " . (error_get_last()['message'] ?? ''));
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
return $handle;
|
|
@@ -127,6 +127,7 @@ final class Cache
|
|
|
127
127
|
/**
|
|
128
128
|
* Returns values used to detect if cached template needs recompilation when autoRefresh is enabled.
|
|
129
129
|
* Triggers recompilation when template code, Latte engine, or any extension changes.
|
|
130
|
+
* @return list<mixed>
|
|
130
131
|
*/
|
|
131
132
|
protected function generateRefreshSignature(Engine $engine, string $name): array
|
|
132
133
|
{
|
|
@@ -134,7 +135,7 @@ final class Cache
|
|
|
134
135
|
Engine::Version,
|
|
135
136
|
$engine->getLoader()->getContent($name),
|
|
136
137
|
array_map(
|
|
137
|
-
fn($extension) => filemtime((new \ReflectionObject($extension))->getFileName()),
|
|
138
|
+
fn($extension) => @filemtime((string) (new \ReflectionObject($extension))->getFileName()), // @ file may not exist
|
|
138
139
|
$engine->getExtensions(),
|
|
139
140
|
),
|
|
140
141
|
];
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte\Runtime;
|
|
11
9
|
|
|
12
10
|
use Latte;
|
|
@@ -22,7 +20,7 @@ use function array_column, array_combine, array_keys, array_unshift, strtoupper;
|
|
|
22
20
|
#[\AllowDynamicProperties]
|
|
23
21
|
class FilterExecutor
|
|
24
22
|
{
|
|
25
|
-
/** @var callable
|
|
23
|
+
/** @var array<callable> */
|
|
26
24
|
private array $_dynamic = [];
|
|
27
25
|
|
|
28
26
|
/** @var array<string, array{callable, ?bool}> */
|
|
@@ -47,7 +45,7 @@ class FilterExecutor
|
|
|
47
45
|
|
|
48
46
|
/**
|
|
49
47
|
* Returns all run-time filters.
|
|
50
|
-
* @return callable
|
|
48
|
+
* @return array<string, callable>
|
|
51
49
|
*/
|
|
52
50
|
public function getAll(): array
|
|
53
51
|
{
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte\Runtime;
|
|
11
9
|
|
|
12
10
|
use Latte;
|
|
@@ -14,22 +12,23 @@ use function in_array, strtoupper;
|
|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
|
-
*
|
|
15
|
+
* Content type context for contextual filters.
|
|
18
16
|
*/
|
|
19
17
|
class FilterInfo
|
|
20
18
|
{
|
|
21
|
-
public
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
public function __construct(?string $contentType = null)
|
|
25
|
-
{
|
|
26
|
-
$this->contentType = $contentType;
|
|
19
|
+
public function __construct(
|
|
20
|
+
public ?string $contentType = null,
|
|
21
|
+
) {
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Validates content type is allowed for this filter.
|
|
27
|
+
* @param list<string|null> $contentTypes
|
|
28
|
+
*/
|
|
30
29
|
public function validate(array $contentTypes, ?string $name = null): void
|
|
31
30
|
{
|
|
32
|
-
if (!in_array($this->contentType, $contentTypes, true)) {
|
|
31
|
+
if (!in_array($this->contentType, $contentTypes, strict: true)) {
|
|
33
32
|
$name = $name ? " |$name" : $name;
|
|
34
33
|
$type = $this->contentType ? ' ' . strtoupper($this->contentType) : '';
|
|
35
34
|
throw new Latte\RuntimeException("Filter{$name} used with incompatible type{$type}.");
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte\Runtime;
|
|
11
9
|
|
|
12
10
|
use Latte\Helpers;
|
|
@@ -20,10 +18,10 @@ use function array_keys;
|
|
|
20
18
|
#[\AllowDynamicProperties]
|
|
21
19
|
class FunctionExecutor
|
|
22
20
|
{
|
|
23
|
-
/** @var callable
|
|
21
|
+
/** @var array<string, callable> */
|
|
24
22
|
private array $_list = [];
|
|
25
23
|
|
|
26
|
-
/** @var bool
|
|
24
|
+
/** @var array<string, bool> */
|
|
27
25
|
private array $_aware = [];
|
|
28
26
|
|
|
29
27
|
|
|
@@ -40,7 +38,7 @@ class FunctionExecutor
|
|
|
40
38
|
|
|
41
39
|
/**
|
|
42
40
|
* Returns all run-time functions.
|
|
43
|
-
* @return callable
|
|
41
|
+
* @return array<string, callable>
|
|
44
42
|
*/
|
|
45
43
|
public function getAll(): array
|
|
46
44
|
{
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte\Runtime;
|
|
11
9
|
|
|
12
10
|
use Latte;
|
|
@@ -36,7 +34,7 @@ class Helpers
|
|
|
36
34
|
/**
|
|
37
35
|
* Escapes string for use inside CSS template.
|
|
38
36
|
*/
|
|
39
|
-
public static function escapeCss($s): string
|
|
37
|
+
public static function escapeCss(mixed $s): string
|
|
40
38
|
{
|
|
41
39
|
// http://www.w3.org/TR/2006/WD-CSS21-20060411/syndata.html#q6
|
|
42
40
|
return addcslashes((string) $s, "\x00..\x1F!\"#$%&'()*+,./:;<=>?@[\\]^`{|}~");
|
|
@@ -60,7 +58,7 @@ class Helpers
|
|
|
60
58
|
/**
|
|
61
59
|
* Escapes string for use inside iCal template.
|
|
62
60
|
*/
|
|
63
|
-
public static function escapeICal($s): string
|
|
61
|
+
public static function escapeICal(mixed $s): string
|
|
64
62
|
{
|
|
65
63
|
// https://www.ietf.org/rfc/rfc5545.txt
|
|
66
64
|
$s = str_replace("\r", '', (string) $s);
|
|
@@ -70,7 +68,7 @@ class Helpers
|
|
|
70
68
|
|
|
71
69
|
|
|
72
70
|
/**
|
|
73
|
-
* Converts
|
|
71
|
+
* Converts content between content types.
|
|
74
72
|
*/
|
|
75
73
|
public static function convertTo(FilterInfo $info, string $dest, string $s): string
|
|
76
74
|
{
|
|
@@ -86,7 +84,7 @@ class Helpers
|
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
|
|
89
|
-
public static function nop($s): string
|
|
87
|
+
public static function nop(mixed $s): string
|
|
90
88
|
{
|
|
91
89
|
return (string) $s;
|
|
92
90
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte\Runtime;
|
|
11
9
|
|
|
12
10
|
|
|
@@ -15,10 +13,10 @@ namespace Latte\Runtime;
|
|
|
15
13
|
*/
|
|
16
14
|
class Html implements HtmlStringable
|
|
17
15
|
{
|
|
18
|
-
private string $value;
|
|
16
|
+
private readonly string $value;
|
|
19
17
|
|
|
20
18
|
|
|
21
|
-
public function __construct($value)
|
|
19
|
+
public function __construct(string|\Stringable|null $value)
|
|
22
20
|
{
|
|
23
21
|
$this->value = (string) $value;
|
|
24
22
|
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
<?php
|
|
1
|
+
<?php declare(strict_types=1);
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of the Latte (https://latte.nette.org)
|
|
5
5
|
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare(strict_types=1);
|
|
9
|
-
|
|
10
8
|
namespace Latte\Runtime;
|
|
11
9
|
|
|
12
10
|
use Latte;
|
|
13
11
|
use Latte\ContentType;
|
|
14
12
|
use Nette;
|
|
15
|
-
use function get_debug_type, html_entity_decode, htmlspecialchars, in_array, is_array, is_bool, is_float, is_int,
|
|
16
|
-
use const ENT_HTML5, ENT_NOQUOTES, ENT_QUOTES, ENT_SUBSTITUTE;
|
|
13
|
+
use function get_debug_type, html_entity_decode, htmlspecialchars, in_array, is_array, is_bool, is_float, is_int, is_string, ord, preg_match, preg_replace, preg_replace_callback, str_replace, strip_tags, strtolower, strtr;
|
|
14
|
+
use const ENT_HTML5, ENT_NOQUOTES, ENT_QUOTES, ENT_SUBSTITUTE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_THROW_ON_ERROR, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE;
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
/**
|
|
@@ -38,7 +36,7 @@ final class HtmlHelpers
|
|
|
38
36
|
/**
|
|
39
37
|
* Escapes string for use inside HTML text.
|
|
40
38
|
*/
|
|
41
|
-
public static function escapeText($s): string
|
|
39
|
+
public static function escapeText(mixed $s): string
|
|
42
40
|
{
|
|
43
41
|
if ($s instanceof HtmlStringable || $s instanceof Nette\HtmlStringable) {
|
|
44
42
|
return $s->__toString();
|
|
@@ -53,7 +51,7 @@ final class HtmlHelpers
|
|
|
53
51
|
/**
|
|
54
52
|
* Escapes string for use inside HTML attribute value.
|
|
55
53
|
*/
|
|
56
|
-
public static function escapeAttr($s): string
|
|
54
|
+
public static function escapeAttr(mixed $s): string
|
|
57
55
|
{
|
|
58
56
|
if ($s instanceof HtmlStringable) {
|
|
59
57
|
$s = self::convertHtmlToText($s->__toString());
|
|
@@ -68,7 +66,7 @@ final class HtmlHelpers
|
|
|
68
66
|
/**
|
|
69
67
|
* Escapes string for use inside HTML tag.
|
|
70
68
|
*/
|
|
71
|
-
public static function escapeTag($s): string
|
|
69
|
+
public static function escapeTag(mixed $s): string
|
|
72
70
|
{
|
|
73
71
|
$s = (string) $s;
|
|
74
72
|
$s = htmlspecialchars($s, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE, 'UTF-8');
|
|
@@ -83,7 +81,7 @@ final class HtmlHelpers
|
|
|
83
81
|
/**
|
|
84
82
|
* Escapes string for use inside HTML/XML comments.
|
|
85
83
|
*/
|
|
86
|
-
public static function escapeComment($s): string
|
|
84
|
+
public static function escapeComment(mixed $s): string
|
|
87
85
|
{
|
|
88
86
|
$s = (string) $s;
|
|
89
87
|
if ($s && ($s[0] === '-' || $s[0] === '>' || $s[0] === '!')) {
|
|
@@ -91,7 +89,7 @@ final class HtmlHelpers
|
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
$s = str_replace('--', '- - ', $s);
|
|
94
|
-
if (
|
|
92
|
+
if (str_ends_with($s, '-')) {
|
|
95
93
|
$s .= ' ';
|
|
96
94
|
}
|
|
97
95
|
|
|
@@ -102,7 +100,7 @@ final class HtmlHelpers
|
|
|
102
100
|
/**
|
|
103
101
|
* Escapes HTML for usage in <script type=text/html>
|
|
104
102
|
*/
|
|
105
|
-
public static function escapeRawHtml($s): string
|
|
103
|
+
public static function escapeRawHtml(mixed $s): string
|
|
106
104
|
{
|
|
107
105
|
if ($s instanceof HtmlStringable || $s instanceof Nette\HtmlStringable) {
|
|
108
106
|
return self::convertHtmlToRawText($s->__toString());
|
|
@@ -115,7 +113,7 @@ final class HtmlHelpers
|
|
|
115
113
|
/**
|
|
116
114
|
* Escapes only quotes.
|
|
117
115
|
*/
|
|
118
|
-
public static function escapeQuotes($s): string
|
|
116
|
+
public static function escapeQuotes(mixed $s): string
|
|
119
117
|
{
|
|
120
118
|
return strtr((string) $s, ['"' => '"', "'" => ''']);
|
|
121
119
|
}
|
|
@@ -124,7 +122,7 @@ final class HtmlHelpers
|
|
|
124
122
|
/**
|
|
125
123
|
* Converts JS and CSS for usage in <script> or <style>
|
|
126
124
|
*/
|
|
127
|
-
public static function convertJSToRawText($s): string
|
|
125
|
+
public static function convertJSToRawText(mixed $s): string
|
|
128
126
|
{
|
|
129
127
|
return preg_replace('#</(script|style)#i', '<\/$1', (string) $s);
|
|
130
128
|
}
|
|
@@ -196,7 +194,7 @@ final class HtmlHelpers
|
|
|
196
194
|
return match (true) {
|
|
197
195
|
is_string($value), is_int($value), is_float($value), $value instanceof \Stringable => $namePart . '="' . self::escapeAttr($value) . '"',
|
|
198
196
|
$value === null => '',
|
|
199
|
-
default => self::triggerInvalidValue(trim($namePart), $value)
|
|
197
|
+
default => self::triggerInvalidValue(trim($namePart), $value),
|
|
200
198
|
};
|
|
201
199
|
}
|
|
202
200
|
|
|
@@ -269,7 +267,8 @@ final class HtmlHelpers
|
|
|
269
267
|
}
|
|
270
268
|
|
|
271
269
|
|
|
272
|
-
|
|
270
|
+
/** @param array<mixed> $items */
|
|
271
|
+
private static function formatArrayAttribute(string $namePart, array $items, \Closure $cb, string $separator): string
|
|
273
272
|
{
|
|
274
273
|
$res = [];
|
|
275
274
|
foreach ($items as $k => $v) {
|
|
@@ -281,11 +280,12 @@ final class HtmlHelpers
|
|
|
281
280
|
}
|
|
282
281
|
|
|
283
282
|
|
|
284
|
-
public static function triggerInvalidValue(string $name, mixed $value):
|
|
283
|
+
public static function triggerInvalidValue(string $name, mixed $value): string
|
|
285
284
|
{
|
|
286
285
|
$source = Latte\Helpers::guessTemplatePosition();
|
|
287
286
|
$type = get_debug_type($value);
|
|
288
287
|
trigger_error("Invalid value for attribute '$name': $type is not allowed" . ($source ? " ($source)" : '.'), E_USER_WARNING);
|
|
288
|
+
return '';
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
|
|
@@ -321,7 +321,7 @@ final class HtmlHelpers
|
|
|
321
321
|
public static function isUrlAttribute(string $tag, string $attr): bool
|
|
322
322
|
{
|
|
323
323
|
$attr = strtolower($attr);
|
|
324
|
-
return in_array($attr, ['href', 'src', 'action', 'formaction'], true)
|
|
324
|
+
return in_array($attr, ['href', 'src', 'action', 'formaction'], strict: true)
|
|
325
325
|
|| ($attr === 'data' && strtolower($tag) === 'object');
|
|
326
326
|
}
|
|
327
327
|
|
|
@@ -355,7 +355,7 @@ final class HtmlHelpers
|
|
|
355
355
|
throw new Latte\RuntimeException("Invalid tag name '$name'");
|
|
356
356
|
|
|
357
357
|
} elseif (self::isVoidElement($name) !== self::isVoidElement($origName ?? 'div') // non-void is default
|
|
358
|
-
|| in_array(strtolower($name), ['style', 'script'], true)) {
|
|
358
|
+
|| in_array(strtolower($name), ['style', 'script'], strict: true)) {
|
|
359
359
|
throw new Latte\RuntimeException("Forbidden: Cannot change element to <$name>");
|
|
360
360
|
}
|
|
361
361
|
return $name;
|