Get config from file cache
@param string $file
@return array|false Return array config when file existed and readable, otherwise return false
@throws Exception\RuntimeException
189106
public function getConfig($file = null)
    {
        $file = !empty($file) ? $file : $this->fileCache;
        if (file_exists($file)) {
            if (!is_readable($file)) {
                throw new Exception\RuntimeException(sprintf('"%s" cannot read', $file));
            }
            return require $file;
        }
        return false;
    }
357662
public function check(File $file)
    {
        if ($file->getUid() !== $this->uid) {
            throw new \Exception('This CachedFile is not for uid ['.$file->getUid().']');
        }

        return $this->hash === $this->hashFile($file);
    }
616419
public static function get(
        $file
    ) {
        if (is_string($file)) {
            $file = new \SplFileInfo($file);
        }

        $extension = mb_strtolower($file->getExtension());
        if ('' === $extension) {
            return static::MIME_TYPE_IF_UNKNOWN;
        }

        if (array_key_exists($extension, static::$mimeTypes)) {
            return static::$mimeTypes[$extension];
        }

        if (function_exists('finfo_open') && $file->isFile()) {
            $path = $file->getPath();

            $fileInfo = finfo_open(FILEINFO_MIME);
            $mimeType = finfo_file($fileInfo, $path);
            finfo_close($fileInfo);

            return $mimeType;
        }

        return static::MIME_TYPE_IF_UNKNOWN;
    }
802533
protected function getProperties($file)
    {
        $properties = array();

        if (false === $lines = @file($file)) {
            throw new Exception(sprintf('Unable to parse contents of "%s".', $file));
        }

        foreach ($lines as $line) {
            $line = trim($line);

            if ('' == $line || in_array($line[0], array('#', ';'))) {
                continue;
            }

            $pos = strpos($line, '=');
            $properties[trim(substr($line, 0, $pos))] = trim(substr($line, $pos + 1));
        }

        return $properties;
    }
1092901
public function write($file)
    {
        $content = '';
        if ($this->section) {
            $content .= "[{$this->section}]\n";
        }

        foreach ($this->data as $key => $value) {
            if (is_array($value)) {
                $content .= $this->createArrayLines($value, $key);
                continue;
            }

            $content .= $this->createPropertyLine($key, $value);
        }

        if (file_put_contents($file, $content) === false) {
            throw new RuntimeException('Failed to write config file: ' . $file);
        }

        return $this;
    }
326706
public function load($file)
    {
        if (!is_readable($file)) {
            throw new ConfigurationException(sprintf("Cannot read configuration file: %s", $file));
        }

        try {
            $config = Yaml::parse(file_get_contents($file));
        } catch (ParseException $e) {
            throw new ConfigurationException('Error in configuration file: %s', $e->getMessage());
        }

        return $this->loadFromArray($config);
    }
852008
public static function get(String $file) : stdClass
    {
        $file = self::rpath($file);

        if( ! is_file($file) )
        {
            throw new Exception\FileNotFoundException(NULL, $file);
        }

        return (object)
        [
            'basename'   => self::pathInfo($file, 'basename'),
            'size'       => filesize($file),
            'date'       => filemtime($file),
            'readable'   => is_readable($file),
            'writable'   => is_writable($file),
            'executable' => is_executable($file),
            'permission' => fileperms($file)
        ];
    }
903058
public function loadConfig(string $file): self
    {
        if (file_exists($file) === false) {
            throw new \RuntimeException('No such config file.');
        }
        $data = json_decode(file_get_contents($file), true);
        if ($data === null) {
            throw new \RuntimeException('Invalid config file.');
        }
        return $this->setConfigs($data);
    }
873456
protected function _loadConfig($file) {
        $suffix = pathinfo($file, PATHINFO_EXTENSION);
        $suffix = ($suffix === 'dist') ?
                    pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION) : $suffix;
        if ($suffix == 'ini') {
            $config = Garp_Config_Ini::getCached($file, $this->getEnvironment())->toArray();
        } else {
            $config = parent::_loadConfig($file);
        }
        return $config;
    }
1359474
protected function loadConfig($file)
    {
        $file = $this->vendorDir . '/' . $file;
        if (!is_file($file)) {
            return [];
        }
        $this->opcacheInvalidate($file);
        return require($file);
    }
987100
private function load(string $file): array
    {
        $file = basename($file);
        $fileName = realpath($this->configDirectory . '/' . $file);

        try {
            $json = @file_get_contents($fileName);

            if ($json !== false) {
                $configuration = json_decode($json, true);

                if (!empty($configuration)) {
                    if (!empty($configuration['@extends'])) {
                        $extends = $configuration['@extends'];
                        unset($configuration['@extends']);

                        $configuration = array_replace_recursive($this->load($extends), $configuration);
                    }
                } else {
                    throw new BerliozException(sprintf('Not a valid JSON configuration file "%s"', $file));
                }
            } else {
                throw new BerliozException(sprintf('Unable to load configuration file "%s"', $file));
            }
        } catch (BerliozException $e) {
            throw $e;
        } catch (\Exception $e) {
            throw new BerliozException(sprintf('Unable to load configuration file "%s"', $file));
        }

        return $configuration;
    }
453690
public function withYamlConfig($file)
    {
        if (!class_exists(Yaml::class)) {
            throw new RuntimeException("You need to install 'symfony/yaml' to use this feature");
        }

        if (!is_readable($file)) {
            throw new RuntimeException("The configuration file is not readable");
        }

        $config = Yaml::parse(file_get_contents($file));
        if (!is_array($config)) {
            throw new RuntimeException("The configuration is not valid");
        }

        $this->withConfig($config);

        return $this;
    }
1165260
public function load_config_file($file)
    {
        if (!is_readable($file)) {
            return;
        }

        include $file;

        // read comments from config file
        if (function_exists('token_get_all')) {
            $tokens    = token_get_all(file_get_contents($file));
            $in_config = false;
            $buffer    = '';

            for ($i = 0; $i < count($tokens); $i++) {
                $token = $tokens[$i];
                if ($token[0] == T_VARIABLE && ($token[1] == '$config' || $token[1] == '$rcmail_config')) {
                    $in_config = true;
                    if ($buffer && $tokens[$i+1] == '[' && $tokens[$i+2][0] == T_CONSTANT_ENCAPSED_STRING) {
                        $propname = trim($tokens[$i+2][1], "'\"");
                        $this->comments[$propname] = $buffer;
                        $buffer = '';
                        $i += 3;
                    }
                }
                else if ($in_config && $token[0] == T_COMMENT) {
                    $buffer .= strtr($token[1], array('\n' => "\n"));
                }
            }
        }

        // deprecated name of config variable
        if (is_array($rcmail_config)) {
            return $rcmail_config;
        }

        return $config;
    }
44571
protected function getConfig($file = null)
    {
        // Config
        $appConfig = $this->getServiceLocator()->get('Config');

        if (!isset($appConfig['sphinxsearch'])) {
            throw new \InvalidArgumentException('Config not found with name: "sphinxsearch"');
        } else {
            $config = new Config($appConfig['sphinxsearch'], true); // defaults
            if (!is_null($file)) {
                $fileConfig = Factory::fromFile($file, true);
                if (!isset($fileConfig['sphinxsearch'])) {
                    throw new \InvalidArgumentException('Config not found with name: "sphinxsearch"');
                }
                $config->merge($fileConfig['sphinxsearch']);
            }
        }

        return $config;
    }
334095
public function load($file = '@root/.env')
    {
        $this->_file = $file;

        $file = $this->alias->resolve($file);
        $parsed_file = $file . '.php';
        if (is_file($parsed_file)) {
            /** @noinspection PhpIncludeInspection */
            $env = require $parsed_file;
        } elseif (is_file($file)) {
            $lines = file($file, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
            if ($lines === false) {
                throw new RuntimeException(['read `:file` failed', 'file' => $file]);
            }
            $env = $this->parse($lines);
        } else {
            throw new FileNotFoundException(['.env file is not found: :file', 'file' => $file]);
        }

        /** @noinspection AdditionOperationOnArraysInspection */
        $this->_env += $env;

        if ($this->_toEnv) {
            /** @noinspection AdditionOperationOnArraysInspection */
            $_ENV += $env;
        }

        return $this;
    }
395466
public function loadFile($file)
    {
        if (!is_file($file)) {
            throw new \RuntimeException(sprintf('File: %s not found.', $file));
        }

        $this->body = function () use ($file) {
            return file_get_contents($file);
        };

        $this->setFilename(pathinfo($file, PATHINFO_BASENAME));

        return $this;
    }
118733
public static function read($file, $force = false) {
        if (!is_readable($file)) {
            if ($force === true) {
                return [];
            } else {
                throw new Exception(sprintf(
                    'Unable to read file "%s"',
                    $file
                ), ExitApp::RUNTIME_ERROR);
            }
        }

        $fileContent = file_get_contents($file);

        if ($fileContent === false) {
            throw new Exception(sprintf(
                'Unable to read file "%s"',
                $file
            ), ExitApp::RUNTIME_ERROR);
        }

        $result = json_decode(
            trim($fileContent),
            true
        );

        if ($result === false) {
            throw new Exception(sprintf(
                'File "%s" contains invalid JSON data.',
                ExitApp::RUNTIME_ERROR
            ));
        }

        return $result;
    }