Read a file from Splash Server

@param string $file File Identifier (Given by Splash Server)
@param string $md5  Local FileName

@return array|false $file       False if not found, else file contents array
510649
public function getFile($file = null, $md5 = null)
    {
        //====================================================================//
        // Stack Trace
        Splash::log()->trace();

        //====================================================================//
        // PHPUNIT Exception => Look First in Local FileSystem
        //====================================================================//
        if (defined('SPLASH_DEBUG') && !empty(SPLASH_DEBUG)) {
            $filePath = dirname(__DIR__)."/Resources/files/".$file;
            if (is_file($filePath)) {
                $file = $this->readFile($filePath, $md5);

                return is_array($file) ? $file : false;
            }
            $imgPath = dirname(__DIR__)."/Resources/img/".$file;
            if (is_file($imgPath)) {
                $file = $this->readFile($imgPath, $md5);

                return is_array($file) ? $file : false;
            }
        }

        //====================================================================//
        // Initiate Tasks parameters array
        $params = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
        $params->file = $file;
        $params->md5 = $md5;
        //====================================================================//
        // Add Task to Ws Task List
        Splash::ws()->addTask(SPL_F_GETFILE, $params, Splash::trans("MsgSchRemoteReadFile", (string) $file));

        //====================================================================//
        // Execute Task
        $response = Splash::ws()->call(SPL_S_FILE);

        //====================================================================//
        // Return First Task Result
        return Splash::ws()->getNextResult($response);
    }
119324
protected function get_file( $file ) {

		$path_parts = $this->parse_path( $file );

		if ( '' === $path_parts[0] ) {
			$file = $this->root;
			unset( $path_parts[0] );
		} else {
			$file = $this->cwd;
		}

		foreach ( $path_parts as $part ) {

			if ( '' === $part ) {
				continue;
			}

			if ( 'dir' !== $file->type || false === isset( $file->contents->$part ) ) {
				return false;
			}

			$file = $file->contents->$part;
		}

		return $file;
	}
1329562
public function read($file)
    {
        $fp = fopen($file, 'r+');

        $contents = '';

        while ($part = fread($fp, 1024)) {
            $contents .= $part;
        }

        if (null !== $fp) {
            fclose($fp);
        }

        return $contents;
    }
610163
private function read_file($file)
  {
    $handler = fopen($file, "r");
    $file_content = fread($handler, filesize($file));
    fclose($handler);

    return $file_content;
  }
19366
protected function _fileGetContents($file)
    {
        $result = false;
        if (!is_file($file)) {
            return false;
        }
        $f = @fopen($file, 'rb');
        if ($f) {
            if ($this->_options['file_locking']) @flock($f, LOCK_SH);
            $result = stream_get_contents($f);
            if ($this->_options['file_locking']) @flock($f, LOCK_UN);
            @fclose($f);
        }
        return $result;
    }
1182878
public function load_from_file($file)
    {
        $success = false;

        foreach ($this->resolve_paths($file) as $fpath) {
            if ($fpath && is_file($fpath) && is_readable($fpath)) {
                // use output buffering, we don't need any output here
                ob_start();
                include($fpath);
                ob_end_clean();

                if (is_array($config)) {
                    $this->merge($config);
                    $success = true;
                }
                // deprecated name of config variable
                if (is_array($rcmail_config)) {
                    $this->merge($rcmail_config);
                    $success = true;
                }
            }
        }

        return $success;
    }
1268402
private function getCache($file)
    {
        if (null === $this->cache) {
            return null;
        }

        $key = md5($file);

        // File already present
        if ($this->cache->has($key)) {
            list($mtime, $path) = unserialize($this->cache->get($key));

            if ($mtime === filemtime($file)) {
                return $path;
            }

            $delete = $this->directory.'/'.$path;
            if (file_exists($delete) && false === @unlink($delete)) {
                throw new \RuntimeException('Unable to remove file '.$delete);
            }
        }

        return null;
    }
1173529
private static function read($file, $force = false)
    {
        if($force === false && isset(self::$history[$file]))
        {
            return self::$history[$file];
        }

        $path = self::$configDirectory . $file . '.php';

        if(file_exists($path))
        {
            $contents = include $path;

            if(is_array($contents) || is_string($contents))
            {
                return self::$history[$file] = $contents;
            }

            return false;
        }

        return false;
    }
24315
protected function _read($file) {
		$text = file_get_contents($file);
		if (empty($text)) {
			return [];
		}
		$pieces = explode(NL, $text);
		return $pieces;
	}
933208
public final function loadFile($file) {
        $f = $this->getPath($file);
        if (is_file($f) && is_readable($f)) {
            return @file_get_contents($f);
        }

        return false;
    }
226112
public function read($file)
    {
        if (!file_exists($file)) {
            throw new \InvalidArgumentException('Failed to find Moodle config.php file, perhaps Moodle has not been installed yet');
        }

        // Must suppress as unreadable files emit PHP warning, but we handle it below.
        $contents = @file_get_contents($file);

        if ($contents === false) {
            throw new \RuntimeException('Failed to read from the Moodle config.php file');
        }

        return $contents;
    }
1179921
public static function readMo($file)
    {
        $f = file_get_contents($file);
        
        if (! is_string($f)) {
            throw new LocaleException('Could not open file: ' . $file);
        }
        
        $magic = bin2hex(substr($f, 0, 4));
        if ($magic === '950412de') { // Big endian
            $header = 'Nrev/NN/NO/NT/NS/NH';
            $format = 'N';
        } elseif ($magic === 'de120495') { // Little endian
            $header = 'Vrev/VN/VO/VT/VS/VH';
            $format = 'V';
        } else {
            throw new LocaleException('Not a valid MO file: incorrect magic number: ' . $magic);
        }
        $o = 4;
        
        $data = unpack($header, substr($f, $o, 24));
        $num = $data['N'];
        $oOffset = $data['O'];
        $tOffset = $data['T'];
        
        if ($num == 0) {
            return new Locale();
        }
        
        $format = $format . ($num * 2);
        
        $o = $oOffset;
        $oTable = unpack($format, substr($f, $o, 8 * $num));
        $o = $tOffset;
        $tTable = unpack($format, substr($f, $o, 8 * $num));
        
        $offsets = array();
        $n = $num * 2;
        $o = $oTable[2];
        $messages = array();
        for ($i = 1; $i <= $n; $i += 2) {
            $length = $oTable[$i];
            if ($length == 0) {
                $message = '';
                $o += 1;
            } else {
                $message = substr($f, $o, $length);
                $o += $length + 1;
                $hasNul = strpos($message, "\0");
                if ($hasNul !== false) {
                    $message = substr($message, $hasNul + 1); // gets plural
                }
            }
            $messages[$i] = $message;
        }
        $o = $tTable[2];
        $l = new Locale();
        for ($i = 1; $i <= $n; $i += 2) {
            $length = $tTable[$i];
            if ($length > 0) {
                $translation = substr($f, $o, $length);
                $o += $length + 1;
                if ($messages[$i] == '') {
                    $properties = explode("\n", $translation);
                    foreach ($properties as $property) {
                        list ($property, $value) = explode(':', $property, 2);
                        if (trim(strtolower($property)) == 'plural-forms') {
                            $l->pluralForms = $value;
                            break;
                        } elseif (trim(strtolower($property)) == 'language') {
                            $value = LanguageTag::parseTag($value);
                            $l->name = $value[0];
                            $l->region = $value[1];
                        }
                    }
                }
                if (strpos($translation, "\0") !== false) {
                    $translation = explode("\0", $translation);
                }
                $l->set($messages[$i], $translation);
            } else {
                $o += 1;
            }
        }
        return $l;
    }
800296
public static function get($file = false) {

        if ($file && self::isFile($file)) {

            return file_get_contents($file);
        }

        return false;
    }
621800
public static function includeFile($file)
    {
        $data               = static::$properties['data'];
        $templatePath       = static::$properties['templatePath'];
        $compilePath        = static::$properties['compilePath'];
        $compileCached      = static::$properties['compileCached'];
        $compileFileNameMd5 = static::$properties['compileFileNameMd5'];
        $compileFileSuffix  = static::$properties['compileFileSuffix'];
        $templateFile       = $templatePath . $file;

        if ( !file_exists($templateFile) )
        {
            throw new \InvalidArgumentException('included template file ' . $file . ' not found.');
        }

        $pathInfo = pathinfo($file);
        $filename = $pathInfo['filename'];

        if (!$compileFileNameMd5 && !file_exists($compilePath . $pathInfo['dirname']))
        {
            static::mkdir($compilePath . $pathInfo['dirname']);
        }

        $filenameMd5 = (($compileFileNameMd5) ? md5(md5($filename)) : $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $filename);
        $compileFile = $compilePath . $filenameMd5 . $compileFileSuffix;

        if ($compileCached)
        {
            if (!file_exists($compileFile) || (filemtime($templateFile) > filemtime($compileFile)))
            {
                $tpl = file_get_contents($templateFile);
                $tpl = static::parser($tpl);
                file_put_contents($compileFile, $tpl);
            }
        }
        else
        {
            $tpl = file_get_contents($templateFile);
            $tpl = static::parser($tpl);
            file_put_contents($compileFile, $tpl);
        }

        return $compileFile;
    }
911541
public static byte[] md5(File file) throws IOException {
		try (InputStream in = new FileInputStream(file)) {
			return md5(in);
		}
	}
1323535
public function read($file)
	{
		if (!file_exists($file) || (filesize($file) < 10))
		{
			throw new FileNotFoundException('No configuration file found and no installation code available.', 500);
		}

		require_once $file;

		if (!class_exists('\\JConfig'))
		{
			throw new UnsupportedFormatException('Invalid configuration file.', 500);
		}

		$config = new \JConfig;

		if (isset($config->tmp_path))
		{
			if (substr($config->tmp_path, strlen(PATH_ROOT)) == DS . 'tmp')
			{
				$config->tmp_path = PATH_APP . substr($config->tmp_path, strlen(PATH_ROOT));
			}
		}

		if (isset($config->log_path))
		{
			if (substr($config->log_path, strlen(PATH_ROOT)) == DS . 'logs')
			{
				$config->log_path = PATH_APP . substr($config->log_path, strlen(PATH_ROOT));
			}
		}

		return $config;
	}
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;
    }