Read area definitions and content from the disk

@param  string $dirPath
352406
private function scanAreas($dirPath)
    {
        $dirPath = realpath($dirPath);

        if(strcmp($this->contentPath, $dirPath) > 0)
        {
            return;
        }

        if(is_dir($dirPath) && (($dir = @opendir($dirPath)) !== false))
        {
            while (($subDirName = readdir($dir)) !== false)
            {
                if(
                    ((substr($subDirName, 0, 1) == '.') || (substr($subDirName, 0, 1) == '_')) &&
                    $subDirName != '.' &&
                    $subDirName != '..' &&
                    is_dir($dirPath . DIRECTORY_SEPARATOR . $subDirName)
                ) {
                    $areaName = $subDirName;
                    //Searching for all areas
                    if(realpath($this->contentPath . $this->getNode()->getUri()) == $dirPath)
                    {
                        //normalize area name
                        $areaName = (substr($areaName, 1, 5) == 'tree_') ? substr($areaName, 6) : substr($areaName, 1);
                        $area = new Area($areaName, false);
                        $this->areas[$areaName] = $area;
                        $this->fillArea($area, $dirPath . DIRECTORY_SEPARATOR . $subDirName);
                    }
                    //Searching for areas to inherit only
                    else
                    {
                        if(substr($areaName, 1, 5) == 'tree_')
                        {
                            $areaName = substr($areaName, 6);

                            if(!$this->hasArea($areaName))
                            {
                                $area = new Area($areaName, true);
                                $this->areas[$areaName] = $area;
                                $this->fillArea($area, $dirPath . DIRECTORY_SEPARATOR . $subDirName);
                            }
                        }
                    }
                }
            }

            closedir($dir);
        }
        // @codeCoverageIgnoreStart
        else
        {
            throw new  PageException("Unable to read path");
        }
        // @codeCoverageIgnoreEnd

        $this->scanAreas($dirPath . '/..');
    }
1372503
protected function collectFiles(string $dir, string $basePath): array
    {
        $files = [];
        $dh = \opendir($dir);
        
        try {
            while (false !== ($entry = \readdir($dh))) {
                if ($entry == '.' || $entry == '..') {
                    continue;
                }
                
                $check = $dir . \DIRECTORY_SEPARATOR . $entry;
                
                if (\is_dir($check)) {
                    foreach ($this->collectFiles($check, $basePath . '/' . $entry) as $k => $v) {
                        $files[$k] = $v;
                    }
                } elseif (\is_file($check)) {
                    $files[$basePath . '/' . $entry] = $check;
                }
            }
            
            return $files;
        } finally {
            \closedir($dh);
        }
    }
1045094
function (dirPath) {

		var dirContents = fs.readdirSync(dirPath);
		return dirContents.filter(function (subDirName) {
			// Filter out non-directories.
			var subDirPath = path.join(dirPath, subDirName);
			return fs.lstatSync(subDirPath).isDirectory();
		});
	}
350833
protected function getFileList($dirPath)
    {
        $fileList = array();

        $paths = $this->getFileDirs($dirPath);
        foreach ($paths as $filesPath) {
            if (file_exists($filesPath)) {
                $files = $this->getFileManager()->getFileList($filesPath, true, '', true, true);
                $fileList = array_merge($fileList, $files);
            }
        }

        //vendor file list
        $vendorFileList = $this->getVendorFileList('copy');
        if (!empty($vendorFileList)) {
            $fileList = array_merge($fileList, $vendorFileList);
        }

        return $fileList;
    }
1341672
private static function dirReady($path) {
    if (!file_exists($path)) {
      $parent = preg_replace("/\/[^\/]+\/?$/", '', $path);
      if (!self::dirReady($parent)) {
        return FALSE;
      }

      mkdir($path, 0777, true);
    }

    if (!is_dir($path)) {
      trigger_error('Path is not a directory ' . $path, E_USER_WARNING);
      return FALSE;
    }

    if (!is_writable($path)) {
      trigger_error('Unable to write to ' . $path . ' – check directory permissions –', E_USER_WARNING);
      return FALSE;
    }

    return TRUE;
  }
51656
public function readFileFunc($filepath)
    {
        /** @var UniformResourceLocator $locator */
        $locator = $this->grav['locator'];

        if ($locator->isStream($filepath)) {
            $filepath = $locator->findResource($filepath);
        }

        if ($filepath && file_exists($filepath)) {
            return file_get_contents($filepath);
        }

        return false;
    }
1294337
public function scan( $path )
	{
		$this->numberFound		= 0;
		$this->numberScanned	= 0;
		$this->numberTodos		= 0;
		$this->numberLines		= 0;
		$this->list				= array();
		$extensions		= $this->getExtensionPattern(); 
		$pattern		= $this->getExtendedPattern();
		$iterator		= $this->getIndexIterator( $path, $extensions );
		try{
			foreach( $iterator as $entry )
			{
				$this->numberScanned++;
				$content	= file_get_contents( $entry->getPathname() );
				$lines		= explode( "\n", $content );
				$i			= 0;
				$list		= array();
				foreach( $lines as $line )
				{
					$this->numberLines++;
					$i++;
					if( !preg_match( $pattern, $line ) )
						continue;
					$this->numberTodos++;
					$list[$i]	= $line;#trim( $line );
				}
				if( !$list )
					continue;
				$this->numberFound++;
				$this->list[$entry->getPathname()]	= array(
					'fileName'	=> $entry->getFilename(),
					'lines'		=> $list,
				);
			}
		}
		catch( UnexpectedValueException $e ){
		}
		catch( Exception $e ){
			throw new RuntimeException( $e->getMessage(), $e->getCode(), $es );
		}
	}
802169
function readdir(fullpath, cb) {
    get(self.endpoint + '/contents' + fullpath + self.refparam, cb);
  }
1303338
protected function _rrmdir( $path )
    {
        $i = new DirectoryIterator( $path );
        foreach( $i as $f )
        {
            if( $f->isFile() )
            {
                $this->warn( 'Permanently removed file ' . str_replace( base_path(), null, $f->getRealPath() ) );
                unlink( $f->getRealPath() );
            }
            else if( !$f->isDot() && $f->isDir() )
            {
                $this->_rrmdir( $f->getRealPath() );
            }
        }
        $this->warn( 'Permanently removed directory' . str_replace( base_path(), null, $path ) );
        rmdir( $path );
    }
293806
function fileFetchContents( $filePath )
    {
        eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileFetchContents( '$filePath' )", __METHOD__ );

        eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
        $rslt = is_readable( $filePath ) ? file_get_contents( $filePath ) : false;
        eZDebug::accumulatorStop( 'dbfile' );

        return $rslt;
    }
494418
private function lsdir(string $path): array
    {
        $result = @scandir($path);

        if (false === $result) {
            $message = 'Could not read directory.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        return array_values(array_diff($result, ['.', '..']));
    }
42713
public static function mkdir($dirpath)
    {
        if(isset(Yii::$aliases['@static'])){
            $root = Yii::getAlias('@static') . DIRECTORY_SEPARATOR;
        }else{
            $root = Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR;
        }

        $root = preg_replace('/[\\\\\/]/', DIRECTORY_SEPARATOR, $root);
        $dirpath = preg_replace('/[\\\\\/]/', DIRECTORY_SEPARATOR, $dirpath);

        if($dirpath != $root && !file_exists($dirpath)){
            $path = explode(DIRECTORY_SEPARATOR, str_replace($root, '', $dirpath));

            $dirpath = $root . array_shift($path);

            if(!file_exists($dirpath)){
                @mkdir($dirpath);
                @chmod($dirpath, 0777);
            }

            foreach($path as $dir){
                $dirpath .= DIRECTORY_SEPARATOR . $dir;

                if($dir != '.' && $dir != '..'){
                    if(!file_exists($dirpath)){
                        @mkdir($dirpath);
                        @chmod($dirpath, 0777);
                    }
                }
            }
        }

        return $dirpath;
    }
1010710
public function loadTheme(string $dirPath, string $configPath)
    {
        $theme = (new ThemeManager($this, $dirPath, new ClassLoader()))
            ->load($dirPath.'/'.trim($configPath, '\/'));

        $this->instance('wp.theme', $theme);

        return $theme;
    }
665452
private function deleteFiles($dirPath)
    {
        foreach (glob($dirPath.DIRECTORY_SEPARATOR.'{*,.[!.]*,..?*}', GLOB_BRACE) as $content) {
            if (is_dir($content)) {
                $this->deleteFiles($content);
            } else {
                unlink($content);
            }
        }
        rmdir($dirPath);
    }
972456
public static function enumPHPFile($dirPath)
    {
        if (!is_dir($dirPath)) {
            return new \ArrayIterator();
        }
        $directory = new \RecursiveDirectoryIterator($dirPath);
        $iterator = new \RecursiveIteratorIterator($directory);
        $regex = new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH);
        return $regex;
    }
240452
public function setDirPaths($dir_path)
    {
        if (is_null($dir_path)) {
            $this->setDir($this->getUploadPath());
            $this->setDirPath("");
        } else {
            $this->setDirPath($this->DirTrim($dir_path));
            $this->setDir($this->getUploadPath() . self::DS . $dir_path);
        }

        $path_valid = $this->checkPath($this->getDir());
        if (!$path_valid) {
            $this->setDir($this->getUploadPath());
        }
    }
1233013
protected function dirnameCE($path) {
		return (!$this->encoding)? $this->_dirname($path) :	$this->convEncOut($this->_dirname($this->convEncIn($path)));
	}