Get file as content.

@param string $file with content

@return string as content of the file

@throws Exception when file does not exist
11928
public function get($file)
    {
        $basepath = $this->config['basepath'];
        $suffix = $this->config['suffix'];
        $target = "$basepath/$file{$suffix}";

        if (!is_readable($target)) {
            throw new \Exception(t("No such file content: @FILENAME", ["@FILENAME" => $target]));
        }

        $filter  = $this->config['textfilter'];
        $content = file_get_contents($target);
        $content = $this->di->textFilter->doFilter($content, $filter);

        return $content;
    }
657936
public function load($file) {
		$this->_origin = $file;
		if(!is_null($file)) {
			if(file_exists($file)) {
				if (is_null($this->_name)) {
					$bits = explode('/', $file);
					$this->_name = preg_replace('~\.tmpl~', '', array_pop($bits));
				}
				$this->_contents = file_get_contents($file);
				$this->_dir = dirname($file);
			}
			else {
				throw new \InvalidArgumentException("file does not exist (". $file .")");
			}
		}
		return $this;
	}
108796
public function appendToFile($content)
    {
        $result = @fwrite($this->_file, $content);

        if ($result === false) {
            throw new Exception("I'm can not wrtite to file");
        }

        return $result;
    }
438959
public function fetch($file)
    {
        $templateFile = $this->findTemplateFile($file);

        if (empty($templateFile)) {
            throw new Exception("Template file does not exists: $file");            
        }

        extract($this->vars);
        ob_start();
        include $templateFile;
        $buffer = ob_get_contents();
        ob_end_clean();
        return $buffer;
    }
154295
public function getAction($file)
    {
        if (!is_dir($this->source_directory) || !isset($this->file_extension, $this->response_type)) {
            throw new Exception("Controller is not configured!");
        }
        $source_file = $this->source_directory . "/" . $file . "." . $this->file_extension;
        if (!is_readable($source_file)) {
            throw new Error404Exception;
        }
        $this->response->setHeader("Content-Type", $this->response_type);
        return $this->view->display($source_file);
    }
1182859
public static function fromFile(string $file) : DOMDocument
    {
        if (!is_file($file)) {
            throw new InvalidArgumentException(sprintf('Path "%s" is not a file', $file));
        }

        if (!is_readable($file)) {
            throw new InvalidArgumentException(sprintf('File "%s" is not readable', $file));
        }

        // libxml_disable_entity_loader(true) disables \DOMDocument::load() method
        // so we need to read the content and use \DOMDocument::loadXML()
        $xml = file_get_contents($file);
        if ($xml === false) {
            throw new RuntimeException(sprintf(
                'Contents of readable file "%s" could not be gotten',
                $file
            ));
        }

        if (trim($xml) === '') {
            throw new RuntimeException(sprintf('File "%s" does not have content', $file));
        }

        return static::fromString($xml);
    }
972050
protected function getFileContents($file, $line){
        if(!is_string($file) || !is_int($line)
            || !is_file($file) || !is_readable($file)
        ){
            return null;
        }

        $file       = new \SplFileObject($file, "r");
        $current    = 1;
        $contents   = [];
        $min        = $line - 3;
        $max        = $line + 3;

        foreach($file as $row){
            if($min <= $current && $current <= $max){
                $contents[$current] = $row;
            }

            $current++;
        }

        if(empty($contents)){
            return null;
        }

        return $contents;
    }
53263
protected static function getMaps($file)
    {
        $maps = json_decode(File::get($file), true);

        if (is_null($maps)) {
            throw new Exception('The existing mapping file contains invalid json string. Please fix the file then try again');
        }

        return $maps;
    }
650938
private function loadFile(string $file) : string
    {
        if (!file_exists($file)) {
            throw new \Exception($file . ' not found');
        }
        return (string)file_get_contents($file);
    }
146772
public function get($file)
    {
        $path = $this->getPath($file);

        if (! file_exists($path)) {
            throw new FileDoesNotExists;
        }

        return file_get_contents($path);
    }
800209
public function getFiles($file = null)
    {
        if ($file !== null) {
            $return = array();
            foreach ($this->_files as $name => $content) {
                if ($name === $file) {
                    $return[$file] = $this->_files[$name];
                }

                if ($content['name'] === $file) {
                    $return[$name] = $this->_files[$name];
                }
            }

            if (count($return) === 0) {
                require_once 'Zend/Validate/Exception.php';
                throw new Zend_Validate_Exception("The file '$file' was not found");
            }

            return $return;
        }

        return $this->_files;
    }
800296
public static function get($file = false) {

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

            return file_get_contents($file);
        }

        return false;
    }
229445
protected function getFileContents($file)
    {
        if ($file instanceof ModuleResource) {
            $path = $file->getPath();
        } else {
            $path = Director::baseFolder() . '/' . $file;
        }
        if (!file_exists($path)) {
            return null;
        }
        $content = file_get_contents($path);

        // Remove UTF-8 BOM
        if (substr($content, 0, 3) === pack("CCC", 0xef, 0xbb, 0xbf)) {
            $content = substr($content, 3);
        }

        return $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;
    }
1008679
protected static function _parse($file) {
		$header = '';
		$content = '';

		if (!$stream = fopen($file, 'r')) {
			throw new Exception('Failed to open file.');
		}

		$isHeader = false;

		while (!feof($stream)) {
			$line = rtrim(fgets($stream));

			if ($line === '---') {
				$isHeader = !$isHeader;
				continue;
			}
			if ($isHeader) {
				$header .= $line . "\n";
			} else {
				$content .= $line . "\n";
			}
		}
		if ($header) {
			$info = Yaml::parse($header);
		} else {
			$info = [];
		}

		fclose($stream);
		return [$info, $content];
	}
754511
private function FileGetContents($file) {
    $fileObj = new SplFileObject($file, 'r');
    while (!$fileObj->flock(LOCK_EX)) {
      usleep(1);
    }
    $str = $fileObj->fread($fileObj->getSize());
    $fileObj->flock(LOCK_UN);
    return $str;
  }
1275273
public static function getMime($file)
    {
        $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime = finfo_file($fileInfo, $file);

        return empty($mime) ? : $mime;
    }