Get the contents of a file.

@param  string $filepath The file path.
@return string contents of the file.
@throws \moodle_exception If the file cannot be opened.
968570
protected function get_file_content(string $filepath) : String {
        $content = file_get_contents($filepath);
        if ($content === false) {
            throw new \moodle_exception('cannotopenfile', 'error', '', $filepath);
        }
        return $content;
    }
219607
private function getRealFilePath( string $filePath ) : string
	{
		$realFilePath = getcwd() . DIRECTORY_SEPARATOR . ltrim( $filePath, '/' );
		$outputDir    = dirname( $realFilePath );
		if ( !@mkdir( $outputDir, 0777, true ) && !is_dir( $outputDir ) )
		{
			throw new InvalidArgumentException( 'Invalid file path: ' . $realFilePath );
		}

		return $realFilePath;
	}
425772
public function scan($filepath)
    {
        $proc = new Process(sprintf('%s %s --Output=XML --Full', $this->path, $filepath));
        $proc->run();

        if (!$proc->isSuccessful()) {
            throw new \RuntimeException($proc->getErrorOutput());
        }

        $result = $proc->getOutput();

        //parse structure to turn into raw php array
        $xml = simplexml_load_string($result);
        $data = array();
        $data['version'] = (string) $xml['version'];

        foreach ($xml->File->track as $track) {
            $trackType = strtolower($track['type']);
            $trackId = isset($track['streamid']) ? $track['streamid'] : 1;
            $trackId = (string)$trackId;

            $trackData = [];
            foreach ($track as $rawKey => $rawVal) {
                $key = strtolower($rawKey);
                $val = (string)$rawVal;

                # This sometimes doesn't match streamid, so let's ignore it
                if ($key == 'stream_identifier') { continue; }

                if (!array_key_exists($key, $trackData)) {
                    $trackData[$key] = array($val);
                } elseif (!in_array($val, $trackData[$key])) {
                    $trackData[$key][] = $val;
                }
            }

            if ($trackType == 'general') {
                $data['file']['general'] = $trackData;
            } else {
                $data['file'][$trackType][$trackId] = $trackData;
            }
        }

        return $data;
    }
1276972
protected function getFileAsset($filePath)
    {
        $file = new \SplFileInfo($filePath);

        if (!$file->isReadable() || $file->isDir()) {
            return null;
        }

        $filePath = $file->getRealPath();

        return new FileAsset($filePath);
    }
338654
public function getFilePath($filePath)
    {
        $composerFiles = [];
        foreach ($this->alias as $name => $path) {
            $composerFiles[] = $path . '/' . $filePath;
        }

        return FileHelper::getFirstExistingFileArray($composerFiles);
    }
1073012
public function get_file($filepath, $file = '') {
        list($bucket, $uri) = $this->explode_path($filepath);
        $path = $this->prepare_file($file);
        try {
            $this->s->getObject($bucket, $uri, $path);
        } catch (S3Exception $e) {
            throw new moodle_exception(
                'errorwhilecommunicatingwith',
                'repository',
                '',
                $this->get_name(),
                $e->getMessage()
            );
        }
        return array('path' => $path);
    }
465003
protected function readFile(string $filePath): string
    {
        /**
         * read bin
         */
        $handle = fopen($filePath, 'rb');
        $stream = fread($handle, $this->maxByteCacheLen);
        fclose($handle);
        return $stream;
    }
51656
public function readFileFunc($filepath)
    {
        /** @var UniformResourceLocator $locator */
        $locator = $this->grav['locator'];

        if ($locator->isStream($filepath)) {
            $filepath = $locator->findResource($filepath);
        }

        if ($filepath && file_exists($filepath)) {
            return file_get_contents($filepath);
        }

        return false;
    }
753188
public function getFilePath( string$filePath, string$path=null ):string
	{
		if( !isset($this->basePath) )
			{ throw new \Exception('BasePath musbe set.'); }

		if( !strlen($filePath) )
			{ throw new \Exception('FilePath cannot be empty.'); }

		if( '/'===$filePath{0} ){
			if( is_null($path) )
				{ return $filePath; }
			else
				{ return $this->basePath.$filePath; }
		}else{
			if( !strlen($path) )
				{ return $this->basePath.'/'.$filePath; }
			elseif( '/'===substr($path,-1) )
				{ return $path.$filePath; }
			else
				{ return $path.'/'.$filePath; }
		}

	}
334766
public function save($filepath = '')
    {
        $string = $this->innerHtml();
        if ($filepath !== '') {
            file_put_contents($filepath, $string, LOCK_EX);
        }

        return $string;
    }
172754
public function setFilePath($filePath)
    {
        $this->isURI = false;
        $this->filePath = trim($filePath);

        $this->content = null;
        return $this;
    }
916516
protected function openFile($filePath)
    {
        if (empty($filePath)) {
            throw new \Exception('Input file not defined.');
        } elseif (!file_exists($filePath)) {
            throw new \Exception("File does not exist: {$filePath}");
        }

        $handle = @fopen($filePath, 'r');
        if (false === $handle) {
            throw new \Exception("Unable to open file for reading: {$filePath}");
        }

        return $handle;
    }
505098
protected function getFilesStatus(string $filepath) : bool
    {
        $status     = false;
        $path       = explode('/', $filepath);

        if (empty($path[0])) {
            // Internal Path
            $site           = $path[1];
            $acceptables    = ['css', 'CSS'];
            $filename       = $path[count($path) - 1];

            // check if style file has correct extension
            $nameParts = explode('.', $filename);
            if (!in_array($nameParts[count($nameParts) - 1], $acceptables)) {
                return false;
            }

            // Getting the subfolder(s)
            $subfolders     = '';
            for ($i = 2; $i <= count($path) - 2; $i++) {
                $subfolders .= $path[$i] . '/';
            }

            $fullPath = $_SERVER['DOCUMENT_ROOT'] . '/../module/MelisSites/' . $site . '/public/' . $subfolders . $filename;
            if (is_file($fullPath) && file_exists($fullPath)) {
                return true;
            }

        } else {
            // External Path
            if (filter_var($filepath, FILTER_VALIDATE_URL)) {
                $header_response = get_headers($filepath, 1);
                if (strpos($header_response[0], "200") !== false) {
                    // File exists
                    return true;
                }
            }
        }

        return $status;
    }
1182988
public function fileGetContents($filePath)
    {
        if ($this->fileExists($filePath) == false) {
            throw new FileSystemException('File '.$filePath.' was not found');
        }
        return file_get_contents($filePath);
    }
415811
public function parseFile($filePath, array $vars = [])
    {
        if (is_file($filePath)) {
            return $this->parseString(file_get_contents($filePath), $vars);
        }

        // Try to find from filePaths
        if (count($this->filePaths)) {
            foreach ($this->filePaths as $fileDirectory) {
                if (is_file($fileDirectory . $filePath)) {
                    return $this->parseString(file_get_contents($fileDirectory . $filePath), $vars);
                    break;
                }
            }
        }

        return null;
    }
293806
function fileFetchContents( $filePath )
    {
        eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileFetchContents( '$filePath' )", __METHOD__ );

        eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
        $rslt = is_readable( $filePath ) ? file_get_contents( $filePath ) : false;
        eZDebug::accumulatorStop( 'dbfile' );

        return $rslt;
    }
1163654
public function get($filename, $includePath = false, $streamContext = null)
    {
        return file_get_contents($filename, $includePath, $streamContext);
    }