Read a script excerpt

@param string $path
@param int    $init
@param int    $end
@param bool   $lines
@throws \Inphinit\Experimental\Exception
@return string
544698
public static function portion($path, $init = 0, $end = 1024, $lines = false)
    {
        self::fullpath($path);

        if ($lines !== true) {
            return file_get_contents($path, false, null, $init, $end);
        }

        $i = 1;
        $output = '';

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

        while (false === feof($handle) && $i <= $end) {
            $data = fgets($handle);

            if ($i >= $init) {
                $output .= $data;
            }

            ++$i;
        }

        fclose($handle);

        return $output;
    }
907515
public static function getViewContent($path) {
        if ($path === false) {
            throw new \Exception('The view file is not specified. Probably the correct path to the file was not found. Make sure that all paths are specified correctly, the files exists and is available.');
        }

        ob_start();

        require($path);

        $result = ob_get_contents();

        ob_end_clean();

        return $result;
    }
126593
public function file($path)
    {
        try {
            $contents = $this->filesystem->read($this->localPath."/{$path}");

            return preg_split("/\r\n|\n|\r/", $contents);
        } catch (Flysystem\FileNotFoundException $e) {
            throw new CompilerException($e->getMessage(), null, $e->getCode(), $e);
        }
    }
870067
public String getFileContents(String path) throws Exception {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        Resources.copy(Pages.class.getResource(path), outputStream);
        return new String(outputStream.toByteArray(), "UTF-8");
    }
1278137
public function getContents($initialIdent = 4, $trimFirstAndLastLineBreak = true)
    {
        $file      = explode(PHP_EOL, file_get_contents($this->getFileName()));
        $startLine = $this->getStartLine();
        $endLine   = $this->getEndLine()-1;
        $contents  = PHP_EOL;
        $subStrStart = false;

        while ($startLine<$endLine) {
            $line = $file[$startLine];

            if (!$subStrStart) {
                $numberOfWhiteSpace = strspn($line, ' ');
                $subStrStart        = $numberOfWhiteSpace - $initialIdent;
            }

            $contents .= substr(rtrim($line), $subStrStart) . PHP_EOL;

            $startLine++;
        }

        if ($trimFirstAndLastLineBreak) {
            $contents = ltrim(rtrim($contents, PHP_EOL), PHP_EOL);
        }

        return $contents;
    }
1369037
public function reads( $path )
	{
		try {
			$content = $this->fs->get( $path );
		} catch( \Exception $e ) {
			throw new Exception( $e->getMessage(), 0, $e );
		}

		if( ( $stream = tmpfile() ) === false ) {
			throw new Exception( 'Couldn\'t create temporary file' );
		}

		if( fwrite( $stream, $content ) === false ) {
			throw new Exception( 'Couldn\'t write to temporary file' );
		}

		if( rewind( $stream ) === false ) {
			throw new Exception( 'Couldn\'t rewind temporary file' );
		}

		return $stream;
	}
818762
public static function init($path, $url = '/')
  {
    self::$path = rtrim(realpath($path), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    self::$url = $url;
    self::$router = new Router();

    self::$page->onInit();
    self::$page->onPost();
    self::$page->beforeRender();
    print self::$page->render();
    self::$page->afterRender();
  }
179892
public function get($path)
    {
        $localPath = $this->createUri($path);
        if (!file_exists($localPath)) {
            return null;
        } elseif (!is_readable($localPath)) {
            throw new Exception\OperationFailureException('File reading error.');
        } else {
            return new FileDescriptor($localPath, filesize($localPath));
        }
    }
94350
public function execute($path = null)
    {
        $content = '';

        // loop files
        foreach ($this->data as $source => $js) {
            /*
             * Combine js: separating the scripts by a ;
             * I'm also adding a newline: it will be eaten when whitespace is
             * stripped, but we need to make sure we're not just appending
             * a new script right after a previous script that ended with a
             * singe-line comment on the last line (in which case it would also
             * be seen as part of that comment)
             */
            $content .= $js."\n;";
        }

        /*
         * Let's first take out strings, comments and regular expressions.
         * All of these can contain JS code-like characters, and we should make
         * sure any further magic ignores anything inside of these.
         *
         * Consider this example, where we should not strip any whitespace:
         * var str = "a   test";
         *
         * Comments will be removed altogether, strings and regular expressions
         * will be replaced by placeholder text, which we'll restore later.
         */
        $this->extractStrings('\'"`');
        $this->stripComments();
        $this->extractRegex();
        $content = $this->replace($content);

        $content = $this->propertyNotation($content);
        $content = $this->shortenBools($content);
        $content = $this->stripWhitespace($content);

        /*
         * Earlier, we extracted strings & regular expressions and replaced them
         * with placeholder text. This will restore them.
         */
        $content = $this->restoreExtractedData($content);

        return $content;
    }
696213
public function readBetween(int $start, int $end) : string
    {
        return implode("\n", $this->readLinesBetween($start, $end));
    }
1186140
public function import(array $path,$exts=null){
        $exts = $exts?:$this->path_autoext;
        $ext = '*.{inc.php,fuc.php';
        if($this->sapi=='cli') {
            $ext .= ',cli.php';
            is_string($exts) and $ext .= ','.$exts.'.php';
        }
        else {
            if(is_string($exts)){
                $ext .= ','.$exts.'.php';
            }
            /*
            $host = Request::driver()->host;
            if($host && is_array($exts) && isset($exts[$host])) {
                $ext .= ','.$exts[$host].'.php';
            }
            else if(is_string($exts)){
                $ext .= ','.$exts.'.php';
            }
            */
        }
        $config = [];
        $ext .='}';
        $auto = [];
        foreach ($path as $val) {
            $tmp = glob($val . $ext,GLOB_BRACE);
            $tmp and $auto = array_merge($auto,$tmp);
        }
        foreach ($auto as $v) {
            $conf = include $v;
            is_array($conf) and $config=array_merge($config,$conf);
        }
        $this->config = array_merge($this->config,$config);
    }
1104409
public static function loadDotFile($path)
    {
        $file = file_get_contents($path);
        if ($file === false) {
            return null;
        }

        $file = str_replace("\r", "\n", $file);      // Turn CR into LF
        $file = str_replace("\n\n", "\n", $file);   // Turn LFLF into LF
        $lines = explode("\n", $file);

        $data = [];

        $lineCount = count($lines);

        for ($i = 0; $i < $lineCount; $i++) {
            $line = trim($lines[$i]);
            if (strlen($line) === 0) {
                continue;
            }

            $split = explode('=', $line, 2);
            if (count($split) < 2) {
                throw new Exception\ConfigurationException("Invalid data in .bitrank file on line $i. ($line)");
            }

            $key = $split[0];
            $value = $split[1];

            $data[$key] = $value;
        }

        return $data;
    }
203958
protected function readLine($file, $lines = 50)
    {
        if (is_file($file) === false) {
            $this->error('tail: cannot open ‘'.$file.'’ for reading: No such file or directory');

            return;
        }

        $fp = fopen($file, 'r');
        $i = 1;
        $result = [];
        while (! feof($fp)) {
            if ($i > $lines) {
                break;
            }
            $content = fgets($fp);
            $result[] = $content;
            $i++;
        }
        fclose($fp);

        $this->line(implode('', $result));
    }
455890
public void init(String path, String charset) throws IOException {
		BufferedReader reader = FileUtil.getReader(path, charset);
		try {
			String line;
			while(true) {
				line = reader.readLine();
				if(line == null) {
					break;
				}
				this.add(line);
			}
		}finally {
			IoUtil.close(reader);
		}
	}
14858
private function needsInitialNewline($path)
    {
        $result = false;
        if (! file_exists($path)) {
            return $result;
        }
        $fh = fopen($path, 'r');
        if ($fh === false) {
            return $result;
        }
        if (fseek($fh, -1, SEEK_END) === 0) {
            $lastChar = fgetc($fh);
            if ($lastChar !== "\n" && $lastChar !== "\r") {
                $result = true;
            }
        }
        fclose($fh);
        return $result;
    }
173169
private void readData(StringBuilder powerShellOutput) throws IOException {
        String line;
        while (null != (line = this.reader.readLine())) {

            //In the case of script mode it finish when the last line is read
            if (this.scriptMode) {
                if (line.equals(PowerShell.END_SCRIPT_STRING)) {
                    break;
                }
            }

            powerShellOutput.append(line).append(CRLF);

            //When not in script mode, it exits when the command is finished
            if (!this.scriptMode) {
                try {
                    if (this.closed || !canContinueReading()) {
                        break;
                    }
                } catch (InterruptedException ex) {
                    Logger.getLogger(PowerShellCommandProcessor.class.getName()).log(Level.SEVERE, "Error executing command and reading result", ex);
                }
            }
        }
    }
62792
public static function readFile($dir, $path)
    {
        if (!pathinfo($path, PATHINFO_EXTENSION)) {
            $path .= '.json';
        }

        if ($path[0] != '/') {
            $path = $dir.DIRECTORY_SEPARATOR.$path;
        }

        if (!is_file($path) || !is_readable($path)) {
            throw new \RuntimeException(sprintf('Unable to load configuration from "%s".', $path));
        }

        $data = json_decode(file_get_contents($path), true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \RuntimeException('Configuration JSON format is invalid.');
        }

        if (isset($data['$extends']) && is_string($data['$extends'])) {
            $extends = static::readFile($dir, $data['$extends']);
            $data = array_replace_recursive($extends, $data);
            unset($data['$extends']);
        }

        return $data;
    }