StripLineComments::read PHP Méthode

read() public méthode

Returns stream only including lines from the original stream which don't start with any of the specified comment prefixes.
public read ( $len = null ) : mixed
Résultat mixed the resulting stream, or -1 if the end of the resulting stream has been reached.
    function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }
        $buffer = $this->in->read($len);
        if ($buffer === -1) {
            return -1;
        }
        $lines = explode("\n", $buffer);
        $filtered = array();
        $commentsSize = count($this->_comments);
        foreach ($lines as $line) {
            for ($i = 0; $i < $commentsSize; $i++) {
                $comment = $this->_comments[$i]->getValue();
                if (StringHelper::startsWith($comment, ltrim($line))) {
                    $line = null;
                    break;
                }
            }
            if ($line !== null) {
                $filtered[] = $line;
            }
        }
        $filtered_buffer = implode("\n", $filtered);
        return $filtered_buffer;
    }