@vituum/vite-plugin-latte 2.0.0-next.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.js +4 -2
- package/package.json +11 -9
- package/types/index.d.ts +1 -1
- package/vendor/autoload.php +1 -4
- package/vendor/composer/InstalledVersions.php +36 -2
- package/vendor/composer/autoload_classmap.php +14 -15
- package/vendor/composer/autoload_psr4.php +2 -0
- package/vendor/composer/autoload_static.php +38 -15
- package/vendor/composer/installed.json +32 -22
- package/vendor/composer/installed.php +12 -12
- package/vendor/composer/platform_check.php +4 -5
- package/vendor/latte/latte/bin/latte-lint +10 -3
- package/vendor/latte/latte/composer.json +16 -6
- package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +13 -38
- package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +9 -7
- package/vendor/latte/latte/src/Bridges/Tracy/TracyExtension.php +2 -4
- package/vendor/latte/latte/src/Bridges/Tracy/dist/panel.phtml +94 -0
- package/vendor/latte/latte/src/Bridges/Tracy/dist/tab.phtml +10 -0
- package/vendor/latte/latte/src/Latte/Compiler/Block.php +4 -6
- package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +67 -86
- package/vendor/latte/latte/src/Latte/Compiler/Node.php +6 -3
- package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +16 -6
- package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +25 -12
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +7 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +8 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +7 -15
- 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 +37 -67
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ExpressionAttributeNode.php +60 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/TagNode.php +70 -0
- 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 -15
- 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 +6 -22
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +18 -5
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +18 -7
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AuxiliaryNode.php +5 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +38 -9
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +14 -6
- 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 +12 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +10 -6
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +7 -6
- 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 +10 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +14 -5
- 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 +14 -5
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +6 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +6 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +18 -5
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +14 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +14 -6
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +14 -6
- 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 +14 -15
- 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 +16 -11
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +19 -9
- 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 +33 -8
- 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 +6 -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 +6 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +29 -41
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +9 -4
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/OperatorNode.php +27 -0
- 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 +9 -6
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +8 -6
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/InterpolatedStringNode.php +9 -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 +6 -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 +6 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/{Expression/NotNode.php → VariadicPlaceholderNode.php} +9 -9
- package/vendor/latte/latte/src/Latte/{Essential → Compiler}/Nodes/PrintNode.php +9 -15
- 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 +6 -4
- package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +32 -18
- package/vendor/latte/latte/src/Latte/Compiler/Position.php +7 -7
- package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +72 -104
- package/vendor/latte/latte/src/Latte/Compiler/Tag.php +17 -16
- package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +11 -8
- package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +28 -23
- package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +360 -336
- package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +49 -38
- package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +37 -12
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +35 -21
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +121 -71
- package/vendor/latte/latte/src/Latte/Compiler/Token.php +79 -70
- package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +21 -14
- package/vendor/latte/latte/src/Latte/ContentType.php +4 -3
- package/vendor/latte/latte/src/Latte/Engine.php +147 -188
- package/vendor/latte/latte/src/Latte/Essential/AuxiliaryIterator.php +5 -7
- package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +5 -5
- package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +5 -4
- package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +155 -127
- package/vendor/latte/latte/src/Latte/Essential/Filters.php +99 -44
- package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +14 -13
- 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 +46 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +2 -3
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +10 -7
- 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 +8 -9
- 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 +6 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +7 -7
- 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 +11 -11
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +5 -6
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +26 -27
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +7 -10
- 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 +35 -47
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +4 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NElseNode.php +69 -34
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +9 -33
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +7 -4
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +3 -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 +4 -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 +5 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +4 -5
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +10 -6
- 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 +82 -21
- package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +2 -4
- package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +1 -3
- package/vendor/latte/latte/src/Latte/Essential/Tracer.php +24 -28
- package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +14 -14
- package/vendor/latte/latte/src/Latte/Extension.php +12 -6
- package/vendor/latte/latte/src/Latte/Feature.php +24 -0
- package/vendor/latte/latte/src/Latte/Helpers.php +65 -15
- package/vendor/latte/latte/src/Latte/Loader.php +1 -9
- package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +11 -17
- package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +7 -21
- 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/Runtime/Cache.php +143 -0
- package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +5 -6
- package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +11 -11
- package/vendor/latte/latte/src/Latte/Runtime/FunctionExecutor.php +5 -6
- package/vendor/latte/latte/src/Latte/Runtime/Helpers.php +91 -0
- package/vendor/latte/latte/src/Latte/Runtime/Html.php +3 -5
- package/vendor/latte/latte/src/Latte/Runtime/HtmlHelpers.php +374 -0
- package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +1 -3
- package/vendor/latte/latte/src/Latte/Runtime/Template.php +162 -182
- package/vendor/latte/latte/src/Latte/Runtime/XmlHelpers.php +108 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +12 -4
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +15 -5
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +5 -6
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticMethodCallNode.php +14 -4
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +4 -3
- package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +8 -6
- package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +16 -12
- package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +18 -16
- package/vendor/latte/latte/src/Latte/attributes.php +7 -3
- package/vendor/latte/latte/src/Latte/exceptions.php +52 -6
- package/vendor/latte/latte/src/Tools/Linter.php +74 -28
- package/vendor/latte/latte/src/Tools/LinterExtension.php +176 -0
- package/vendor/nette/utils/composer.json +15 -5
- package/vendor/nette/utils/readme.md +1 -1
- package/vendor/nette/utils/src/HtmlStringable.php +4 -1
- package/vendor/nette/utils/src/Iterators/CachingIterator.php +10 -25
- 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 -11
- package/vendor/nette/utils/src/Translator.php +1 -1
- package/vendor/nette/utils/src/Utils/ArrayHash.php +6 -10
- package/vendor/nette/utils/src/Utils/ArrayList.php +8 -12
- package/vendor/nette/utils/src/Utils/Arrays.php +38 -18
- package/vendor/nette/utils/src/Utils/Callback.php +13 -8
- package/vendor/nette/utils/src/Utils/DateTime.php +95 -26
- package/vendor/nette/utils/src/Utils/FileInfo.php +6 -7
- package/vendor/nette/utils/src/Utils/FileSystem.php +10 -5
- package/vendor/nette/utils/src/Utils/Finder.php +31 -12
- package/vendor/nette/utils/src/Utils/Floats.php +1 -0
- package/vendor/nette/utils/src/Utils/Helpers.php +22 -2
- package/vendor/nette/utils/src/Utils/Html.php +130 -127
- package/vendor/nette/utils/src/Utils/Image.php +80 -60
- package/vendor/nette/utils/src/Utils/ImageColor.php +5 -0
- package/vendor/nette/utils/src/Utils/ImageType.php +2 -0
- package/vendor/nette/utils/src/Utils/Iterables.php +41 -7
- package/vendor/nette/utils/src/Utils/Json.php +2 -0
- package/vendor/nette/utils/src/Utils/ObjectHelpers.php +2 -0
- package/vendor/nette/utils/src/Utils/Paginator.php +10 -43
- package/vendor/nette/utils/src/Utils/Random.php +2 -0
- package/vendor/nette/utils/src/Utils/Reflection.php +22 -15
- package/vendor/nette/utils/src/Utils/ReflectionMethod.php +6 -1
- package/vendor/nette/utils/src/Utils/Strings.php +62 -57
- package/vendor/nette/utils/src/Utils/Type.php +91 -42
- package/vendor/nette/utils/src/Utils/Validators.php +9 -7
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.panel.phtml +0 -101
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.tab.phtml +0 -15
- package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +0 -129
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ErrorSuppressNode.php +0 -36
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallableNode.php +0 -39
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallableNode.php +0 -42
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticMethodCallableNode.php +0 -57
- package/vendor/latte/latte/src/Latte/PositionAwareException.php +0 -47
- package/vendor/latte/latte/src/Latte/Runtime/Filters.php +0 -283
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallableNode.php +0 -29
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallableNode.php +0 -30
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticMethodCallableNode.php +0 -30
|
@@ -10,6 +10,8 @@ declare(strict_types=1);
|
|
|
10
10
|
namespace Nette\Utils;
|
|
11
11
|
|
|
12
12
|
use Nette;
|
|
13
|
+
use function constant, current, defined, end, explode, file_get_contents, implode, ltrim, next, ord, strrchr, strtolower, substr;
|
|
14
|
+
use const T_AS, T_CLASS, T_COMMENT, T_CURLY_OPEN, T_DOC_COMMENT, T_DOLLAR_OPEN_CURLY_BRACES, T_ENUM, T_INTERFACE, T_NAME_FULLY_QUALIFIED, T_NAME_QUALIFIED, T_NAMESPACE, T_NS_SEPARATOR, T_STRING, T_TRAIT, T_USE, T_WHITESPACE, TOKEN_PARSE;
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -26,18 +28,17 @@ final class Reflection
|
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
#[\Deprecated('use Nette\Utils\Validators::isClassKeyword()')]
|
|
30
32
|
public static function isClassKeyword(string $name): bool
|
|
31
33
|
{
|
|
32
34
|
return Validators::isClassKeyword($name);
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
|
|
36
|
-
/** @deprecated use native ReflectionParameter::getDefaultValue() */
|
|
37
38
|
public static function getParameterDefaultValue(\ReflectionParameter $param): mixed
|
|
38
39
|
{
|
|
39
40
|
if ($param->isDefaultValueConstant()) {
|
|
40
|
-
$const = $orig = $param->getDefaultValueConstantName();
|
|
41
|
+
$const = $orig = $param->getDefaultValueConstantName() ?? throw new Nette\ShouldNotHappenException;
|
|
41
42
|
$pair = explode('::', $const);
|
|
42
43
|
if (isset($pair[1])) {
|
|
43
44
|
$pair[0] = Type::resolve($pair[0], $param);
|
|
@@ -67,6 +68,7 @@ final class Reflection
|
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
70
|
* Returns a reflection of a class or trait that contains a declaration of given property. Property can also be declared in the trait.
|
|
71
|
+
* @return \ReflectionClass<object>
|
|
70
72
|
*/
|
|
71
73
|
public static function getPropertyDeclaringClass(\ReflectionProperty $prop): \ReflectionClass
|
|
72
74
|
{
|
|
@@ -136,9 +138,7 @@ final class Reflection
|
|
|
136
138
|
} elseif ($ref instanceof \ReflectionMethod) {
|
|
137
139
|
return $ref->getDeclaringClass()->name . '::' . $ref->name . '()';
|
|
138
140
|
} elseif ($ref instanceof \ReflectionFunction) {
|
|
139
|
-
return
|
|
140
|
-
? '{closure}()'
|
|
141
|
-
: $ref->name . '()';
|
|
141
|
+
return $ref->isAnonymous() ? '{closure}()' : $ref->name . '()';
|
|
142
142
|
} elseif ($ref instanceof \ReflectionProperty) {
|
|
143
143
|
return self::getPropertyDeclaringClass($ref)->name . '::$' . $ref->name;
|
|
144
144
|
} elseif ($ref instanceof \ReflectionParameter) {
|
|
@@ -152,6 +152,7 @@ final class Reflection
|
|
|
152
152
|
/**
|
|
153
153
|
* Expands the name of the class to full name in the given context of given class.
|
|
154
154
|
* Thus, it returns how the PHP parser would understand $name if it were written in the body of the class $context.
|
|
155
|
+
* @param \ReflectionClass<object> $context
|
|
155
156
|
* @throws Nette\InvalidArgumentException
|
|
156
157
|
*/
|
|
157
158
|
public static function expandClassName(string $name, \ReflectionClass $context): string
|
|
@@ -190,7 +191,10 @@ final class Reflection
|
|
|
190
191
|
}
|
|
191
192
|
|
|
192
193
|
|
|
193
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* @param \ReflectionClass<object> $class
|
|
196
|
+
* @return array<string, class-string> of [alias => class]
|
|
197
|
+
*/
|
|
194
198
|
public static function getUseStatements(\ReflectionClass $class): array
|
|
195
199
|
{
|
|
196
200
|
if ($class->isAnonymous()) {
|
|
@@ -202,7 +206,7 @@ final class Reflection
|
|
|
202
206
|
if ($class->isInternal()) {
|
|
203
207
|
$cache[$name] = [];
|
|
204
208
|
} else {
|
|
205
|
-
$code = file_get_contents($class->getFileName());
|
|
209
|
+
$code = (string) file_get_contents((string) $class->getFileName());
|
|
206
210
|
$cache = self::parseUseStatements($code, $name) + $cache;
|
|
207
211
|
}
|
|
208
212
|
}
|
|
@@ -213,6 +217,7 @@ final class Reflection
|
|
|
213
217
|
|
|
214
218
|
/**
|
|
215
219
|
* Parses PHP code to [class => [alias => class, ...]]
|
|
220
|
+
* @return array<string, array<string, string>>
|
|
216
221
|
*/
|
|
217
222
|
private static function parseUseStatements(string $code, ?string $forClass = null): array
|
|
218
223
|
{
|
|
@@ -240,9 +245,7 @@ final class Reflection
|
|
|
240
245
|
case T_CLASS:
|
|
241
246
|
case T_INTERFACE:
|
|
242
247
|
case T_TRAIT:
|
|
243
|
-
case
|
|
244
|
-
? T_CLASS
|
|
245
|
-
: T_ENUM:
|
|
248
|
+
case T_ENUM:
|
|
246
249
|
if ($name = self::fetch($tokens, T_STRING)) {
|
|
247
250
|
$class = $namespace . $name;
|
|
248
251
|
$classLevel = $level + 1;
|
|
@@ -259,8 +262,8 @@ final class Reflection
|
|
|
259
262
|
$name = ltrim($name, '\\');
|
|
260
263
|
if (self::fetch($tokens, '{')) {
|
|
261
264
|
while ($suffix = self::fetch($tokens, $nameTokens)) {
|
|
262
|
-
if (self::fetch($tokens, T_AS)) {
|
|
263
|
-
$uses[
|
|
265
|
+
if (self::fetch($tokens, T_AS) && ($alias = self::fetch($tokens, T_STRING))) {
|
|
266
|
+
$uses[$alias] = $name . $suffix;
|
|
264
267
|
} else {
|
|
265
268
|
$tmp = explode('\\', $suffix);
|
|
266
269
|
$uses[end($tmp)] = $name . $suffix;
|
|
@@ -270,8 +273,8 @@ final class Reflection
|
|
|
270
273
|
break;
|
|
271
274
|
}
|
|
272
275
|
}
|
|
273
|
-
} elseif (self::fetch($tokens, T_AS)) {
|
|
274
|
-
$uses[
|
|
276
|
+
} elseif (self::fetch($tokens, T_AS) && ($alias = self::fetch($tokens, T_STRING))) {
|
|
277
|
+
$uses[$alias] = $name;
|
|
275
278
|
|
|
276
279
|
} else {
|
|
277
280
|
$tmp = explode('\\', $name);
|
|
@@ -304,6 +307,10 @@ final class Reflection
|
|
|
304
307
|
}
|
|
305
308
|
|
|
306
309
|
|
|
310
|
+
/**
|
|
311
|
+
* @param \PhpToken[] $tokens
|
|
312
|
+
* @param string|int|int[] $take
|
|
313
|
+
*/
|
|
307
314
|
private static function fetch(array &$tokens, string|int|array $take): ?string
|
|
308
315
|
{
|
|
309
316
|
$res = null;
|
|
@@ -9,6 +9,8 @@ declare(strict_types=1);
|
|
|
9
9
|
|
|
10
10
|
namespace Nette\Utils;
|
|
11
11
|
|
|
12
|
+
use function explode, is_string, str_contains;
|
|
13
|
+
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* ReflectionMethod preserving the original class name.
|
|
@@ -16,9 +18,11 @@ namespace Nette\Utils;
|
|
|
16
18
|
*/
|
|
17
19
|
final class ReflectionMethod extends \ReflectionMethod
|
|
18
20
|
{
|
|
19
|
-
|
|
21
|
+
/** @var \ReflectionClass<object> */
|
|
22
|
+
private readonly \ReflectionClass $originalClass;
|
|
20
23
|
|
|
21
24
|
|
|
25
|
+
/** @param class-string|object $objectOrMethod */
|
|
22
26
|
public function __construct(object|string $objectOrMethod, ?string $method = null)
|
|
23
27
|
{
|
|
24
28
|
if (is_string($objectOrMethod) && str_contains($objectOrMethod, '::')) {
|
|
@@ -29,6 +33,7 @@ final class ReflectionMethod extends \ReflectionMethod
|
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
|
|
36
|
+
/** @return \ReflectionClass<object> */
|
|
32
37
|
public function getOriginalClass(): \ReflectionClass
|
|
33
38
|
{
|
|
34
39
|
return $this->originalClass;
|
|
@@ -11,7 +11,8 @@ namespace Nette\Utils;
|
|
|
11
11
|
|
|
12
12
|
use JetBrains\PhpStorm\Language;
|
|
13
13
|
use Nette;
|
|
14
|
-
use function is_array, is_object, strlen;
|
|
14
|
+
use function array_keys, array_map, array_shift, array_values, bin2hex, class_exists, defined, extension_loaded, function_exists, htmlspecialchars, htmlspecialchars_decode, iconv, iconv_strlen, iconv_substr, implode, in_array, is_array, is_callable, is_int, is_object, is_string, key, max, mb_convert_case, mb_strlen, mb_strtolower, mb_strtoupper, mb_substr, pack, preg_last_error, preg_last_error_msg, preg_quote, preg_replace, str_contains, str_ends_with, str_repeat, str_replace, str_starts_with, strlen, strpos, strrev, strrpos, strtolower, strtoupper, strtr, substr, trim, unpack, utf8_decode;
|
|
15
|
+
use const ENT_IGNORE, ENT_NOQUOTES, ICONV_IMPL, MB_CASE_TITLE, PHP_EOL, PREG_OFFSET_CAPTURE, PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_SPLIT_DELIM_CAPTURE, PREG_SPLIT_NO_EMPTY, PREG_SPLIT_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL;
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -21,9 +22,9 @@ class Strings
|
|
|
21
22
|
{
|
|
22
23
|
use Nette\StaticClass;
|
|
23
24
|
|
|
24
|
-
public const TrimCharacters = " \t\n\r\0\x0B\u{A0}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{200A}\u{200B}";
|
|
25
|
+
public const TrimCharacters = " \t\n\r\0\x0B\u{A0}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{200A}\u{200B}\u{2028}\u{3000}";
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
#[\Deprecated('use Strings::TrimCharacters')]
|
|
27
28
|
public const TRIM_CHARACTERS = self::TrimCharacters;
|
|
28
29
|
|
|
29
30
|
|
|
@@ -58,7 +59,8 @@ class Strings
|
|
|
58
59
|
throw new Nette\NotSupportedException(__METHOD__ . '() requires ICONV extension that is not loaded.');
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
$res = iconv('UTF-32BE', 'UTF-8//IGNORE', pack('N', $code));
|
|
63
|
+
return $res === false ? throw new Nette\ShouldNotHappenException : $res;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
|
|
@@ -72,11 +74,11 @@ class Strings
|
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
$tmp = iconv('UTF-8', 'UTF-32BE//IGNORE', $c);
|
|
75
|
-
if (
|
|
77
|
+
if ($tmp === false || $tmp === '') {
|
|
76
78
|
throw new Nette\InvalidArgumentException('Invalid UTF-8 character "' . ($c === '' ? '' : '\x' . strtoupper(bin2hex($c))) . '".');
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
return unpack('N', $tmp)[1];
|
|
81
|
+
return unpack('N', $tmp)[1] ?? throw new Nette\ShouldNotHappenException;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
|
|
@@ -123,7 +125,8 @@ class Strings
|
|
|
123
125
|
$start += self::length($s); // unifies iconv_substr behavior with mb_substr
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
|
|
128
|
+
$res = iconv_substr($s, $start, $length, 'UTF-8');
|
|
129
|
+
return $res === false ? throw new Nette\InvalidStateException('iconv_substr() failed.') : $res;
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
|
|
@@ -134,7 +137,7 @@ class Strings
|
|
|
134
137
|
public static function normalize(string $s): string
|
|
135
138
|
{
|
|
136
139
|
// convert to compressed normal form (NFC)
|
|
137
|
-
if (class_exists('Normalizer', false) && ($n = \Normalizer::normalize($s, \Normalizer::FORM_C)) !== false) {
|
|
140
|
+
if (class_exists('Normalizer', autoload: false) && ($n = \Normalizer::normalize($s, \Normalizer::FORM_C)) !== false) {
|
|
138
141
|
$s = $n;
|
|
139
142
|
}
|
|
140
143
|
|
|
@@ -185,17 +188,12 @@ class Strings
|
|
|
185
188
|
*/
|
|
186
189
|
public static function toAscii(string $s): string
|
|
187
190
|
{
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if ($transliterator === null) {
|
|
191
|
-
if (class_exists('Transliterator', false)) {
|
|
192
|
-
$transliterator = \Transliterator::create('Any-Latin; Latin-ASCII');
|
|
193
|
-
} else {
|
|
194
|
-
trigger_error(__METHOD__ . "(): it is recommended to enable PHP extensions 'intl'.", E_USER_NOTICE);
|
|
195
|
-
$transliterator = false;
|
|
196
|
-
}
|
|
191
|
+
if (!extension_loaded('intl')) {
|
|
192
|
+
throw new Nette\NotSupportedException(__METHOD__ . '() requires INTL extension that is not loaded.');
|
|
197
193
|
}
|
|
198
194
|
|
|
195
|
+
$iconv = defined('ICONV_IMPL') ? trim(ICONV_IMPL, '"\'') : null;
|
|
196
|
+
|
|
199
197
|
// remove control characters and check UTF-8 validity
|
|
200
198
|
$s = self::pcre('preg_replace', ['#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $s]);
|
|
201
199
|
|
|
@@ -205,39 +203,24 @@ class Strings
|
|
|
205
203
|
$s = strtr($s, ["\u{AE}" => '(R)', "\u{A9}" => '(c)', "\u{2026}" => '...', "\u{AB}" => '<<', "\u{BB}" => '>>', "\u{A3}" => 'lb', "\u{A5}" => 'yen', "\u{B2}" => '^2', "\u{B3}" => '^3', "\u{B5}" => 'u', "\u{B9}" => '^1', "\u{BA}" => 'o', "\u{BF}" => '?', "\u{2CA}" => "'", "\u{2CD}" => '_', "\u{2DD}" => '"', "\u{1FEF}" => '', "\u{20AC}" => 'EUR', "\u{2122}" => 'TM', "\u{212E}" => 'e', "\u{2190}" => '<-', "\u{2191}" => '^', "\u{2192}" => '->', "\u{2193}" => 'V', "\u{2194}" => '<->']); // ® © … « » £ ¥ ² ³ µ ¹ º ¿ ˊ ˍ ˝ ` € ™ ℮ ← ↑ → ↓ ↔
|
|
206
204
|
}
|
|
207
205
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
} else { // null or 'unknown' (#216)
|
|
218
|
-
$s = self::pcre('preg_replace', ['#[^\x00-\x7F]++#', '', $s]); // remove non-ascii chars
|
|
219
|
-
}
|
|
220
|
-
} elseif ($iconv === 'glibc' || $iconv === 'libiconv') {
|
|
221
|
-
// temporarily hide these characters to distinguish them from the garbage that iconv creates
|
|
222
|
-
$s = strtr($s, '`\'"^~?', "\x01\x02\x03\x04\x05\x06");
|
|
223
|
-
if ($iconv === 'glibc') {
|
|
224
|
-
// glibc implementation is very limited. transliterate into Windows-1250 and then into ASCII, so most Eastern European characters are preserved
|
|
225
|
-
$s = iconv('UTF-8', 'WINDOWS-1250//TRANSLIT//IGNORE', $s);
|
|
226
|
-
$s = strtr(
|
|
227
|
-
$s,
|
|
228
|
-
"\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x96\xa0\x8b\x97\x9b\xa6\xad\xb7",
|
|
229
|
-
'ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt- <->|-.',
|
|
230
|
-
);
|
|
231
|
-
$s = self::pcre('preg_replace', ['#[^\x00-\x7F]++#', '', $s]);
|
|
232
|
-
} else {
|
|
233
|
-
$s = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
|
|
206
|
+
$s = \Transliterator::create('Any-Latin; Latin-ASCII')?->transliterate($s)
|
|
207
|
+
?? throw new Nette\InvalidStateException('Transliterator::transliterate() failed.');
|
|
208
|
+
|
|
209
|
+
// use iconv because The transliterator leaves some characters out of ASCII, eg → ʾ
|
|
210
|
+
if ($iconv === 'glibc') {
|
|
211
|
+
$s = strtr($s, '?', "\x01"); // temporarily hide ? to distinguish them from the garbage that iconv creates
|
|
212
|
+
$s = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
|
|
213
|
+
if ($s === false) {
|
|
214
|
+
throw new Nette\InvalidStateException('iconv() failed.');
|
|
234
215
|
}
|
|
235
216
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
217
|
+
$s = str_replace(['?', "\x01"], ['', '?'], $s); // remove garbage and restore ? characters
|
|
218
|
+
} elseif ($iconv === 'libiconv') {
|
|
219
|
+
$s = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
|
|
220
|
+
if ($s === false) {
|
|
221
|
+
throw new Nette\InvalidStateException('iconv() failed.');
|
|
222
|
+
}
|
|
223
|
+
} else { // null or 'unknown' (#216)
|
|
241
224
|
$s = self::pcre('preg_replace', ['#[^\x00-\x7F]++#', '', $s]); // remove non-ascii chars
|
|
242
225
|
}
|
|
243
226
|
|
|
@@ -351,7 +334,7 @@ class Strings
|
|
|
351
334
|
*/
|
|
352
335
|
public static function compare(string $left, string $right, ?int $length = null): bool
|
|
353
336
|
{
|
|
354
|
-
if (class_exists('Normalizer', false)) {
|
|
337
|
+
if (class_exists('Normalizer', autoload: false)) {
|
|
355
338
|
$left = \Normalizer::normalize($left, \Normalizer::FORM_D); // form NFD is faster
|
|
356
339
|
$right = \Normalizer::normalize($right, \Normalizer::FORM_D); // form NFD is faster
|
|
357
340
|
}
|
|
@@ -375,6 +358,10 @@ class Strings
|
|
|
375
358
|
public static function findPrefix(array $strings): string
|
|
376
359
|
{
|
|
377
360
|
$first = array_shift($strings);
|
|
361
|
+
if ($first === null) {
|
|
362
|
+
return '';
|
|
363
|
+
}
|
|
364
|
+
|
|
378
365
|
for ($i = 0; $i < strlen($first); $i++) {
|
|
379
366
|
foreach ($strings as $s) {
|
|
380
367
|
if (!isset($s[$i]) || $first[$i] !== $s[$i]) {
|
|
@@ -398,8 +385,8 @@ class Strings
|
|
|
398
385
|
public static function length(string $s): int
|
|
399
386
|
{
|
|
400
387
|
return match (true) {
|
|
401
|
-
extension_loaded('mbstring') => mb_strlen($s, 'UTF-8'),
|
|
402
|
-
extension_loaded('iconv') => iconv_strlen($s, 'UTF-8'),
|
|
388
|
+
extension_loaded('mbstring') => (int) mb_strlen($s, 'UTF-8'),
|
|
389
|
+
extension_loaded('iconv') => (int) iconv_strlen($s, 'UTF-8'),
|
|
403
390
|
default => strlen(@utf8_decode($s)), // deprecated
|
|
404
391
|
};
|
|
405
392
|
}
|
|
@@ -448,7 +435,10 @@ class Strings
|
|
|
448
435
|
throw new Nette\NotSupportedException(__METHOD__ . '() requires ICONV extension that is not loaded.');
|
|
449
436
|
}
|
|
450
437
|
|
|
451
|
-
|
|
438
|
+
$tmp = iconv('UTF-8', 'UTF-32BE', $s);
|
|
439
|
+
return $tmp === false
|
|
440
|
+
? throw new Nette\InvalidStateException('iconv() failed.')
|
|
441
|
+
: (string) iconv('UTF-32LE', 'UTF-8', strrev($tmp));
|
|
452
442
|
}
|
|
453
443
|
|
|
454
444
|
|
|
@@ -527,6 +517,7 @@ class Strings
|
|
|
527
517
|
|
|
528
518
|
/**
|
|
529
519
|
* Divides the string into arrays according to the regular expression. Expressions in parentheses will be captured and returned as well.
|
|
520
|
+
* @return list<string>
|
|
530
521
|
*/
|
|
531
522
|
public static function split(
|
|
532
523
|
string $subject,
|
|
@@ -553,6 +544,7 @@ class Strings
|
|
|
553
544
|
/**
|
|
554
545
|
* Searches the string for the part matching the regular expression and returns
|
|
555
546
|
* an array with the found expression and individual subexpressions, or `null`.
|
|
547
|
+
* @return ?array<string>
|
|
556
548
|
*/
|
|
557
549
|
public static function match(
|
|
558
550
|
string $subject,
|
|
@@ -573,6 +565,7 @@ class Strings
|
|
|
573
565
|
$pattern .= 'u';
|
|
574
566
|
}
|
|
575
567
|
|
|
568
|
+
$m = [];
|
|
576
569
|
if ($offset > strlen($subject)) {
|
|
577
570
|
return null;
|
|
578
571
|
} elseif (!self::pcre('preg_match', [$pattern, $subject, &$m, $flags, $offset])) {
|
|
@@ -588,7 +581,7 @@ class Strings
|
|
|
588
581
|
/**
|
|
589
582
|
* Searches the string for all occurrences matching the regular expression and
|
|
590
583
|
* returns an array of arrays containing the found expression and each subexpression.
|
|
591
|
-
* @return ($lazy is true ? \Generator<int, array
|
|
584
|
+
* @return ($lazy is true ? \Generator<int, array<string>> : list<array<string>>)
|
|
592
585
|
*/
|
|
593
586
|
public static function matchAll(
|
|
594
587
|
string $subject,
|
|
@@ -611,10 +604,12 @@ class Strings
|
|
|
611
604
|
$flags = PREG_OFFSET_CAPTURE | ($unmatchedAsNull ? PREG_UNMATCHED_AS_NULL : 0);
|
|
612
605
|
return (function () use ($utf8, $captureOffset, $flags, $subject, $pattern, $offset) {
|
|
613
606
|
$counter = 0;
|
|
607
|
+
$m = [];
|
|
614
608
|
while (
|
|
615
609
|
$offset <= strlen($subject) - ($counter ? 1 : 0)
|
|
616
610
|
&& self::pcre('preg_match', [$pattern, $subject, &$m, $flags, $offset])
|
|
617
611
|
) {
|
|
612
|
+
/** @var list<array{string, int}> $m */
|
|
618
613
|
$offset = $m[0][1] + max(1, strlen($m[0][0]));
|
|
619
614
|
if (!$captureOffset) {
|
|
620
615
|
$m = array_map(fn($item) => $item[0], $m);
|
|
@@ -634,6 +629,7 @@ class Strings
|
|
|
634
629
|
? $captureOffset
|
|
635
630
|
: ($captureOffset ? PREG_OFFSET_CAPTURE : 0) | ($unmatchedAsNull ? PREG_UNMATCHED_AS_NULL : 0) | ($patternOrder ? PREG_PATTERN_ORDER : 0);
|
|
636
631
|
|
|
632
|
+
$m = [];
|
|
637
633
|
self::pcre('preg_match_all', [
|
|
638
634
|
$pattern, $subject, &$m,
|
|
639
635
|
($flags & PREG_PATTERN_ORDER) ? $flags : ($flags | PREG_SET_ORDER),
|
|
@@ -647,6 +643,7 @@ class Strings
|
|
|
647
643
|
|
|
648
644
|
/**
|
|
649
645
|
* Replaces all occurrences matching regular expression $pattern which can be string or array in the form `pattern => replacement`.
|
|
646
|
+
* @param string|array<string, string> $pattern
|
|
650
647
|
*/
|
|
651
648
|
public static function replace(
|
|
652
649
|
string $subject,
|
|
@@ -666,7 +663,7 @@ class Strings
|
|
|
666
663
|
|
|
667
664
|
$flags = ($captureOffset ? PREG_OFFSET_CAPTURE : 0) | ($unmatchedAsNull ? PREG_UNMATCHED_AS_NULL : 0);
|
|
668
665
|
if ($utf8) {
|
|
669
|
-
$pattern
|
|
666
|
+
$pattern = is_array($pattern) ? array_map(fn($item) => $item . 'u', $pattern) : $pattern . 'u';
|
|
670
667
|
if ($captureOffset) {
|
|
671
668
|
$replacement = fn($m) => $replacement(self::bytesToChars($subject, [$m])[0]);
|
|
672
669
|
}
|
|
@@ -687,6 +684,10 @@ class Strings
|
|
|
687
684
|
}
|
|
688
685
|
|
|
689
686
|
|
|
687
|
+
/**
|
|
688
|
+
* @param list<array<array{string, int}>> $groups
|
|
689
|
+
* @return list<array<array{string, int}>>
|
|
690
|
+
*/
|
|
690
691
|
private static function bytesToChars(string $s, array $groups): array
|
|
691
692
|
{
|
|
692
693
|
$lastBytes = $lastChars = 0;
|
|
@@ -707,8 +708,12 @@ class Strings
|
|
|
707
708
|
}
|
|
708
709
|
|
|
709
710
|
|
|
710
|
-
/**
|
|
711
|
-
|
|
711
|
+
/**
|
|
712
|
+
* @param callable-string $func
|
|
713
|
+
* @param list<mixed> $args
|
|
714
|
+
* @internal
|
|
715
|
+
*/
|
|
716
|
+
public static function pcre(string $func, array $args): mixed
|
|
712
717
|
{
|
|
713
718
|
$res = Callback::invokeSafe($func, $args, function (string $message) use ($args): void {
|
|
714
719
|
// compile-time error, not detectable by preg_last_error
|
|
@@ -716,7 +721,7 @@ class Strings
|
|
|
716
721
|
});
|
|
717
722
|
|
|
718
723
|
if (($code = preg_last_error()) // run-time error, but preg_last_error & return code are liars
|
|
719
|
-
&& ($res === null || !in_array($func, ['preg_filter', 'preg_replace_callback', 'preg_replace'], true))
|
|
724
|
+
&& ($res === null || !in_array($func, ['preg_filter', 'preg_replace_callback', 'preg_replace'], strict: true))
|
|
720
725
|
) {
|
|
721
726
|
throw new RegexpException(preg_last_error_msg()
|
|
722
727
|
. ' (pattern: ' . implode(' or ', (array) $args[0]) . ')', $code);
|