Output the contents of an entire file

@param   string  $path
@param   string  $format
@return  string
493664
public static function file($path, $format = '')
	{
		if ($format === '')
		{
			$format = self::getExtension($path);
		}
		$text = file_get_contents($path);
		return self::output($text, $format);
	}
953343
public function format($format)
    {
        $function = $this->localFormatFunction ?: static::$formatFunction;

        if (!$function) {
            return $this->rawFormat($format);
        }

        if (is_string($function) && method_exists($this, $function)) {
            $function = [$this, $function];
        }

        return $function(...func_get_args());
    }
300168
public function getContent($path)
    {
        /* @var $response \Guzzle\Http\Message\Response */
        $response = $this->getBrowser()->get($path)->send();
        if ($response->isError()) {
            throw new \RuntimeException('Failed to query the server '.$this->host);
        }
        if ($response->getStatusCode() !== 200 || !($html = $response->getBody(true))) {
            return;
        }
        $html = iconv('windows-1251', 'utf-8', $html);

        // clean content
        $config = [
            'output-xhtml' => true,
            'indent' => true,
            'indent-spaces' => 0,
            'fix-backslash' => true,
            'hide-comments' => true,
            'drop-empty-paras' => true,
            'wrap' => false,
        ];
        $tidy = new \tidy();
        $tidy->parseString($html, $config, 'utf8');
        $tidy->cleanRepair();
        $html = $tidy->root()->value;
        // ignore blocks
        $html = preg_replace('/<noembed>.*?<\/noembed>/is', '', $html);
        $html = preg_replace('/<noindex>.*?<\/noindex>/is', '', $html);
        // remove noembed
        return $html;
    }
879134
public function dumpFile($path)
    {
        $path = $this->resolve($path);

        return $this->dump($this->getFileContents($path), $path);
    }
183545
public function in($format = '')
    {
        if (empty($format)) {
            $line = fgets(STDIN);
        } else {
            $line = fscanf(STDIN, $format . PHP_EOL, $line);
        }

        return trim($line);
    }
895490
public static function output($path, $length = 102400, $delay = 0)
    {
        if (is_readable($path) === false) {
            return false;
        }

        $buffer = ob_get_level() !== 0;

        $handle = fopen($path, 'rb');

        $length = is_int($length) && $length > 0 ? $length : 102400;

        while (false === feof($handle)) {
            echo fread($handle, $length);

            if ($delay > 0) {
                usleep($delay);
            }

            if ($buffer) {
                ob_flush();
            }

            flush();
        }
    }
1171972
public static function loadAllFromPath($path, $format, $package = null)
    {
        $config = Ioc::getConfig();

        $locale  = $config['language.locale'] ?: 'en-GB';
        $default = $config['language.default'] ?: 'en-GB';
        $locale  = LanguageNormalize::toLanguageTag($locale);
        $default = LanguageNormalize::toLanguageTag($default);

        $localePath = $path . '/' . $locale;

        $files = [];

        if (is_dir($localePath)) {
            $files = array_merge($files, (array) Folder::files($localePath, false, Folder::PATH_BASENAME));
        }

        $defaultPath = $path . '/' . $default;

        if (is_dir($defaultPath)) {
            $files = array_merge($files, (array) Folder::files($defaultPath, false, Folder::PATH_BASENAME));
        }

        foreach ($files as $file) {
            $ext = File::getExtension($file);

            if (strcasecmp($ext, $format) !== 0) {
                continue;
            }

            static::loadFile(File::stripExtension($file), strtolower($format), $package);
        }
    }
1083976
public static function create($path, $format)
    {
        switch ($format) {
            case IMAGETYPE_JPEG:
                $result = imagecreatefromjpeg($path);
                break;
            case IMAGETYPE_PNG:
                $result = imagecreatefrompng($path);
                break;
            case IMAGETYPE_GIF:
                $result = imagecreatefromgif($path);
                break;
        }

        if (!$result) {
            throw new \Exception("Failing to create image (" . $path . ")");
        }

        return $result;
    }
178947
protected function sprintf(string $format, ...$args)
    {
        return $this->output->write(sprintf($format, ...$args), false);
    }
1374439
public function output($data, $format = null)
    {
        $contentType = $this->outputContentType($format);

        try {
            $content = $this->serializeData($data, $contentType);
        } catch (\UnexpectedValueException $e) {
            if (!isset($format) && isset($this->defaultFormat) && $this->defaultFormat !== $contentType) {
                $this->output($data, $this->defaultFormat); // Try default format instead
                return;
            }
            
            throw $e;
        }

        $this->getResponse()->getBody()->write($content);
    }
814168
public function toString($format = null)
    {
        if ($format) {
            $this->dom->formatOutput = true;
        }
        return $this->dom->saveXML();
    }
620180
public function read(string $format = null) : string
    {
        $input = array_shift($this->stack);
        if (isset($format, $input)) {
            $input = sprintf($format, $input);
        }
        return $input ?? '';
    }
332233
public static function loadFile($file, $format = null)
    {
        if (!isset($format)) {
            $ext = pathinfo($file, PATHINFO_EXTENSION);
            $format = ArrayHelper::fetch(self::$FORMATS, $ext);
            if (!isset($format)) {
                throw new \InvalidArgumentException("Cannot infer format from file '{$file}'");
            }
        }
        if ($format == 'json') {
            return json_decode(file_get_contents($file), true);
        } elseif ($format == 'yaml') {
            return Yaml::parse(file_get_contents($file));
        } elseif ($format == 'php') {
            return require($file);
        } else {
            throw new \InvalidArgumentException("Invalid format '{$format}'");
        }
    }
882118
public static function dump( $var, $format = 'html', $back = 0, $options = NULL, $return = FALSE, $max_depth = 6 )
    {
        list( $file, $line ) = self::caller( $back );

        if ( !$options ){
            $options = array();
        }
        $default_options = array(
                'title' => 'system dump',
                'font_size' => 11,
                'max_string_length' => self::DUMP_MAX_LENGTH,
                'type' => 'textarea',
            );
        $options = array_merge( $default_options, $options );

        $title             = $options['title'];
        $font_size         = $options['font_size'];
        $max_string_length = $options['max_string_length'];
        $type              = $options['type'];

        $lines = array();
        $recursion = array();
        self::_dump( '-', $var, 0, $max_string_length, $lines, $max_depth, $recursion );

        switch( $format )
        {
        case "html":
            switch( $type ){
            case 'div':
                $output  = "<div style=\"font-size:12px; margin: 2px\"> $title:" . implode('',$lines) . " @$file($line)</div>";
                break;
            case 'textarea':
            default:
                $output  = "<h3 style=\"font-size:12px; margin: 0; color:black; background-color:white; text-align: left\"> $title @$file($line)</h3>";
                $output .= "<textarea rows=14 style=\"width:100%; font-size:{$font_size}px; margin: 0; color:black; background-color:white; border: 1px solid silver;\">";
                $output .= implode(PHP_EOL,$lines);
                $output .= "</textarea>";
                break;
            }
            break;
        case "shell":
        default:
            $output  = "$title @$file($line)" . PHP_EOL;
            $output .= implode(PHP_EOL,$lines) . PHP_EOL;
            break;
        }

        if ( $return ){
            return $output;
        }
        else{
            echo $output;
            return null;
        }
    }
82703
public static function section($path, $start = 0, $end = 0, $undent = false)
	{
		$format = self::getExtension($path);
		$text   = file_get_contents($path);
		if ($start !== 0 || $end !== 0)
		{
			$text = self::lines($text, $start, $end);
			if ($undent)
			{
				$text = self::undent($text);
			}
		}
		return self::output($text, $format);
	}
577920
static function GetContents($path)
    {
        if (!self::Exists($path))
            throw new Exceptions\PathNotFoundException("File $path doesn't exist");
        
        if (!self::IsReadable($path))
            throw new Exceptions\PathNoAccessException("File $path cannot be read");
        
        return file_get_contents($path);
    }
1279696
public function fileGetContents($path)
    {
        if (! $this->isFile($path))
            return false;
        return $this->at($path)->content;
    }