Ejemplo n.º 1
0
 public function testPhpParserException()
 {
     $traverser = $this->getMock('PhpParser\\NodeTraverser');
     $traverser->expects($this->once())->method('traverse')->will($this->throwException(new \PhpParser\Error('error')));
     $writer = new Writer($traverser);
     $this->setExpectedException('hanneskod\\classtools\\Exception\\RuntimeException');
     $writer->write([]);
 }
Ejemplo n.º 2
0
 /**
  * Strip statements
  *
  * @expectOutputRegex #echo 'bar';#
  */
 public function exampleStripNodes()
 {
     $reader = new Reader("<?php require 'Foo.php'; echo 'bar';");
     $writer = new Writer();
     $writer->apply(new Action\NodeStripper('Expr_Include'));
     // Outputs the echo statement
     echo $writer->write($reader->readAll());
 }
Ejemplo n.º 3
0
 public function run()
 {
     $writer = new Writer($this->config['parameters'], $this->config['dataFolder']);
     $tables = $this->config['storage']['input']['tables'];
     foreach ($tables as $table) {
         $writer->write($table);
     }
 }
Ejemplo n.º 4
0
 public function testWriteIntegers()
 {
     $w = new Writer(tmpfile(), array('hasHeader' => true));
     $numbers = array('zero' => 0, 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5);
     $w->write($numbers);
     foreach ($w as $line) {
         $this->assertEquals($line, $numbers);
     }
 }
Ejemplo n.º 5
0
 public function generate()
 {
     $parseData = \EventController::callFilter(self::EventName, $this->data->getValue());
     $view = new View($this->tpl->getValue());
     $view->addHelper(new ViewHelper());
     $view->set($parseData);
     $content = $view->render();
     $writer = new Writer($this->url->getValue());
     $writer->write($content);
 }
Ejemplo n.º 6
0
 /**
  * Handles closing elements of the xml file.
  *
  * @param      $name The local name (without prefix), or the empty string if
  *         Namespace processing is not being performed.
  */
 public function endElement($name)
 {
     if (self::DEBUG) {
         print "endElement(" . $name . ") called\n";
     }
     if ($name == "dataset") {
         if ($this->currBuilder !== null) {
             $this->sqlWriter->write($this->currBuilder->getTableEndSql());
         }
         $this->sqlWriter->write(call_user_func(array($this->builderClazz, 'getDatabaseEndSql')));
     }
 }
Ejemplo n.º 7
0
 public function execute()
 {
     $iterator = new \DirectoryIterator($this->inputDir);
     $interpreter = new Interpreter();
     $operations = [];
     foreach ($iterator as $path) {
         if ($path->getExtension() === 'rst') {
             $operations[] = $interpreter->parse(file_get_contents($path->getRealPath()));
         }
     }
     $operations = array_values(array_filter($operations));
     usort($operations, function ($a, $b) {
         return strlen($a['path']) - strlen($b['path']);
     });
     $writer = new Writer($this->outputDir, $this->namespace, $operations);
     $writer->write();
 }
Ejemplo n.º 8
0
 /**
  * 配列をCSV形式で書き出す
  * @access public
  * @see Writer::write()
  */
 function write($arr)
 {
     $enclosure = preg_quote($this->enclosure);
     foreach ($arr as $index => $ar) {
         if (!is_string($ar)) {
             continue;
         }
         // 文字列中に"がある場合は""に置換える
         // RFC4180
         if (mb_strstr($ar, $this->enclosure) !== false) {
             $ar = preg_replace('/' . $enclosure . '/', $this->enclosure . $this->enclosure, $ar);
         }
         // 文字列の場合は囲み文字を追加する
         $ar = $this->enclosure . $ar . $this->enclosure;
         $arr[$index] = $ar;
     }
     parent::write(implode($this->delimiter, $arr) . $this->newLineChar);
 }
    public function testSaveGlobalUseStatements()
    {
        $reader = new Reader(<<<EOF
<?php
use random\\Exception;
class ClassName
{
}
EOF
);
        $expected = <<<EOF
namespace  {
    use random\\Exception;
    class ClassName
    {
    }
}
EOF;
        $writer = new Writer();
        $this->assertEquals($expected, $writer->write($reader->read('ClassName')));
    }
Ejemplo n.º 10
0
 /**
  * Write PHP array, as table. Input array format: keys are strings,
  * values are (type,value) tuples.
  *
  * @param $d
  *
  * @return Writer
  */
 public function writeTable($d)
 {
     $this->flushBits();
     $table_data = new Writer();
     foreach ($d as $k => $va) {
         list($ftype, $v) = $va;
         $table_data->writeShortStr($k);
         if ($ftype == 'S') {
             $table_data->write('S');
             $table_data->writeLongStr($v);
         } else {
             if ($ftype == 'I') {
                 $table_data->write('I');
                 $table_data->_writeSignedLong($v);
             } else {
                 if ($ftype == 'D') {
                     // 'D' type values are passed Decimal instances.
                     $table_data->write('D');
                     $table_data->writeOctet($v->e);
                     $table_data->_writeSignedLong($v->n);
                 } else {
                     if ($ftype == 'T') {
                         $table_data->write('T');
                         $table_data->writeTimestamp($v);
                     } else {
                         if ($ftype == 'F') {
                             $table_data->write('F');
                             $table_data->writeTable($v);
                         } else {
                             if ($ftype = 'A') {
                                 $table_data->write('A');
                                 $table_data->writeArray($v);
                             }
                         }
                     }
                 }
             }
         }
     }
     $table_data = $table_data->getvalue();
     $this->writeLong(strlen($table_data));
     $this->write($table_data);
     return $this;
 }
Ejemplo n.º 11
0
 public function write($output)
 {
     return $this->writer->write($output);
 }
Ejemplo n.º 12
0
 function testWriteToMimeDir()
 {
     $result = Writer::write($this->getComponent());
     $this->assertEquals("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", $result);
 }
Ejemplo n.º 13
0
 function pipe(Writer $writer)
 {
     while ($v = $this->read()) {
         $writer->write($v);
     }
 }
Ejemplo n.º 14
0
 /**
  * @param FileWriter $writer
  * @param PhingFile $f
  *
  * @return void
  */
 private function appendFile(Writer $writer, PhingFile $f)
 {
     $in = $this->getFilteredReader(new FileReader($f));
     $text = '';
     while (-1 !== ($buffer = $in->read())) {
         // -1 indicates EOF
         $text .= $buffer;
     }
     if ($this->fixLastLine && ($text[strlen($text) - 1] !== "\n" || $text[strlen($text) - 1] !== "\r")) {
         $text .= $this->eolString;
     }
     $text = $this->appendHeader($text);
     $text = $this->appendFooter($text);
     $writer->write($text);
     if ($f instanceof PhingFile && $this->to instanceof PhingFile) {
         $this->log("Appending contents of " . $f->getPath() . " to " . $this->to->getPath());
     }
 }
Ejemplo n.º 15
0
 /**
  * Returns the document as a string
  *
  * @param  string  $format  the desired format (optional; if omitted, defaults
  *      to 'rtf')
  * @return  string
  * @throws  InvalidArgumentException  if $format is not a string
  * @since  0.1.0
  */
 public function write($format = 'rtf')
 {
     $string = '';
     // if $format is a string
     if (is_string($format)) {
         $writer = new Writer();
         $string = $writer->write($this->root, $format);
     } else {
         throw new \InvalidArgumentException(__METHOD__ . "() expects parameter one, format, to be a string");
     }
     return $string;
 }
Ejemplo n.º 16
0
 /**
  * write() should return a string if format is text
  */
 public function testWrite_returnsString_ifFormatIsText()
 {
     $group = (new Element\Group())->appendChild(new Element\Text('foo '))->appendChild((new Element\Group())->appendChild(new Element\Control\Word\B())->appendChild(new Element\Text('bar'))->appendChild(new Element\Control\Word\B(0)));
     $renderer = new Renderer();
     $root = $renderer->render($group);
     $writer = new Writer();
     $expected = 'foo bar';
     $actual = $writer->write($root, 'text');
     $this->assertEquals($expected, $actual);
     return;
 }