public static function parseFile(string $filename, bool $resultAsObject = false)
    {
        if (!is_file($filename)) {
            throw new ParseException(sprintf('File "%s" does not exist.', $filename));
        }

        if (!is_readable($filename)) {
            throw new ParseException(sprintf('File "%s" cannot be read.', $filename));
        }

        try {
            $data = self::doParse(file_get_contents($filename), $resultAsObject);
        } catch (SyntaxErrorException $e) {
            $exception = new ParseException($e->getMessage());
            $exception->setParsedFile($filename);

            if ($token = $e->getToken()) {
                $exception->setParsedLine($token->getLine());
            }

            throw $exception;
        }

        return $data;
    }
public static function parseFile(string $filename, bool $resultAsObject = false)
    {
        if (!is_file($filename)) {
            throw new ParseException(sprintf('File "%s" does not exist.', $filename));
        }

        if (!is_readable($filename)) {
            throw new ParseException(sprintf('File "%s" cannot be read.', $filename));
        }

        try {
            $data = self::doParse(file_get_contents($filename), $resultAsObject);
        } catch (SyntaxErrorException $e) {
            $exception = new ParseException($e->getMessage());
            $exception->setParsedFile($filename);

            if ($token = $e->getToken()) {
                $exception->setParsedLine($token->getLine());
            }

            throw $exception;
        }

        return $data;
    }
public static function parseFile ( string $ filename , bool $ resultAsObject = false ) { if ( ! is_file ( $ filename ) ) { throw new ParseException ( sprintf ( 'File "%s" does not exist.' , $ filename ) ) ; } if ( ! is_readable ( $ filename ) ) { throw new ParseException ( sprintf ( 'File "%s" cannot be read.' , $ filename ) ) ; } try { $ data = self :: doParse ( file_get_contents ( $ filename ) , $ resultAsObject ) ; } catch ( SyntaxErrorException $ e ) { $ exception = new ParseException ( $ e -> getMessage ( ) ) ; $ exception -> setParsedFile ( $ filename ) ; if ( $ token = $ e -> getToken ( ) ) { $ exception -> setParsedLine ( $ token -> getLine ( ) ) ; } throw $ exception ; } return $ data ; }
Parses a TOML file into a PHP array.

Usage:
<code>
$array = Toml::parseFile('config.toml');
print_r($array);
</code>

@param string $input A string containing TOML
@param bool $resultAsObject (optional) Returns the result as an object

@return mixed The TOML converted to a PHP value

@throws ParseException If the TOML file is not valid
Parses a TOML file into a PHP array .