@vituum/vite-plugin-latte 1.1.0 → 1.2.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.
Files changed (71) hide show
  1. package/latte/PlaceholderFunction.php +2 -2
  2. package/package.json +1 -1
  3. package/vendor/autoload.php +1 -1
  4. package/vendor/composer/autoload_classmap.php +51 -0
  5. package/vendor/composer/autoload_real.php +4 -4
  6. package/vendor/composer/autoload_static.php +53 -2
  7. package/vendor/composer/installed.json +96 -7
  8. package/vendor/composer/installed.php +14 -5
  9. package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +11 -2
  10. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +1 -1
  11. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +2 -2
  12. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +11 -21
  13. package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +1 -1
  14. package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +2 -2
  15. package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +275 -280
  16. package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +4 -4
  17. package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +10 -2
  18. package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +6 -2
  19. package/vendor/latte/latte/src/Latte/Engine.php +109 -97
  20. package/vendor/latte/latte/src/Latte/Essential/AuxiliaryIterator.php +46 -0
  21. package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +42 -25
  22. package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +76 -72
  23. package/vendor/latte/latte/src/Latte/Essential/Filters.php +95 -37
  24. package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +7 -0
  25. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +36 -0
  26. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +25 -3
  27. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +9 -2
  28. package/vendor/latte/latte/src/Latte/Essential/Passes.php +10 -50
  29. package/vendor/latte/latte/src/Latte/Helpers.php +3 -1
  30. package/vendor/latte/latte/src/Latte/Loader.php +1 -0
  31. package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +1 -2
  32. package/vendor/latte/latte/src/Latte/Runtime/Filters.php +1 -4
  33. package/vendor/latte/latte/src/Latte/Runtime/FunctionExecutor.php +68 -0
  34. package/vendor/latte/latte/src/Latte/Runtime/Template.php +1 -3
  35. package/vendor/nette/utils/.phpstorm.meta.php +13 -0
  36. package/vendor/nette/utils/composer.json +51 -0
  37. package/vendor/nette/utils/license.md +60 -0
  38. package/vendor/nette/utils/readme.md +56 -0
  39. package/vendor/nette/utils/src/HtmlStringable.php +22 -0
  40. package/vendor/nette/utils/src/Iterators/CachingIterator.php +164 -0
  41. package/vendor/nette/utils/src/Iterators/Mapper.php +34 -0
  42. package/vendor/nette/utils/src/SmartObject.php +140 -0
  43. package/vendor/nette/utils/src/StaticClass.php +34 -0
  44. package/vendor/nette/utils/src/Translator.php +25 -0
  45. package/vendor/nette/utils/src/Utils/ArrayHash.php +106 -0
  46. package/vendor/nette/utils/src/Utils/ArrayList.php +136 -0
  47. package/vendor/nette/utils/src/Utils/Arrays.php +522 -0
  48. package/vendor/nette/utils/src/Utils/Callback.php +137 -0
  49. package/vendor/nette/utils/src/Utils/DateTime.php +140 -0
  50. package/vendor/nette/utils/src/Utils/FileInfo.php +69 -0
  51. package/vendor/nette/utils/src/Utils/FileSystem.php +326 -0
  52. package/vendor/nette/utils/src/Utils/Finder.php +510 -0
  53. package/vendor/nette/utils/src/Utils/Floats.php +107 -0
  54. package/vendor/nette/utils/src/Utils/Helpers.php +104 -0
  55. package/vendor/nette/utils/src/Utils/Html.php +839 -0
  56. package/vendor/nette/utils/src/Utils/Image.php +829 -0
  57. package/vendor/nette/utils/src/Utils/ImageColor.php +75 -0
  58. package/vendor/nette/utils/src/Utils/ImageType.php +25 -0
  59. package/vendor/nette/utils/src/Utils/Iterables.php +159 -0
  60. package/vendor/nette/utils/src/Utils/Json.php +84 -0
  61. package/vendor/nette/utils/src/Utils/ObjectHelpers.php +229 -0
  62. package/vendor/nette/utils/src/Utils/Paginator.php +245 -0
  63. package/vendor/nette/utils/src/Utils/Random.php +52 -0
  64. package/vendor/nette/utils/src/Utils/Reflection.php +320 -0
  65. package/vendor/nette/utils/src/Utils/ReflectionMethod.php +36 -0
  66. package/vendor/nette/utils/src/Utils/Strings.php +708 -0
  67. package/vendor/nette/utils/src/Utils/Type.php +267 -0
  68. package/vendor/nette/utils/src/Utils/Validators.php +416 -0
  69. package/vendor/nette/utils/src/Utils/exceptions.php +50 -0
  70. package/vendor/nette/utils/src/compatibility.php +32 -0
  71. package/vendor/nette/utils/src/exceptions.php +109 -0
@@ -0,0 +1,245 @@
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 Nette\Utils;
11
+
12
+ use Nette;
13
+
14
+
15
+ /**
16
+ * Paginating math.
17
+ *
18
+ * @property int $page
19
+ * @property-read int $firstPage
20
+ * @property-read int|null $lastPage
21
+ * @property-read int<0,max> $firstItemOnPage
22
+ * @property-read int<0,max> $lastItemOnPage
23
+ * @property int $base
24
+ * @property-read bool $first
25
+ * @property-read bool $last
26
+ * @property-read int<0,max>|null $pageCount
27
+ * @property positive-int $itemsPerPage
28
+ * @property int<0,max>|null $itemCount
29
+ * @property-read int<0,max> $offset
30
+ * @property-read int<0,max>|null $countdownOffset
31
+ * @property-read int<0,max> $length
32
+ */
33
+ class Paginator
34
+ {
35
+ use Nette\SmartObject;
36
+
37
+ private int $base = 1;
38
+
39
+ /** @var positive-int */
40
+ private int $itemsPerPage = 1;
41
+
42
+ private int $page = 1;
43
+
44
+ /** @var int<0, max>|null */
45
+ private ?int $itemCount = null;
46
+
47
+
48
+ /**
49
+ * Sets current page number.
50
+ */
51
+ public function setPage(int $page): static
52
+ {
53
+ $this->page = $page;
54
+ return $this;
55
+ }
56
+
57
+
58
+ /**
59
+ * Returns current page number.
60
+ */
61
+ public function getPage(): int
62
+ {
63
+ return $this->base + $this->getPageIndex();
64
+ }
65
+
66
+
67
+ /**
68
+ * Returns first page number.
69
+ */
70
+ public function getFirstPage(): int
71
+ {
72
+ return $this->base;
73
+ }
74
+
75
+
76
+ /**
77
+ * Returns last page number.
78
+ */
79
+ public function getLastPage(): ?int
80
+ {
81
+ return $this->itemCount === null
82
+ ? null
83
+ : $this->base + max(0, $this->getPageCount() - 1);
84
+ }
85
+
86
+
87
+ /**
88
+ * Returns the sequence number of the first element on the page
89
+ * @return int<0, max>
90
+ */
91
+ public function getFirstItemOnPage(): int
92
+ {
93
+ return $this->itemCount !== 0
94
+ ? $this->offset + 1
95
+ : 0;
96
+ }
97
+
98
+
99
+ /**
100
+ * Returns the sequence number of the last element on the page
101
+ * @return int<0, max>
102
+ */
103
+ public function getLastItemOnPage(): int
104
+ {
105
+ return $this->offset + $this->length;
106
+ }
107
+
108
+
109
+ /**
110
+ * Sets first page (base) number.
111
+ */
112
+ public function setBase(int $base): static
113
+ {
114
+ $this->base = $base;
115
+ return $this;
116
+ }
117
+
118
+
119
+ /**
120
+ * Returns first page (base) number.
121
+ */
122
+ public function getBase(): int
123
+ {
124
+ return $this->base;
125
+ }
126
+
127
+
128
+ /**
129
+ * Returns zero-based page number.
130
+ * @return int<0, max>
131
+ */
132
+ protected function getPageIndex(): int
133
+ {
134
+ $index = max(0, $this->page - $this->base);
135
+ return $this->itemCount === null
136
+ ? $index
137
+ : min($index, max(0, $this->getPageCount() - 1));
138
+ }
139
+
140
+
141
+ /**
142
+ * Is the current page the first one?
143
+ */
144
+ public function isFirst(): bool
145
+ {
146
+ return $this->getPageIndex() === 0;
147
+ }
148
+
149
+
150
+ /**
151
+ * Is the current page the last one?
152
+ */
153
+ public function isLast(): bool
154
+ {
155
+ return $this->itemCount === null
156
+ ? false
157
+ : $this->getPageIndex() >= $this->getPageCount() - 1;
158
+ }
159
+
160
+
161
+ /**
162
+ * Returns the total number of pages.
163
+ * @return int<0, max>|null
164
+ */
165
+ public function getPageCount(): ?int
166
+ {
167
+ return $this->itemCount === null
168
+ ? null
169
+ : (int) ceil($this->itemCount / $this->itemsPerPage);
170
+ }
171
+
172
+
173
+ /**
174
+ * Sets the number of items to display on a single page.
175
+ */
176
+ public function setItemsPerPage(int $itemsPerPage): static
177
+ {
178
+ $this->itemsPerPage = max(1, $itemsPerPage);
179
+ return $this;
180
+ }
181
+
182
+
183
+ /**
184
+ * Returns the number of items to display on a single page.
185
+ * @return positive-int
186
+ */
187
+ public function getItemsPerPage(): int
188
+ {
189
+ return $this->itemsPerPage;
190
+ }
191
+
192
+
193
+ /**
194
+ * Sets the total number of items.
195
+ */
196
+ public function setItemCount(?int $itemCount = null): static
197
+ {
198
+ $this->itemCount = $itemCount === null ? null : max(0, $itemCount);
199
+ return $this;
200
+ }
201
+
202
+
203
+ /**
204
+ * Returns the total number of items.
205
+ * @return int<0, max>|null
206
+ */
207
+ public function getItemCount(): ?int
208
+ {
209
+ return $this->itemCount;
210
+ }
211
+
212
+
213
+ /**
214
+ * Returns the absolute index of the first item on current page.
215
+ * @return int<0, max>
216
+ */
217
+ public function getOffset(): int
218
+ {
219
+ return $this->getPageIndex() * $this->itemsPerPage;
220
+ }
221
+
222
+
223
+ /**
224
+ * Returns the absolute index of the first item on current page in countdown paging.
225
+ * @return int<0, max>|null
226
+ */
227
+ public function getCountdownOffset(): ?int
228
+ {
229
+ return $this->itemCount === null
230
+ ? null
231
+ : max(0, $this->itemCount - ($this->getPageIndex() + 1) * $this->itemsPerPage);
232
+ }
233
+
234
+
235
+ /**
236
+ * Returns the number of items on current page.
237
+ * @return int<0, max>
238
+ */
239
+ public function getLength(): int
240
+ {
241
+ return $this->itemCount === null
242
+ ? $this->itemsPerPage
243
+ : min($this->itemsPerPage, $this->itemCount - $this->getPageIndex() * $this->itemsPerPage);
244
+ }
245
+ }
@@ -0,0 +1,52 @@
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 Nette\Utils;
11
+
12
+ use Nette;
13
+ use Random\Randomizer;
14
+
15
+
16
+ /**
17
+ * Secure random string generator.
18
+ */
19
+ final class Random
20
+ {
21
+ use Nette\StaticClass;
22
+
23
+ /**
24
+ * Generates a random string of given length from characters specified in second argument.
25
+ * Supports intervals, such as `0-9` or `A-Z`.
26
+ */
27
+ public static function generate(int $length = 10, string $charlist = '0-9a-z'): string
28
+ {
29
+ $charlist = preg_replace_callback(
30
+ '#.-.#',
31
+ fn(array $m): string => implode('', range($m[0][0], $m[0][2])),
32
+ $charlist,
33
+ );
34
+ $charlist = count_chars($charlist, mode: 3);
35
+ $chLen = strlen($charlist);
36
+
37
+ if ($length < 1) {
38
+ throw new Nette\InvalidArgumentException('Length must be greater than zero.');
39
+ } elseif ($chLen < 2) {
40
+ throw new Nette\InvalidArgumentException('Character list must contain at least two chars.');
41
+ } elseif (PHP_VERSION_ID >= 80300) {
42
+ return (new Randomizer)->getBytesFromString($charlist, $length);
43
+ }
44
+
45
+ $res = '';
46
+ for ($i = 0; $i < $length; $i++) {
47
+ $res .= $charlist[random_int(0, $chLen - 1)];
48
+ }
49
+
50
+ return $res;
51
+ }
52
+ }
@@ -0,0 +1,320 @@
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 Nette\Utils;
11
+
12
+ use Nette;
13
+
14
+
15
+ /**
16
+ * PHP reflection helpers.
17
+ */
18
+ final class Reflection
19
+ {
20
+ use Nette\StaticClass;
21
+
22
+ /** @deprecated use Nette\Utils\Validator::isBuiltinType() */
23
+ public static function isBuiltinType(string $type): bool
24
+ {
25
+ return Validators::isBuiltinType($type);
26
+ }
27
+
28
+
29
+ /** @deprecated use Nette\Utils\Validator::isClassKeyword() */
30
+ public static function isClassKeyword(string $name): bool
31
+ {
32
+ return Validators::isClassKeyword($name);
33
+ }
34
+
35
+
36
+ /** @deprecated use native ReflectionParameter::getDefaultValue() */
37
+ public static function getParameterDefaultValue(\ReflectionParameter $param): mixed
38
+ {
39
+ if ($param->isDefaultValueConstant()) {
40
+ $const = $orig = $param->getDefaultValueConstantName();
41
+ $pair = explode('::', $const);
42
+ if (isset($pair[1])) {
43
+ $pair[0] = Type::resolve($pair[0], $param);
44
+ try {
45
+ $rcc = new \ReflectionClassConstant($pair[0], $pair[1]);
46
+ } catch (\ReflectionException $e) {
47
+ $name = self::toString($param);
48
+ throw new \ReflectionException("Unable to resolve constant $orig used as default value of $name.", 0, $e);
49
+ }
50
+
51
+ return $rcc->getValue();
52
+
53
+ } elseif (!defined($const)) {
54
+ $const = substr((string) strrchr($const, '\\'), 1);
55
+ if (!defined($const)) {
56
+ $name = self::toString($param);
57
+ throw new \ReflectionException("Unable to resolve constant $orig used as default value of $name.");
58
+ }
59
+ }
60
+
61
+ return constant($const);
62
+ }
63
+
64
+ return $param->getDefaultValue();
65
+ }
66
+
67
+
68
+ /**
69
+ * Returns a reflection of a class or trait that contains a declaration of given property. Property can also be declared in the trait.
70
+ */
71
+ public static function getPropertyDeclaringClass(\ReflectionProperty $prop): \ReflectionClass
72
+ {
73
+ foreach ($prop->getDeclaringClass()->getTraits() as $trait) {
74
+ if ($trait->hasProperty($prop->name)
75
+ // doc-comment guessing as workaround for insufficient PHP reflection
76
+ && $trait->getProperty($prop->name)->getDocComment() === $prop->getDocComment()
77
+ ) {
78
+ return self::getPropertyDeclaringClass($trait->getProperty($prop->name));
79
+ }
80
+ }
81
+
82
+ return $prop->getDeclaringClass();
83
+ }
84
+
85
+
86
+ /**
87
+ * Returns a reflection of a method that contains a declaration of $method.
88
+ * Usually, each method is its own declaration, but the body of the method can also be in the trait and under a different name.
89
+ */
90
+ public static function getMethodDeclaringMethod(\ReflectionMethod $method): \ReflectionMethod
91
+ {
92
+ // file & line guessing as workaround for insufficient PHP reflection
93
+ $decl = $method->getDeclaringClass();
94
+ if ($decl->getFileName() === $method->getFileName()
95
+ && $decl->getStartLine() <= $method->getStartLine()
96
+ && $decl->getEndLine() >= $method->getEndLine()
97
+ ) {
98
+ return $method;
99
+ }
100
+
101
+ $hash = [$method->getFileName(), $method->getStartLine(), $method->getEndLine()];
102
+ if (($alias = $decl->getTraitAliases()[$method->name] ?? null)
103
+ && ($m = new \ReflectionMethod($alias))
104
+ && $hash === [$m->getFileName(), $m->getStartLine(), $m->getEndLine()]
105
+ ) {
106
+ return self::getMethodDeclaringMethod($m);
107
+ }
108
+
109
+ foreach ($decl->getTraits() as $trait) {
110
+ if ($trait->hasMethod($method->name)
111
+ && ($m = $trait->getMethod($method->name))
112
+ && $hash === [$m->getFileName(), $m->getStartLine(), $m->getEndLine()]
113
+ ) {
114
+ return self::getMethodDeclaringMethod($m);
115
+ }
116
+ }
117
+
118
+ return $method;
119
+ }
120
+
121
+
122
+ /**
123
+ * Finds out if reflection has access to PHPdoc comments. Comments may not be available due to the opcode cache.
124
+ */
125
+ public static function areCommentsAvailable(): bool
126
+ {
127
+ static $res;
128
+ return $res ?? $res = (bool) (new \ReflectionMethod(__METHOD__))->getDocComment();
129
+ }
130
+
131
+
132
+ public static function toString(\Reflector $ref): string
133
+ {
134
+ if ($ref instanceof \ReflectionClass) {
135
+ return $ref->name;
136
+ } elseif ($ref instanceof \ReflectionMethod) {
137
+ return $ref->getDeclaringClass()->name . '::' . $ref->name . '()';
138
+ } elseif ($ref instanceof \ReflectionFunction) {
139
+ return $ref->name . '()';
140
+ } elseif ($ref instanceof \ReflectionProperty) {
141
+ return self::getPropertyDeclaringClass($ref)->name . '::$' . $ref->name;
142
+ } elseif ($ref instanceof \ReflectionParameter) {
143
+ return '$' . $ref->name . ' in ' . self::toString($ref->getDeclaringFunction());
144
+ } else {
145
+ throw new Nette\InvalidArgumentException;
146
+ }
147
+ }
148
+
149
+
150
+ /**
151
+ * Expands the name of the class to full name in the given context of given class.
152
+ * Thus, it returns how the PHP parser would understand $name if it were written in the body of the class $context.
153
+ * @throws Nette\InvalidArgumentException
154
+ */
155
+ public static function expandClassName(string $name, \ReflectionClass $context): string
156
+ {
157
+ $lower = strtolower($name);
158
+ if (empty($name)) {
159
+ throw new Nette\InvalidArgumentException('Class name must not be empty.');
160
+
161
+ } elseif (Validators::isBuiltinType($lower)) {
162
+ return $lower;
163
+
164
+ } elseif ($lower === 'self' || $lower === 'static') {
165
+ return $context->name;
166
+
167
+ } elseif ($lower === 'parent') {
168
+ return $context->getParentClass()
169
+ ? $context->getParentClass()->name
170
+ : 'parent';
171
+
172
+ } elseif ($name[0] === '\\') { // fully qualified name
173
+ return ltrim($name, '\\');
174
+ }
175
+
176
+ $uses = self::getUseStatements($context);
177
+ $parts = explode('\\', $name, 2);
178
+ if (isset($uses[$parts[0]])) {
179
+ $parts[0] = $uses[$parts[0]];
180
+ return implode('\\', $parts);
181
+
182
+ } elseif ($context->inNamespace()) {
183
+ return $context->getNamespaceName() . '\\' . $name;
184
+
185
+ } else {
186
+ return $name;
187
+ }
188
+ }
189
+
190
+
191
+ /** @return array<string, class-string> of [alias => class] */
192
+ public static function getUseStatements(\ReflectionClass $class): array
193
+ {
194
+ if ($class->isAnonymous()) {
195
+ throw new Nette\NotImplementedException('Anonymous classes are not supported.');
196
+ }
197
+
198
+ static $cache = [];
199
+ if (!isset($cache[$name = $class->name])) {
200
+ if ($class->isInternal()) {
201
+ $cache[$name] = [];
202
+ } else {
203
+ $code = file_get_contents($class->getFileName());
204
+ $cache = self::parseUseStatements($code, $name) + $cache;
205
+ }
206
+ }
207
+
208
+ return $cache[$name];
209
+ }
210
+
211
+
212
+ /**
213
+ * Parses PHP code to [class => [alias => class, ...]]
214
+ */
215
+ private static function parseUseStatements(string $code, ?string $forClass = null): array
216
+ {
217
+ try {
218
+ $tokens = \PhpToken::tokenize($code, TOKEN_PARSE);
219
+ } catch (\ParseError $e) {
220
+ trigger_error($e->getMessage(), E_USER_NOTICE);
221
+ $tokens = [];
222
+ }
223
+
224
+ $namespace = $class = null;
225
+ $classLevel = $level = 0;
226
+ $res = $uses = [];
227
+
228
+ $nameTokens = [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED];
229
+
230
+ while ($token = current($tokens)) {
231
+ next($tokens);
232
+ switch ($token->id) {
233
+ case T_NAMESPACE:
234
+ $namespace = ltrim(self::fetch($tokens, $nameTokens) . '\\', '\\');
235
+ $uses = [];
236
+ break;
237
+
238
+ case T_CLASS:
239
+ case T_INTERFACE:
240
+ case T_TRAIT:
241
+ case PHP_VERSION_ID < 80100
242
+ ? T_CLASS
243
+ : T_ENUM:
244
+ if ($name = self::fetch($tokens, T_STRING)) {
245
+ $class = $namespace . $name;
246
+ $classLevel = $level + 1;
247
+ $res[$class] = $uses;
248
+ if ($class === $forClass) {
249
+ return $res;
250
+ }
251
+ }
252
+
253
+ break;
254
+
255
+ case T_USE:
256
+ while (!$class && ($name = self::fetch($tokens, $nameTokens))) {
257
+ $name = ltrim($name, '\\');
258
+ if (self::fetch($tokens, '{')) {
259
+ while ($suffix = self::fetch($tokens, $nameTokens)) {
260
+ if (self::fetch($tokens, T_AS)) {
261
+ $uses[self::fetch($tokens, T_STRING)] = $name . $suffix;
262
+ } else {
263
+ $tmp = explode('\\', $suffix);
264
+ $uses[end($tmp)] = $name . $suffix;
265
+ }
266
+
267
+ if (!self::fetch($tokens, ',')) {
268
+ break;
269
+ }
270
+ }
271
+ } elseif (self::fetch($tokens, T_AS)) {
272
+ $uses[self::fetch($tokens, T_STRING)] = $name;
273
+
274
+ } else {
275
+ $tmp = explode('\\', $name);
276
+ $uses[end($tmp)] = $name;
277
+ }
278
+
279
+ if (!self::fetch($tokens, ',')) {
280
+ break;
281
+ }
282
+ }
283
+
284
+ break;
285
+
286
+ case T_CURLY_OPEN:
287
+ case T_DOLLAR_OPEN_CURLY_BRACES:
288
+ case ord('{'):
289
+ $level++;
290
+ break;
291
+
292
+ case ord('}'):
293
+ if ($level === $classLevel) {
294
+ $class = $classLevel = 0;
295
+ }
296
+
297
+ $level--;
298
+ }
299
+ }
300
+
301
+ return $res;
302
+ }
303
+
304
+
305
+ private static function fetch(array &$tokens, string|int|array $take): ?string
306
+ {
307
+ $res = null;
308
+ while ($token = current($tokens)) {
309
+ if ($token->is($take)) {
310
+ $res .= $token->text;
311
+ } elseif (!$token->is([T_DOC_COMMENT, T_WHITESPACE, T_COMMENT])) {
312
+ break;
313
+ }
314
+
315
+ next($tokens);
316
+ }
317
+
318
+ return $res;
319
+ }
320
+ }
@@ -0,0 +1,36 @@
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 Nette\Utils;
11
+
12
+
13
+ /**
14
+ * ReflectionMethod preserving the original class name.
15
+ * @internal
16
+ */
17
+ final class ReflectionMethod extends \ReflectionMethod
18
+ {
19
+ private \ReflectionClass $originalClass;
20
+
21
+
22
+ public function __construct(object|string $objectOrMethod, ?string $method = null)
23
+ {
24
+ if (is_string($objectOrMethod) && str_contains($objectOrMethod, '::')) {
25
+ [$objectOrMethod, $method] = explode('::', $objectOrMethod, 2);
26
+ }
27
+ parent::__construct($objectOrMethod, $method);
28
+ $this->originalClass = new \ReflectionClass($objectOrMethod);
29
+ }
30
+
31
+
32
+ public function getOriginalClass(): \ReflectionClass
33
+ {
34
+ return $this->originalClass;
35
+ }
36
+ }