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;
    }
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;
    }
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 ; }
Parse a JSON file

@param string $file File path
@param bool $force If "true" and file is not readable ignore it, otherwise throw an exception. Defaults to
"false".

@return array Return content as an array

@throws Exception on error
Parse a JSON file