{@inheritdoc}

@see \C5TL\Parser::parseDirectoryDo()
342741
protected function parseDirectoryDo(\Gettext\Translations $translations, $rootDirectory, $relativePath, $subParsersFilter, $exclude3rdParty)
    {
        switch ($relativePath) {
            case '':
                $directoryAlternatives = array('application/config/generated_overrides', 'application/config', 'concrete/config');
                break;
            case 'application':
                $directoryAlternatives = array('config/generated_overrides', 'config');
                break;
            case 'concrete':
                $directoryAlternatives = array('config');
                break;
            default:
                return;
        }
        $prefix = ($relativePath === '') ? '' : "$relativePath/";
        $this->parseFileTypes($translations, $rootDirectory, $prefix, $directoryAlternatives);
        $this->parseTranslatableStrings($translations, $rootDirectory, $prefix, $directoryAlternatives);
    }
1101805
protected function doChangeDir($dir)
    {
        $connection = $this->connection;

        return $this->retry(function () use ($connection, $dir) {
            $res = @ftp_chdir($connection, $dir);

            if (false === $res) {
                throw new \RuntimeException("Changing directory failed: ".$dir);
            }
        });
    }
901179
public static function dieIfDirectoriesNotWritable($directoriesToCheck = null)
    {
        $resultCheck = self::checkDirectoriesWritable($directoriesToCheck);
        if (array_search(false, $resultCheck) === false) {
            return;
        }

        $directoryList = '';
        foreach ($resultCheck as $dir => $bool) {
            $realpath = Filesystem::realpath($dir);
            if (!empty($realpath) && $bool === false) {
                $directoryList .= self::getMakeWritableCommand($realpath);
            }
        }

        // Also give the chown since the chmod is only 755
        if (!SettingsServer::isWindows()) {
            $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/');
            $directoryList = "<code>chown -R ". self::getUserAndGroup() ." " . $realpath . "</code><br />" . $directoryList;
        }

        if (function_exists('shell_exec')) {
            $currentUser = self::getUser();
            if (!empty($currentUser)) {
                $optionalUserInfo = " (running as user '" . $currentUser . "')";
            }
        }

        $directoryMessage  = "<p><b>Matomo couldn't write to some directories $optionalUserInfo</b>.</p>";
        $directoryMessage .= "<p>Try to Execute the following commands on your server, to allow Write access on these directories"
            . ":</p>"
            . "<blockquote>$directoryList</blockquote>"
            . "<p>If this doesn't work, you can try to create the directories with your FTP software, and set the CHMOD to 0755 (or 0777 if 0755 is not enough). To do so with your FTP software, right click on the directories then click permissions.</p>"
            . "<p>After applying the modifications, you can <a href='index.php'>refresh the page</a>.</p>"
            . "<p>If you need more help, try <a target='_blank' rel='noreferrer noopener' href='https://matomo.org'>Matomo.org</a>.</p>";

        $ex = new MissingFilePermissionException($directoryMessage);
        $ex->setIsHtmlMessage();

        throw $ex;
    }
1142548
protected function parseDirectory($directory)
    {

        // check if we've found a valid directory
        if (is_dir($directory) === false) {
            return;
        }

        // load the object manager instance
        /** @var \AppserverIo\Psr\Di\ObjectManagerInterface $objectManager */
        $objectManager = $this->getApplication()->search(ObjectManagerInterface::IDENTIFIER);

        // check directory for classes we want to register
        /** @var \AppserverIo\Appserver\Core\Api\DeploymentService $service */
        $service = $this->getApplication()->newService('AppserverIo\Appserver\Core\Api\DeploymentService');
        $phpFiles = $service->globDir($directory . DIRECTORY_SEPARATOR . '*.php');

        // iterate all php files
        foreach ($phpFiles as $phpFile) {
            // iterate over all configured descriptors and try to load object description
            foreach ($this->getDescriptors() as $descriptor) {
                try {
                    // cut off the META-INF directory and replace OS specific directory separators
                    $relativePathToPhpFile = str_replace(DIRECTORY_SEPARATOR, '\\', str_replace($directory, '', $phpFile));

                    // now cut off the .php extension
                    $className = substr($relativePathToPhpFile, 0, -4);

                    // we need a reflection class to read the annotations
                    /** \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass */
                    $reflectionClass = $objectManager->getReflectionClass($className);

                    // load the descriptor class
                    $descriptorClass = $descriptor->getNodeValue()->getValue();

                    // load the object descriptor and add it to the object manager
                    /** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */
                    if (class_exists($descriptorClass)) {
                        if ($objectDescriptor = $descriptorClass::newDescriptorInstance()->fromReflectionClass($reflectionClass)) {
                            $objectManager->addObjectDescriptor($objectDescriptor);
                        }
                    }

                // if class can not be reflected continue with next class
                } catch (\Exception $e) {
                    // log an error message
                    $this->getApplication()->getInitialContext()->getSystemLogger()->error($e->__toString());

                    // proceed with the next bean
                    continue;
                }
            }
        }
    }
454327
private static function parseHomeDirectory()
    {
        try {
            $homeDir = System::parseHomeDirectory();

            System::denyWebAccess($homeDir);

            return $homeDir;
        } catch (InvalidConfigException $e) {
            // Context variable was not found -> no home directory
            // This happens often on web servers where the home directory is
            // not set manually
            return null;
        }
    }
1181810
static function RecursiveUnlinkDir($dir,&$error = null,&$error_str = null){
		$error = false;
		$error_str = "";
		settype($dir,"string");
		return Files::_RecursiveUnlinkDir($dir,$error,$error_str);
	}
898077
protected function find($directory)
    {
        if (!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) {
            return false;
        }

        $iterator = new \RecursiveDirectoryIterator(realpath($directory));
        return new \RecursiveIteratorIterator($iterator);
    }
202919
function parseDirectoryEntries(directoryStr) {
		const directoryEntries = [];
		let pos = 0;
		let count = 0;

		while (directoryStr.length - pos >= 12) {
			directoryEntries[count] = directoryStr.substring(pos, pos + 12);
			pos += 12;
			count++;
		}

		return directoryEntries;
	}
507333
public function listDirectory($directory = '.', $ref = 'HEAD')
    {
        $directory  = FileSystem::normalizeDirectorySeparator($directory);
        $directory  = $this->resolveLocalPath(rtrim($directory, '/') . '/');
        $path       = $this->getRepositoryPath();

        /** @var $result CallResult */
        $result = $this->getGit()->{'ls-tree'}($path, array(
            '--name-only',
            '--full-name',
            '-z',
            $ref,
            $this->translatePathspec($directory)
        ));
        $result->assertSuccess(sprintf('Cannot list directory "%s" at "%s" from "%s"',
            $directory, $ref, $this->getRepositoryPath()
        ));

        $output     = $result->getStdOut();
        $listing    = array_map(function($f) use ($directory) {
            return str_replace($directory, '', trim($f));
        }, explode("\x0", $output));
        return $listing;
    }
466176
protected function getCommandExecutionResult(CommandsExecutionDto $commandsDto)
    {
        $commandResult = null;

        switch ($this->osType):
            case(CommandsConstants::LINUX):
                $commandResult = LinuxCommands::getCommandResult($commandsDto);
                break;
            default:
                throw new CommandsExecutionException('Unknown OS type.');
        endswitch;

        return $commandResult;
    }
938453
private function parseItemNodes(\DOMNode $source, \DOMNodeList $resources, Sco $parentSco = null)
    {
        $item = $source->firstChild;
        $scos = [];

        while (!is_null($item)) {
            if ('item' === $item->nodeName) {
                $sco = new Sco();
                $scos[] = $sco;
                $sco->setScoParent($parentSco);
                $this->findAttrParams($sco, $item, $resources);
                $this->findNodeParams($sco, $item->firstChild);

                if ($sco->isBlock()) {
                    $sco->setScoChildren($this->parseItemNodes($item, $resources, $sco));
                }
            }
            $item = $item->nextSibling;
        }

        return $scos;
    }
422855
public function getDirectory(string $id): Directory
    {
        if (isset($this->directories[$id])) {
            return $this->directories[$id];
        }

        if ($this->hasDirectory($id)) {
            return $this->directories[$id] = new static($this->filesystem, $this->getDirectoryPath($id), $this->format);
        }

        throw new RuntimeException(sprintf('Directory "%s" not found', $id));
    }
483926
static function chdir($dir, $callback = null, $argv = array())
    {
        if (!is_dir($dir)) {
            throw new \InvalidArgumentException("$dir does not exist.");
        }

        $cwd = getcwd();
        chdir($dir);

        if (null === $callback) {
            return;
        }

        $returnValue = call_user_func_array($callback, $argv);

        chdir($cwd);
        return $returnValue;
    }
1100700
public static function fromDirectory(string $directory): array
    {
        if (!\is_dir($directory)) {
            throw Exception\DirectoryDoesNotExist::fromDirectory($directory);
        }

        $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(
            $directory,
            \RecursiveDirectoryIterator::FOLLOW_SYMLINKS
        ));

        $constructs = [];

        foreach ($iterator as $fileInfo) {
            /** @var \SplFileInfo $fileInfo */
            if (!$fileInfo->isFile()) {
                continue;
            }

            if ($fileInfo->getBasename('.php') === $fileInfo->getBasename()) {
                continue;
            }

            $fileName = $fileInfo->getRealPath();

            /** @var string $source */
            $source = \file_get_contents($fileName);

            try {
                $constructsFromFile = self::fromSource($source);
            } catch (Exception\ParseError $exception) {
                throw Exception\ParseError::fromFileNameAndParseError(
                    $fileName,
                    $exception
                );
            }

            if (0 === \count($constructsFromFile)) {
                continue;
            }

            foreach ($constructsFromFile as $construct) {
                $name = $construct->name();

                if (\array_key_exists($name, $constructs)) {
                    $construct = $constructs[$name];
                }

                $constructs[$name] = $construct->definedIn($fileName);
            }
        }

        \usort($constructs, static function (Construct $a, Construct $b) {
            return \strcmp(
                $a->name(),
                $b->name()
            );
        });

        $constructsWithMultipleDefinitions = \array_filter($constructs, static function (Construct $construct) {
            return 1 < \count($construct->fileNames());
        });

        if (0 < \count($constructsWithMultipleDefinitions)) {
            throw Exception\MultipleDefinitionsFound::fromConstructs($constructsWithMultipleDefinitions);
        }

        return \array_values($constructs);
    }
905390
public function parse()
    {
        $result = new stdClass();
        $cache = $parser = $exception = $cacheKey = $path = null;
        try {
            $path = $this->find(false);
            // Cached response
            $cache = new PathCache(__FUNCTION__, $this->options);
            $cacheKey = $cache->getKey([$path]);
            $result = $cache->readFrom($cacheKey);
            if ($result !== false) {
                return $result;
            }
            // Real response
            $parser = $this->getParser();
            $result = $parser->parse($path);
        } catch (InvalidArgumentException $exception) {
            $this->mergeMessages($exception, __FUNCTION__);
        }
        $this->mergeMessages($parser, __FUNCTION__);
        $this->mergeMessages($cache, __FUNCTION__);

        // Re-throw parser exception
        if ($exception) {
            throw $exception;
        }

        if ($cache && $cacheKey) {
            $cache->writeTo($cacheKey, $result, ['path' => $path]);
        }

        return $result;
    }
467281
private function getDirectoryIterator(string $directory): \DirectoryIterator
    {
        if ($directory === 'default') {
            return new \DirectoryIterator($this->dataDirectory);
        }
        return new \DirectoryIterator($directory);
    }
657623
public function definirDirApp($directorio)
    {
        $this->dirApp = realpath($directorio);

        $this->dirAutoCargado[] = $this->dirApp . DIRECTORY_SEPARATOR . 'controladores';
        $this->dirAutoCargado[] = $this->dirApp . DIRECTORY_SEPARATOR . 'modelos';
    }