Prepares a directory structure for the given file(spec)
using the configured directory level.
this method is from https://github.com/zendframework/zf2/blob/master/library/Zend/Cache/Storage/Adapter/Filesystem.php

@param string $file
@return void
175794
public function prepareDirectoryStructure($file, $level = '')
    {
        if (!$level) {
            return;
        }

        // Directory structure already exists
        $pathname = dirname($file);
        if (file_exists($pathname)) {
            return;
        }

        $perm     = 0700;
        $umask    = false;

        if ($umask !== false && $perm !== false) {
            $perm = $perm & ~$umask;
        }

        if ($perm === false || $level == 1) {
            // build-in mkdir function is enough

            $umask = ($umask !== false) ? umask($umask) : false;
            $res   = mkdir($pathname, ($perm !== false) ? $perm : 0777, true);

            if ($umask !== false) {
                umask($umask);
            }

            if (!$res) {
                $oct = ($perm === false) ? '777' : decoct($perm);
                throw new Exception\OperationNotPermitedException(
                    "mkdir('{$pathname}', 0{$oct}, true) failed", 0, $err
                );
            }

            if ($perm !== false && !chmod($pathname, $perm)) {
                $oct = decoct($perm);
                throw new Exception\OperationNotPermitedException(
                    "chmod('{$pathname}', 0{$oct}) failed", 0, $err
                );
            }

        } else {
            // build-in mkdir function sets permission together with current umask
            // which doesn't work well on multo threaded webservers
            // -> create directories one by one and set permissions

            // find existing path and missing path parts
            $parts = array();
            $path  = $pathname;
            while (!file_exists($path)) {
                array_unshift($parts, basename($path));
                $nextPath = dirname($path);
                if ($nextPath === $path) {
                    break;
                }
                $path = $nextPath;
            }

            // make all missing path parts
            foreach ($parts as $part) {
                $path.= DIRECTORY_SEPARATOR . $part;

                // create a single directory, set and reset umask immediatly
                $umask = ($umask !== false) ? umask($umask) : false;
                $res   = mkdir($path, ($perm === false) ? 0777 : $perm, false);
                if ($umask !== false) {
                    umask($umask);
                }

                if (!$res) {
                    $oct = ($perm === false) ? '777' : decoct($perm);
                    throw new Exception\OperationNotPermitedException(
                        "mkdir('{$path}', 0{$oct}, false) failed"
                    );
                }

                if ($perm !== false && !chmod($path, $perm)) {
                    $oct = decoct($perm);
                    throw new Exception\OperationNotPermitedException(
                        "chmod('{$path}', 0{$oct}) failed"
                    );
                }
            }
        }
    }
230976
protected static function loadFile( $file )
    {
        switch ( ezcBase::$libraryMode )
        {
            case "devel":
            case "tarball":
                list( $first, $second ) = explode( '/', $file, 2 );
                $file = $first . "/src/" . $second;
                break;

            case "custom":
                list( $first, $second ) = explode( '/', $file, 2 );
                // Add the "src/" after the package name.
                if ( $first == 'Base' || $first == 'UnitTest' )
                {
                    list( $first, $second ) = explode( '/', $file, 2 );
                    $file = $first . "/src/" . $second;
                }
                else
                {
                    list( $first, $second, $third ) = explode( '/', $file, 3 );
                    $file = $first . '/' . $second . "/src/" . $third;
                }
                break;

            case "pear":
                /* do nothing, it's already correct */
                break;
        }

        if ( file_exists( ezcBase::$packageDir . $file ) )
        {
            require( ezcBase::$packageDir . $file );
        }
        else
        {
            // Can not be tested, because if this happens, then one of the
            // components has a broken autoload file.
            throw new ezcBaseFileNotFoundException( ezcBase::$packageDir.$file );
        }
    }
62233
public function mkFile($files)
    {
        foreach ($files as $file) {
            if (!is_file($file)) {
                @mkdir(dirname($file), 0777, true);
                file_put_contents($file, "<?php\n\nreturn [];\n");
            }
        }
    }
1089510
public static function setFile($file)
    {
        if (is_file($file)) {
            $options = Yaml::parse(file_get_contents($file));
            self::$instance = new self($options);
            self::$instance->validateOptions();
        } else {
            throw new Exception("Can't find config file at ".$file);
        }
    }
418179
public function load($file) {
		$this->file = $file;

		$msg = array();
		@include($file);

		$this->msg = $msg;
	}
547642
protected function prepareSeedClass($file)
    {
        $extension = $file->getExtension();
        if ($extension !== 'php') {
            return null;
        }
        return '\\' . str_replace('.' . $extension, '', $file->getFilename());
    }
1110034
public function load(string $file)
    {
        $this->data = Yaml::parse(file_get_contents($file));
        $this->filename = basename($file);
    }
1147123
public static function try_directory($file)
    {
      $matches = array();
      preg_match("/(.*\/).*$/", $file, $matches);
      
      try {
        if (sizeof($matches) >= 1) {
          $folder = $matches[1];

          if (!(is_dir($folder))) {
            mkdir($folder);
            return 1;
          }
        }
      } catch (Exception $e) {
        /** do not handle this exception it is low level and will be warned by the caller **/

        return -1;
      }

      return 1;
    }
33631
public function prepare($file)
    {
        if (request()->has(static::FILE_DELETE_FLAG)) {
            return $this->destroy();
        }

        $this->name = $this->getStoreName($file);

        return $this->uploadAndDeleteOriginal($file);
    }
94238
public function load($file)
    {
        $loader = new PhpConfig();
        $widgets = $loader->read($file);
        $this->add($widgets);
    }
1198301
protected function loader($file)
    {
        foreach ($this->folders as $folder)
        {
            foreach (FileLoader::extensions() as $ext)
            {
                try
                {
                    return FileLoader::load($folder . '/' . $file . '.' . $ext);
                }
                catch (\Throwable $throwable)
                {
                    // skip...
                }
            }
        }

        return null;
    }
519496
public static function chmod($file, $mode)
    {
        if (!@chmod($file, $mode)) {
            throw new IOException(sprintf("Cannot chmod %s to %s", $file, $mode));
        }
    }
1165985
public static function removeFile(string $file)
    {
        // Copied from [[removeDirectory()]]
        try {
            unlink($file);
        } catch (ErrorException $e) {
            if (DIRECTORY_SEPARATOR === '\\') {
                // last resort measure for Windows
                $lines = [];
                exec("DEL /F/Q \"$file\"", $lines, $deleteError);
            } else {
                throw $e;
            }
        }
    }
817512
public function chmod($mode, $file) {
		$this->connectIfNeeded();
		$this->handle->chmod($mode, $file);
		$this->onFileModeChanged(
			new Event(['sender' => $this, 'data' => [
				'mode' => $mode, 'file' => $file
			]])
		);
	}
546410
public function mutateFile(File &$file)
    {
        //
        // If the HTML file has a template then we should pass it on to the plates renderer
        //
        if ($template = $file->getData('template')) {
            $templateRelativePath = '_templates'.DIRECTORY_SEPARATOR.$template.'.phtml';
            $templatePath = $this->project->sourceDirectory.DIRECTORY_SEPARATOR.$templateRelativePath;
            if (file_exists($templatePath)) {
                $fileName = $file->getFilename();
                $filePath = $file->getPath();

                $file->setRendered(false);
                $file->setData(['content' => $file->getContent()]);
                $file->setFileInfo(new SplFileInfo($templatePath, '_templates', $templateRelativePath));
                $file->setContent($file->getFileContent());
                $file->setFilename($fileName);
                $file->setPath($filePath);
            }
        }
    }
122598
protected function setFileInformations($file)
    {
        $this->fileInfo = array(); // reset previously information to have a cleaned object
        if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
            $this->file = $file;
        } elseif ($file instanceof \TYPO3\CMS\Core\Resource\FileReference) {
            $this->file = $file = $file->getOriginalFile();
        }

        if (is_string($file) && !empty($file)) {
            $this->fileInfo = GeneralUtility::split_fileref($file);
            $this->fileInfo['mtime'] = filemtime($file);
            $this->fileInfo['atime'] = fileatime($file);
            $this->fileInfo['owner'] = fileowner($file);
            $this->fileInfo['group'] = filegroup($file);
            $this->fileInfo['size'] = filesize($file);
            $this->fileInfo['type'] = filetype($file);
            $this->fileInfo['perms'] = fileperms($file);
            $this->fileInfo['is_dir'] = is_dir($file);
            $this->fileInfo['is_file'] = is_file($file);
            $this->fileInfo['is_link'] = is_link($file);
            $this->fileInfo['is_readable'] = is_readable($file);
            $this->fileInfo['is_uploaded'] = is_uploaded_file($file);
            $this->fileInfo['is_writeable'] = is_writeable($file);
        }

        if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
            $pathInfo = \TYPO3\CMS\Core\Utility\PathUtility::pathinfo($file->getName());
            $this->fileInfo = array(
                'file' => $file->getName(),
                'filebody' => $file->getNameWithoutExtension(),
                'fileext' => $file->getExtension(),
                'realFileext' => $pathInfo['extension'],
                'atime' => $file->getCreationTime(),
                'mtime' => $file->getModificationTime(),
                'owner' => '',
                'group' => '',
                'size' => $file->getSize(),
                'type' => 'file',
                'perms' => '',
                'is_dir' => false,
                'is_file' => ($file->getStorage()->getDriverType() === 'Local' ?
                    is_file($file->getForLocalProcessing(false)) : true),
                'is_link' => ($file->getStorage()->getDriverType() === 'Local' ?
                    is_link($file->getForLocalProcessing(false)) : false),
                'is_readable' => true,
                'is_uploaded' => false,
                'is_writeable' => false,
            );
        }
        return $this->fileInfo !== array();
    }
63153
public static function addGeneratingFile( $file )
    {
        if ( !( $file instanceof eZDFSFileHandler ) )
            return false; // @todo Exception

        self::$generatingFiles[$file->filePath] = $file;
    }