コード例 #1
0
ファイル: InterfaceMethod.php プロジェクト: lucidphp/writer
 /**
  * {@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
ファイル: PhpGenerator.php プロジェクト: lucidphp/writer
 /**
  * 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
ファイル: Constant.php プロジェクト: lucidphp/writer
 /**
  * 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
ファイル: Property.php プロジェクト: lucidphp/writer
 /**
  * {@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
ファイル: AbstractWriter.php プロジェクト: lucidphp/writer
 /**
  * {@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
ファイル: AbstractBlock.php プロジェクト: lucidphp/writer
 /**
  * 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
ファイル: Annotateable.php プロジェクト: lucidphp/writer
 /**
  * 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
ファイル: Argument.php プロジェクト: lucidphp/writer
 /**
  * {@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
ファイル: WriterTest.php プロジェクト: lucidphp/writer
 /** @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();
 }