예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function generate($raw = false)
 {
     $writer = new Writer(4, true);
     $writer->setOutputIndentation(1);
     $this->getMethodDeclaration($writer, false);
     $writer->appendln(';');
     return $raw ? $writer : $writer->dump();
 }
예제 #2
0
 /**
  * Constructor.
  *
  * @param bool $raw
  */
 public function generate($raw = false)
 {
     $writer = new Writer();
     $writer->writeln('<?php')->newline();
     array_map([$writer, 'writeln'], $this->contents);
     $writer->appendln(PHP_EOL);
     return $raw ? $writer : $writer->dump();
 }
예제 #3
0
 /**
  * generate
  *
  * @param boolean $raw
  *
  * @return void
  */
 public function generate($raw = self::RV_STRING)
 {
     $writer = new Writer();
     $writer->setOutputIndentation(1);
     $this->getDoc($writer);
     $writer->setOutputIndentation(1);
     $writer->writeln(sprintf('const %s = %s;', strtoupper($this->name), $this->getValue()));
     return $raw ? $writer : $writer->dump();
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function generate($raw = false)
 {
     $this->getDoc($writer = new Writer())->writeln(sprintf('%s%s $%s', $this->visibility, $this->prefix, $this->name));
     if (null !== $this->value) {
         $writer->appendln(' = ' . $this->value);
     }
     $writer->appendln(';')->setOutputIndentation(1);
     return $raw ? $writer : $writer->dump();
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function generate($raw = self::RV_STRING)
 {
     $writer = new Writer();
     $this->prepareDoc($ddoc = clone $this->getDoc());
     $this->prepareObjDoc($odoc = clone $this->getObjDoc());
     $writer->writeln($this->getDocType());
     if (!$ddoc->isEmpty()) {
         $writer->newline()->writeln($ddoc->generate());
     }
     $writer->newline()->writeln(sprintf('namespace %s;', $ns = $this->getNamespace()));
     $this->writeUseStatements($writer, $this->getImportResolver(), null !== $ns);
     $writer->newline()->writeln($odoc->generate());
     $this->writeObject($writer);
     return $raw ? $writer : $writer->dump();
 }
예제 #6
0
 /**
  * blockLine
  *
  * @param Writer $writer
  * @param array $lines
  *
  * @return void
  */
 protected function blockLines(Writer $writer, array $lines)
 {
     foreach ($lines as $line) {
         $writer->writeln(' * ' . $line);
     }
 }
예제 #7
0
 /**
  * getDocBlock
  *
  * @return Writer|string
  */
 protected final function getDoc(Writer $writer, $asString = false)
 {
     $this->prepareAnnotations($block = clone $this->docBlock);
     $writer->writeln($block);
     return $asString ? $writer->dump() : $writer;
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function generate($raw = false)
 {
     $writer = new Writer();
     $prefix = $this->isReference ? '&' : '';
     $prefix .= $this->isVariadic ? '...' : '';
     $type = null === $this->type || in_array($this->type, array_merge(self::$silent, self::$primitives)) ? '' : $this->type . ' ';
     if (null !== $this->default) {
         $line = sprintf('%s%s$%s = %s', $type, $prefix, $this->name, $this->default);
     } else {
         $line = sprintf('%s%s$%s', $type, $prefix, $this->name);
     }
     $writer->writeln($line);
     return $raw ? $writer : $writer->dump();
 }
예제 #9
0
 /** @test */
 public function itShouldThrowExceptionOnNoneStrangableValues()
 {
     $wr = new Writer();
     try {
         $wr->writeln([]);
     } catch (\InvalidArgumentException $e) {
         $this->assertSame('Input value must be stringable.', $e->getMessage());
         return;
     }
     $this->fail();
 }
예제 #10
0
파일: Method.php 프로젝트: lucidphp/writer
 /**
  * getBody
  *
  * @return string
  */
 protected function getBody()
 {
     if (null === $this->body) {
         return;
     }
     if ($this->body instanceof Writer) {
         $body = $this->body;
     } else {
         $body = new Writer();
         $body->writeln($this->body);
     }
     $body->setOutputIndentation(0);
     return $body->dump();
 }