PHPExiftool\Reader::computeExcludeDirs PHP Method

computeExcludeDirs() protected method

Compute raw exclude rules to simple ones, based on exclude dirs and search dirs
protected computeExcludeDirs ( string $rawExcludeDirs, $rawSearchDirs ) : array
$rawExcludeDirs string
return array
    protected function computeExcludeDirs($rawExcludeDirs, $rawSearchDirs)
    {
        $excludeDirs = array();
        foreach ($rawExcludeDirs as $excludeDir) {
            $found = false;
            /**
             * is this a relative path ?
             */
            foreach ($rawSearchDirs as $dir) {
                $currentPrefix = realpath($dir) . DIRECTORY_SEPARATOR;
                $supposedExcluded = str_replace($currentPrefix, '', realpath($currentPrefix . $excludeDir));
                if (!$supposedExcluded) {
                    continue;
                }
                if (strpos($supposedExcluded, DIRECTORY_SEPARATOR) === false) {
                    $excludeDirs[] = $supposedExcluded;
                    $found = true;
                    break;
                }
            }
            if ($found) {
                continue;
            }
            /**
             * is this an absolute path ?
             */
            $supposedExcluded = realpath($excludeDir);
            if ($supposedExcluded) {
                foreach ($rawSearchDirs as $dir) {
                    $searchDir = realpath($dir) . DIRECTORY_SEPARATOR;
                    $supposedRelative = str_replace($searchDir, '', $supposedExcluded);
                    if (strpos($supposedRelative, DIRECTORY_SEPARATOR) !== false) {
                        continue;
                    }
                    if (strpos($supposedExcluded, $searchDir) !== 0) {
                        continue;
                    }
                    if (!trim($supposedRelative)) {
                        continue;
                    }
                    $excludeDirs[] = $supposedRelative;
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                throw new RuntimeException(sprintf("Invalid exclude dir %s ; Exclude dir is limited to the name of a directory at first depth", $excludeDir));
            }
        }
        return $excludeDirs;
    }