classes/phing/filters/TailFilter.php
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->initialize();
            $this->setInitialized(true);
        }

        while (($buffer = $this->in->read($len)) !== -1) {
            // Remove the last "\n" from buffer for
            // prevent explode to add an empty cell at
            // the end of array
            $buffer = trim($buffer, "\n");

            $lines = explode("\n", $buffer);
            $skip = $this->skip > 0 ? $this->skip : 0;

            if (count($lines) >= $this->lines) {
                // Buffer have more (or same) number of lines than needed.
                // Fill lineBuffer with the last "$this->_lines" lasts ones.
                $off = count($lines) - $this->lines;
                if ($skip > 0) {
                    $this->lineBuffer = array_slice($lines, $off - $skip, -$skip);
                } else {
                    $this->lineBuffer = array_slice($lines, $off);
                }
            } else {
                // Some new lines ...
                // Prepare space for insert these new ones
                $this->lineBuffer = array_slice($this->lineBuffer, count($lines) - 1);
                $this->lineBuffer = array_merge($this->lineBuffer, $lines);
            }
        }

        if (empty($this->lineBuffer)) {
            $ret = -1;
        } else {
            $ret = implode("\n", $this->lineBuffer);
            $this->lineBuffer = [];
        }

        return $ret;
    }
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->initialize();
            $this->setInitialized(true);
        }

        while (($buffer = $this->in->read($len)) !== -1) {
            // Remove the last "\n" from buffer for
            // prevent explode to add an empty cell at
            // the end of array
            $buffer = trim($buffer, "\n");

            $lines = explode("\n", $buffer);
            $skip = $this->skip > 0 ? $this->skip : 0;

            if (count($lines) >= $this->lines) {
                // Buffer have more (or same) number of lines than needed.
                // Fill lineBuffer with the last "$this->_lines" lasts ones.
                $off = count($lines) - $this->lines;
                if ($skip > 0) {
                    $this->lineBuffer = array_slice($lines, $off - $skip, -$skip);
                } else {
                    $this->lineBuffer = array_slice($lines, $off);
                }
            } else {
                // Some new lines ...
                // Prepare space for insert these new ones
                $this->lineBuffer = array_slice($this->lineBuffer, count($lines) - 1);
                $this->lineBuffer = array_merge($this->lineBuffer, $lines);
            }
        }

        if (empty($this->lineBuffer)) {
            $ret = -1;
        } else {
            $ret = implode("\n", $this->lineBuffer);
            $this->lineBuffer = [];
        }

        return $ret;
    }
public function read ( $ len = null ) { if ( ! $ this -> getInitialized ( ) ) { $ this -> initialize ( ) ; $ this -> setInitialized ( true ) ; } while ( ( $ buffer = $ this -> in -> read ( $ len ) ) !== - 1 ) { // Remove the last "\n" from buffer for // prevent explode to add an empty cell at // the end of array $ buffer = trim ( $ buffer , "\n" ) ; $ lines = explode ( "\n" , $ buffer ) ; $ skip = $ this -> skip > 0 ? $ this -> skip : 0 ; if ( count ( $ lines ) >= $ this -> lines ) { // Buffer have more (or same) number of lines than needed. // Fill lineBuffer with the last "$this->_lines" lasts ones. $ off = count ( $ lines ) - $ this -> lines ; if ( $ skip > 0 ) { $ this -> lineBuffer = array_slice ( $ lines , $ off - $ skip , - $ skip ) ; } else { $ this -> lineBuffer = array_slice ( $ lines , $ off ) ; } } else { // Some new lines ... // Prepare space for insert these new ones $ this -> lineBuffer = array_slice ( $ this -> lineBuffer , count ( $ lines ) - 1 ) ; $ this -> lineBuffer = array_merge ( $ this -> lineBuffer , $ lines ) ; } } if ( empty ( $ this -> lineBuffer ) ) { $ ret = - 1 ; } else { $ ret = implode ( "\n" , $ this -> lineBuffer ) ; $ this -> lineBuffer = [ ] ; } return $ ret ; }
Returns the last n lines of a file.

@param  int $len Num chars to read.
@return mixed The filtered buffer or -1 if EOF.
Returns the last n lines of a file .