@param string      $path
@param string|null $filename
@param bool|null   $overwrite
@param array|null  $required
@param bool|null   $global

@return \chillerlan\DotEnv\DotEnv
@throws \Exception
772557
public function loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null, bool $global = null):DotEnv{
		$this->global = $global;
		$file         = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.($filename ?? '.env');
		$content      = $this->read($file);

		return $this
			->loadData($content, $overwrite ?? false)
			->check($required)
		;
	}
715480
public static function createFromDataPath(string $path, $context = null): self
    {
        $file_args = [$path, false];
        $mime_args = [$path, FILEINFO_MIME];
        if (null !== $context) {
            $file_args[] = $context;
            $mime_args[] = $context;
        }

        $raw = @file_get_contents(...$file_args);
        if (false === $raw) {
            throw new SyntaxError(sprintf('The file `%s` does not exist or is not readable', $path));
        }

        return Uri::createFromComponents([
            'scheme' => 'data',
            'path' => str_replace(' ', '', (new finfo(FILEINFO_MIME))->file(...$mime_args)).';base64,'.base64_encode($raw),
        ]);
    }
975399
public static function at($path)
    {
        $file = new static($path);

        if (! $file->exists()) {
            throw new NonExistentFileException("File does not exist at $path");
        }

        if (! $file->isReadable()) {
            throw new FilePermissionsException("File not readable at $path");
        }

        return $file;
    }
508540
public function newFileFromName($path, $name, $hashName = false){
        $info = pathinfo($name);
        $ext = isset($info['extension'])? ".{$info['extension']}":"";
        $name = $info['filename'];
        $n = $hashName?md5($name):$name;
        $file = new FileImpl("$path/$n$ext");
        $i = 0;
        while($file->exists()){
            $i++;
            $n = $hashName?md5($name.$i):"$name ($i)";
            $file = new FileImpl("$path/$n$ext");
        }
        return $file;

    }
697891
public static function load($path = __DIR__, $file = ".env")
    {
        $content = File::readLines($path . "/" . $file);
        $dotenv = static::parse($content);
        return static::apply($dotenv);
    }
207327
public static function create(string $path, string $content = '', bool $overwrite = true): self
    {
        $path = normalize_path($path);

        if (is_file($path) && $overwrite) {
            self::unlink($path);
        }
        if (!is_file($path)) {
            if (is_writeable(dirname($path))) {
                if ($handle = fopen($path, 'w')) {
                    fwrite($handle, $content);
                    fclose($handle);

                    return new static($path);
                }
                throw new FileException('Creating file ('.$path.') failed');
            }
            throw new FileException('Cannot create file, because the directory ('.dirname($path).') is not accessible',
                FileException::NOT_WRITEABLE);
        }
        throw new FileException('Cannot create file, because the file path ('.$path.') already exist', FileException::ALREADY_EXIST);
    }
133057
public function load($path, $file = '.env')
    {
        try {
            $env = new \Dotenv\Dotenv($path, $file);
            $env->load();

            return true;
        } catch (\Dotenv\Exception\InvalidPathException $e) {
            return false;
        }
    }
400372
public function load($dir, $env = null, $basename = 'config', $extension = 'yml')
    {
        $filepath = $dir . '/' . $basename . '.' . $extension;

        if (!file_exists($filepath)) {
            throw new \Exception(sprintf("Config file \"%s\" does not exist", $filepath));
        }

        $parameters = Yaml::parse($filepath);

        //Override configuration for a specific environment
        if ($env) {
            $filepath = $dir . '/' . $basename . '_' . $env . '.' . $extension;
            if (file_exists($filepath)) {
                $envParameters = Yaml::parse($filepath);
                if ($envParameters) {
                    $parameters = $this->deepMerge($parameters, $envParameters);
                }
            }
        }
        
        return $parameters;
    }
738520
public function copy(string $newFilePath, bool $overwrite = true): self
    {
        $newFilePath = normalize_path($newFilePath);

        if ($overwrite || !is_file($newFilePath)) {
            if (copy($this->path, $newFilePath)) {
                return new self($newFilePath);
            }
            throw new FileException('Cannot copy file to the new file path ('.$newFilePath.') for unknown reasons');
        }
        throw new FileException('Cannot copy file, because the new file path ('.$newFilePath.') already exists', FileException::ALREADY_EXIST);
    }
467728
public static function requireFiles($path)
	{
		$dir = new \DirectoryIterator($path);

		foreach ($dir as $file)
		{

			if (!$file->isDot() || !$file->isDir())
			{

				$file_extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);

				if ($file_extension === 'php')
				{

					static::$names[] = $file->getBasename('.php');

					include_once $file->getPath() . DS . $file->getBasename();

				}

			}

		}
	}
562261
function requireTree($path)
    {
        $resolved = $this->resolve($path);

        if (!$resolved) {
            throw new \InvalidArgumentException("Path '$path' not found.");
        }

        $dir = new \FilesystemIterator($resolved);

        foreach ($dir as $file) {
            # Ignore dotted files
            if (substr($file->getBasename(), 0, 1) !== '.') {
                $this->requireAsset($file->getRealpath());
            }
        }

        return $this;
    }
697118
public function load($path = self::DEFAULT_FILENAME)
	{
		$file = new File($path);

		if (($data = json_decode($file->read(), true)) === null) {
			throw new \UnexpectedValueException('Invalid JSON.');
		}

		$this->data = (array) $data;

		return $this;
	}
1207500
protected static function overlayPath($path)
    {
        $path = str_replace('\\', '/', $path);
        $hasOverlay = false;
        if (strpos($path, self::$rootPath) !== 0) {
            // Path is not below root path, ignore it
            return $path;
        }

        $newPath = ltrim(substr($path, strlen(self::$rootPath)), '/');
        foreach (self::$overlayPaths as $overlay => $replace) {
            if (strpos($newPath, $overlay) === 0) {
                $newPath = $replace . substr($newPath, strlen($overlay));
                $hasOverlay = true;
                break;
            }
        }
        return $hasOverlay ? $newPath : $path;
    }
1215445
public static function chroot(string $path='/', bool $override = false) {

    	// this is now deprecated, will probably be removed in a future release
		trigger_error(
			'Usage of Polyfony\Filesystem is deprecated, require symfony/filesystem instead', 
			E_USER_DEPRECATED
		);

        // if chrooting is enabled in the configuration
        if(Config::get('filesystem', 'chroot') && !$override) {
            // if the path already has the proper (ch)root
            if(strpos($path, Config::get('filesystem', 'data_path')) === 0) {
                // remove the root, remove double dots
                $path = str_replace(array(Config::get('filesystem', 'data_path'), '..'), '', $path);
                // re-add the root
                return(Config::get('filesystem', 'data_path') . $path);
            }
            // the path doesn't start with the (ch)root
            else {
                // remove all double dots and add the root path
                return(Config::get('filesystem', 'data_path') . str_replace('..','',$path));
            }
        }
        // return the path (altered or not)
        return($path);

    }
312767
protected function createDir($path) {
        if (!is_dir($path)) {
            $this->log->info('Create directory %s', $path);

            $status = mkdir($path, 0775, true);

            if ($status === false) {
                throw new Exception(sprintf(
                    'Unable to create directory %s',
                    $path
                ), ExitApp::RUNTIME_ERROR);
            }
        }

        return $this;
    }
138698
public static function ls ($path, $fn = null)
	{
		if (!static::is_absolute($path)) {
			throw new \Exception('Supplied path is not absolute.');
		}

		if ($fn === null) {
			$fn = function ($entry) {
				return substr($entry, 0, 1) != '.';
			};
		}

		$entries = scandir($path);

		return V($entries)->select($fn);
	}
198983
public static function createFromPath(string $path, $context = null): self
    {
        $file_args = [$path, false];
        $mime_args = [$path, FILEINFO_MIME];
        if (null !== $context) {
            $file_args[] = $context;
            $mime_args[] = $context;
        }

        $content = @file_get_contents(...$file_args);
        if (false === $content) {
            throw new SyntaxError(sprintf('`%s` failed to open stream: No such file or directory', $path));
        }

        return new self(
            str_replace(' ', '', (new finfo(FILEINFO_MIME))->file(...$mime_args))
            .';base64,'.base64_encode($content)
        );
    }