19 declare(strict_types=1);
33 protected function isPathIgnored(
string $path, Options $options): bool
35 $regex =
'(' . implode(
'|', $options->getIgnoredPathSnippets()) .
')';
36 return preg_match($regex, $path) > 0;
39 protected function ensureDirectorySeperator(
string $path): string
41 return rtrim($path,
"/") .
"/";
47 private function realpath(
string $path): string
49 $path = array_reduce(explode(
'/', $path),
function (
$a,
$b) {
53 if (
$b ===
"" ||
$b ===
".") {
60 return preg_replace(
"/\/+/",
"/",
"$a/$b");
62 return trim($path,
"/");
65 protected function normalizePath($path, $separator =
'\\/'): string
69 if (str_starts_with($path,
'..')) {
70 throw new \InvalidArgumentException(
'The ZIP name must not start with ../. Please provide a real path for the output file.');
74 if (!str_starts_with($path,
'./')) {
78 if (str_starts_with($path,
'./') && ($realpath = realpath($path)) !==
false) {
82 $normalized = preg_replace(
'#\p{C}+|^\./#u',
'', $path);
83 $normalized = preg_replace(
'#/\.(?=/)|^\./|\./$#',
'', $normalized);
84 $regex =
'#\/*[^/\.]+/\.\.#Uu';
86 while (preg_match($regex, $normalized)) {
87 $normalized = preg_replace($regex,
'', $normalized);
90 if (preg_match(
'#/\.{2}|\.{2}/#', $normalized)) {
91 throw new \LogicException(
92 'Path is outside of the defined root, path: [' . $path .
'], resolved: [' . $normalized .
']' 97 if (!str_starts_with($normalized,
'./') && !str_starts_with($normalized,
'/')) {
98 $normalized =
'./' . $normalized;
static deriveLocationFrom(string $absolute_path)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples