[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: FilePathHelper.php
File is not writable. Editing disabled.
<?php declare (strict_types=1); namespace Rector\FileSystem; use RectorPrefix202411\Nette\Utils\Strings; use Rector\Skipper\FileSystem\PathNormalizer; use RectorPrefix202411\Symfony\Component\Filesystem\Filesystem; use RectorPrefix202411\Webmozart\Assert\Assert; /** * @see \Rector\Tests\FileSystem\FilePathHelperTest */ final class FilePathHelper { /** * @readonly * @var \Symfony\Component\Filesystem\Filesystem */ private $filesystem; /** * @see https://regex101.com/r/d4F5Fm/1 * @var string */ private const SCHEME_PATH_REGEX = '#^([a-z]+)\\:\\/\\/(.+)#'; /** * @see https://regex101.com/r/no28vw/1 * @var string */ private const TWO_AND_MORE_SLASHES_REGEX = '#/{2,}#'; /** * @var string */ private const SCHEME_UNDEFINED = 'undefined'; public function __construct(Filesystem $filesystem) { $this->filesystem = $filesystem; } public function relativePath(string $fileRealPath) : string { if (!$this->filesystem->isAbsolutePath($fileRealPath)) { return $fileRealPath; } return $this->relativeFilePathFromDirectory($fileRealPath, \getcwd()); } /** * Used from * https://github.com/phpstan/phpstan-src/blob/02425e61aa48f0668b4efb3e73d52ad544048f65/src/File/FileHelper.php#L40, with custom modifications */ public function normalizePathAndSchema(string $originalPath) : string { $directorySeparator = \DIRECTORY_SEPARATOR; $matches = Strings::match($originalPath, self::SCHEME_PATH_REGEX); if ($matches !== null) { [, $scheme, $path] = $matches; } else { $scheme = self::SCHEME_UNDEFINED; $path = $originalPath; } $normalizedPath = PathNormalizer::normalize((string) $path); $path = Strings::replace($normalizedPath, self::TWO_AND_MORE_SLASHES_REGEX, '/'); $pathRoot = \strncmp($path, '/', \strlen('/')) === 0 ? $directorySeparator : ''; $pathParts = \explode('/', \trim($path, '/')); $normalizedPathParts = $this->normalizePathParts($pathParts, $scheme); $pathStart = $scheme !== self::SCHEME_UNDEFINED ? $scheme . '://' : ''; return PathNormalizer::normalize($pathStart . $pathRoot . \implode($directorySeparator, $normalizedPathParts)); } private function relativeFilePathFromDirectory(string $fileRealPath, string $directory) : string { Assert::directory($directory); $normalizedFileRealPath = PathNormalizer::normalize($fileRealPath); $relativeFilePath = $this->filesystem->makePathRelative($normalizedFileRealPath, $directory); return \rtrim($relativeFilePath, '/'); } /** * @param string[] $pathParts * @return string[] */ private function normalizePathParts(array $pathParts, string $scheme) : array { $normalizedPathParts = []; foreach ($pathParts as $pathPart) { if ($pathPart === '.') { continue; } if ($pathPart !== '..') { $normalizedPathParts[] = $pathPart; continue; } /** @var string $removedPart */ $removedPart = \array_pop($normalizedPathParts); if ($scheme !== 'phar') { continue; } if (\substr_compare($removedPart, '.phar', -\strlen('.phar')) !== 0) { continue; } $scheme = self::SCHEME_UNDEFINED; } return $normalizedPathParts; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium264.web-hosting.com
Server IP: 69.57.162.13
PHP Version: 8.1.34
Server Software: LiteSpeed
System: Linux premium264.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 73.58 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
No
pkexec:
No
git:
Yes
User Info
Username: kidscntx
User ID (UID): 1154
Group ID (GID): 1112
Script Owner UID: 1154
Current Dir Owner: N/A