diff --git a/src/Iterators/Mapper.php b/src/Iterators/Mapper.php index 87823baf9..284da29da 100644 --- a/src/Iterators/Mapper.php +++ b/src/Iterators/Mapper.php @@ -10,9 +10,8 @@ namespace Nette\Iterators; - /** - * Applies the callback to the elements of the inner iterator. + * @deprecated use Nette\Utils\Iterables::map() */ class Mapper extends \IteratorIterator { diff --git a/src/Utils/Arrays.php b/src/Utils/Arrays.php index c33fb9a57..497f5f11b 100644 --- a/src/Utils/Arrays.php +++ b/src/Utils/Arrays.php @@ -369,11 +369,11 @@ public static function pick(array &$array, string|int $key, mixed $default = nul /** * Tests whether at least one element in the array passes the test implemented by the provided function, - * which has the signature `function ($value, $key, array $array): bool`. - * @template K + * which has the signature `function (mixed $value, int|string $key, array $array): bool`. + * @template K of array-key * @template V - * @param iterable $array - * @param callable(V, K, ($array is array ? array : iterable)): bool $predicate + * @param array $array + * @param callable(V, K, array): bool $predicate */ public static function some(iterable $array, callable $predicate): bool { @@ -389,11 +389,11 @@ public static function some(iterable $array, callable $predicate): bool /** * Tests whether all elements in the array pass the test implemented by the provided function, - * which has the signature `function ($value, $key, array $array): bool`. - * @template K + * which has the signature `function (mixed $value, int|string $key, array $array): bool`. + * @template K of array-key * @template V - * @param iterable $array - * @param callable(V, K, ($array is array ? array : iterable)): bool $predicate + * @param array $array + * @param callable(V, K, array): bool $predicate */ public static function every(iterable $array, callable $predicate): bool { @@ -430,12 +430,12 @@ public static function filter(array $array, callable $predicate): array /** * Returns an array containing the original keys and results of applying the given transform function to each element. - * The function has signature `function ($value, $key, array $array): mixed`. + * The function has signature `function (mixed $value, int|string $key, array $array): mixed`. * @template K of array-key * @template V * @template R - * @param iterable $array - * @param callable(V, K, ($array is array ? array : iterable)): R $transformer + * @param array $array + * @param callable(V, K, array): R $transformer * @return array */ public static function map(iterable $array, callable $transformer): array diff --git a/src/Utils/Callback.php b/src/Utils/Callback.php index 732af9670..867c0bc43 100644 --- a/src/Utils/Callback.php +++ b/src/Utils/Callback.php @@ -94,7 +94,9 @@ public static function toReflection($callable): \ReflectionMethod|\ReflectionFun } if (is_string($callable) && str_contains($callable, '::')) { - return new ReflectionMethod($callable); + return PHP_VERSION_ID < 80300 + ? new ReflectionMethod($callable) + : ReflectionMethod::createFromMethodName($callable); } elseif (is_array($callable)) { return new ReflectionMethod($callable[0], $callable[1]); } elseif (is_object($callable) && !$callable instanceof \Closure) { diff --git a/src/Utils/FileSystem.php b/src/Utils/FileSystem.php index ab9a7e878..fb60d7470 100644 --- a/src/Utils/FileSystem.php +++ b/src/Utils/FileSystem.php @@ -305,6 +305,18 @@ public static function joinPaths(string ...$paths): string } + public static function resolvePath(string ...$paths): string + { + for ($i = count($paths) - 1; $i >= 0; $i--) { + if (self::isAbsolute($paths[$i])) { + return self::joinPaths(...array_slice($paths, $i)); + } + } + + return self::joinPaths(getcwd(), ...$paths); + } + + /** * Converts backslashes to slashes. */ diff --git a/src/Utils/Reflection.php b/src/Utils/Reflection.php index 5a4f2ab75..8ad3aa9bf 100644 --- a/src/Utils/Reflection.php +++ b/src/Utils/Reflection.php @@ -100,7 +100,7 @@ public static function getMethodDeclaringMethod(\ReflectionMethod $method): \Ref $hash = [$method->getFileName(), $method->getStartLine(), $method->getEndLine()]; if (($alias = $decl->getTraitAliases()[$method->name] ?? null) - && ($m = new \ReflectionMethod($alias)) + && ($m = PHP_VERSION_ID < 80300 ? new \ReflectionMethod($alias) : \ReflectionMethod::createFromMethodName($alias)) && $hash === [$m->getFileName(), $m->getStartLine(), $m->getEndLine()] ) { return self::getMethodDeclaringMethod($m); diff --git a/tests/Utils/FileSystem.resolvePath.phpt b/tests/Utils/FileSystem.resolvePath.phpt new file mode 100644 index 000000000..a0f2c367f --- /dev/null +++ b/tests/Utils/FileSystem.resolvePath.phpt @@ -0,0 +1,21 @@ +