src/Traits/PathTrait.php
private static function myParse(string $directorySeparator, string $path, callable $partValidator, ?callable $stringDecoder = null, ?bool &$isAbsolute = null, ?int &$aboveBaseLevel = null, ?array &$directoryParts = null, ?string &$filename = null, ?string &$error = null): bool
    {
        $parts = explode($directorySeparator, $path);
        $partsCount = count($parts);

        $directoryParts = [];
        $filename = null;
        $isAbsolute = false;
        $aboveBaseLevel = 0;
        $index = 0;

        // If the first part is empty and other parts follow, the path begins with directory separator and is therefore absolute.
        if ($partsCount > 1 && $parts[0] === '') {
            $isAbsolute = true;
            $index++;
        }

        // Go through all parts.
        for (; $index < $partsCount; $index++) {
            if (!self::myParsePart($parts[$index], $index === $partsCount - 1, $partValidator, $stringDecoder, $isAbsolute, $aboveBaseLevel, $directoryParts, $filename, $error)) {
                return false;
            }
        }

        return true;
    }
private static function myParse(string $directorySeparator, string $path, callable $partValidator, ?callable $stringDecoder = null, ?bool &$isAbsolute = null, ?int &$aboveBaseLevel = null, ?array &$directoryParts = null, ?string &$filename = null, ?string &$error = null): bool
    {
        $parts = explode($directorySeparator, $path);
        $partsCount = count($parts);

        $directoryParts = [];
        $filename = null;
        $isAbsolute = false;
        $aboveBaseLevel = 0;
        $index = 0;

        // If the first part is empty and other parts follow, the path begins with directory separator and is therefore absolute.
        if ($partsCount > 1 && $parts[0] === '') {
            $isAbsolute = true;
            $index++;
        }

        // Go through all parts.
        for (; $index < $partsCount; $index++) {
            if (!self::myParsePart($parts[$index], $index === $partsCount - 1, $partValidator, $stringDecoder, $isAbsolute, $aboveBaseLevel, $directoryParts, $filename, $error)) {
                return false;
            }
        }

        return true;
    }
private static function myParse ( string $ directorySeparator , string $ path , callable $ partValidator , ? callable $ stringDecoder = null , ? bool & $ isAbsolute = null , ? int & $ aboveBaseLevel = null , ? array & $ directoryParts = null , ? string & $ filename = null , ? string & $ error = null ) : bool { $ parts = explode ( $ directorySeparator , $ path ) ; $ partsCount = count ( $ parts ) ; $ directoryParts = [ ] ; $ filename = null ; $ isAbsolute = false ; $ aboveBaseLevel = 0 ; $ index = 0 ; // If the first part is empty and other parts follow, the path begins with directory separator and is therefore absolute. if ( $ partsCount > 1 && $ parts [ 0 ] === '' ) { $ isAbsolute = true ; $ index ++ ; } // Go through all parts. for ( ; $ index < $ partsCount ; $ index ++ ) { if ( ! self :: myParsePart ( $ parts [ $ index ] , $ index === $ partsCount - 1 , $ partValidator , $ stringDecoder , $ isAbsolute , $ aboveBaseLevel , $ directoryParts , $ filename , $ error ) ) { return false ; } } return true ; }
Tries to parse a path and returns the result or error text.

@param string        $directorySeparator The directory separator.
@param string        $path               The path.
@param callable      $partValidator      The part validator.
@param callable|null $stringDecoder      The string decoding function or null if parts should not be decoded.
@param bool|null     $isAbsolute         Whether the path is absolute or relative if parsing was successful, undefined otherwise.
@param int|null      $aboveBaseLevel     The number of directory parts above base level if parsing was successful, undefined otherwise.
@param string[]|null $directoryParts     The directory parts if parsing was successful, undefined otherwise.
@param string|null   $filename           The file if parsing was not successful, undefined otherwise.
@param string|null   $error              The error text if validation was not successful, undefined otherwise.

@return bool True if parsing was successful, false otherwise.
Tries to parse a path and returns the result or error text .