TTextWriter implements a memory-based text writer. Content written by TTextWriter are stored in memory and can be obtained by calling {@link flush()}.
Since: 3.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Prado\TComponent, implements Prado\IO\ITextWriter
 /**
  * Returns the text content wrapped within a HTML comment with boundary
  * identifier as its comment content.
  * @return string text content chunck.
  */
 public function flush()
 {
     $content = parent::flush();
     if (empty($content)) {
         return "";
     }
     return '<!--' . $this->getBoundary() . '-->' . $content . '<!--//' . $this->getBoundary() . '-->';
 }
示例#2
0
 /**
  * Renders the output cache control.
  * This method overrides the parent implementation by capturing the output
  * from its child controls and saving it into cache, if output cache is needed.
  * @param THtmlWriter
  */
 public function render($writer)
 {
     if ($this->_dataCached) {
         $writer->write($this->_contents);
     } else {
         if ($this->_cacheAvailable) {
             $textwriter = new TTextWriter();
             $multiwriter = new TOutputCacheTextWriterMulti(array($writer->getWriter(), $textwriter));
             $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), $multiwriter);
             $stack = $this->getPage()->getCachingStack();
             $stack->push($this);
             parent::render($htmlWriter);
             $stack->pop();
             $content = $textwriter->flush();
             $data = array($content, $this->_state, $this->_actions, time());
             $this->_cache->set($this->getCacheKey(), $data, $this->getDuration(), $this->getCacheDependency());
         } else {
             parent::render($writer);
         }
     }
 }
示例#3
0
 public function testRenderWithDocumentPathAndTransformPath()
 {
     $expected = "<b>Hello World!</b>\n";
     $transform = new TXmlTransform();
     $transform->setDocumentPath($this->documentPath);
     $transform->setTransformPath($this->transformPath);
     $textWriter = new TTextWriter();
     $htmlWriter = new THtmlWriter($textWriter);
     $transform->render($htmlWriter);
     $actual = $textWriter->flush();
     self::assertEquals($expected, $actual);
 }
示例#4
0
 public function testWriteLine()
 {
     $writer = new TTextWriter();
     $writer->writeLine('some text');
     self::assertEquals("some text\n", $writer->flush());
 }