Author: Thomas Gossmann
Inheritance: extends AbstractModel, implements gossi\codegen\model\GenerateableInterface, implements gossi\codegen\model\DocblockInterface, implements gossi\codegen\model\ValueInterface, use trait gossi\codegen\model\parts\DocblockPart, use trait gossi\codegen\model\parts\LongDescriptionPart, use trait gossi\codegen\model\parts\NamePart, use trait gossi\codegen\model\parts\TypeDocblockGeneratorPart, use trait gossi\codegen\model\parts\TypePart, use trait gossi\codegen\model\parts\ValuePart
Exemplo n.º 1
0
 /**
  * Adds a constant
  *
  * @param string|PhpConstant $nameOrConstant constant name or instance
  * @param string $value
  * @return $this
  */
 public function setConstant($nameOrConstant, $value = null, $isExpression = false)
 {
     if ($nameOrConstant instanceof PhpConstant) {
         $name = $nameOrConstant->getName();
         $constant = $nameOrConstant;
     } else {
         $name = $nameOrConstant;
         $constant = new PhpConstant($nameOrConstant, $value, $isExpression);
     }
     $this->constants->set($name, $constant);
     return $this;
 }
 /**
  * Adds a constant
  *
  * @param string|PhpConstant $nameOrConstant constant name or instance
  * @param string $value
  * @return $this
  */
 public function setConstant($nameOrConstant, $value = null)
 {
     if ($nameOrConstant instanceof PhpConstant) {
         $name = $nameOrConstant->getName();
         $constant = $nameOrConstant;
     } else {
         $name = $nameOrConstant;
         $constant = new PhpConstant($nameOrConstant);
         $constant->setValue($value);
     }
     $this->constants[$name] = $constant;
     return $this;
 }
 public function testExpression()
 {
     $class = new PhpClass('ClassWithExpression');
     $class->setConstant(PhpConstant::create('FOO', 'BAR'))->setProperty(PhpProperty::create('bembel')->setExpression("['ebbelwoi' => 'is eh besser', 'als wie' => 'bier']"))->setMethod(PhpMethod::create('getValue')->addParameter(PhpParameter::create('arr')->setExpression('[self::FOO => \'baz\']')));
     $codegen = new CodeFileGenerator(['generateDocblock' => false]);
     $code = $codegen->generate($class);
     $this->assertEquals($this->getGeneratedContent('ClassWithExpression.php'), $code);
 }
 public function testValues()
 {
     $generator = new ModelGenerator();
     $prop = PhpProperty::create('foo')->setValue('string');
     $this->assertEquals('public $foo = \'string\';' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(300);
     $this->assertEquals('public $foo = 300;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(162.5);
     $this->assertEquals('public $foo = 162.5;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(true);
     $this->assertEquals('public $foo = true;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(false);
     $this->assertEquals('public $foo = false;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(null);
     $this->assertEquals('public $foo = null;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(PhpConstant::create('BAR'));
     $this->assertEquals('public $foo = BAR;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setExpression("['bar' => 'baz']");
     $this->assertEquals('public $foo = [\'bar\' => \'baz\'];' . "\n", $generator->generate($prop));
 }
Exemplo n.º 5
0
 public function testEmptyConstant()
 {
     $constant = new PhpConstant();
     $constant->generateDocblock();
     $this->assertTrue($constant->getDocblock()->isEmpty());
 }
 protected function visitConstant(Const_ $node, Doc $doc = null)
 {
     $const = new PhpConstant($node->name, $this->getValue($node));
     $const->setValue($this->getValue($node->value));
     $this->parseMemberDocblock($const, $doc);
     $this->struct->setConstant($const);
 }
 public function visitStructConstant(PhpConstant $constant)
 {
     $this->writer->writeln('const ' . $constant->getName() . ' = ' . $this->getPhpExport($constant->getValue()) . ';');
 }
 /**
  * @param PhpConstant $a
  * @param PhpConstant $b
  */
 public function compare($a, $b)
 {
     return $this->comparator->compare($a->getName(), $b->getName());
 }
Exemplo n.º 9
0
 /**
  * Creates ClassWithComments
  * 
  * @return PhpClass
  */
 public static function createClassWithComments()
 {
     $class = PhpClass::create('gossi\\codegen\\tests\\fixtures\\ClassWithComments');
     $class->setDescription('A class with comments');
     $class->setLongDescription('Here is a super dooper long-description');
     $docblock = $class->getDocblock();
     $docblock->appendTag(AuthorTag::create('gossi'));
     $docblock->appendTag(SinceTag::create('0.2'));
     $class->setConstant(PhpConstant::create('FOO', 'bar')->setDescription('Best const ever')->setLongDescription('Aaaand we go along long')->setType('string')->setTypeDescription('baz'));
     $class->setProperty(PhpProperty::create('propper')->setDescription('best prop ever')->setLongDescription('Aaaand we go along long long')->setType('string')->setTypeDescription('Wer macht sauber?'));
     $class->setMethod(PhpMethod::create('setup')->setDescription('Short desc')->setLongDescription('Looong desc')->addParameter(PhpParameter::create('moo')->setType('boolean')->setTypeDescription('makes a cow'))->addParameter(PhpParameter::create('foo')->setType('foo', 'makes a fow'))->setType('boolean', 'true on success and false if it fails'));
     return $class;
 }
 public function testValues()
 {
     $generator = new ModelGenerator();
     $prop = PhpParameter::create('foo')->setValue('string');
     $this->assertEquals('$foo = \'string\'', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(300);
     $this->assertEquals('$foo = 300', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(162.5);
     $this->assertEquals('$foo = 162.5', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(true);
     $this->assertEquals('$foo = true', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(false);
     $this->assertEquals('$foo = false', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(null);
     $this->assertEquals('$foo = null', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(PhpConstant::create('BAR'));
     $this->assertEquals('$foo = BAR', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setExpression("['bar' => 'baz']");
     $this->assertEquals('$foo = [\'bar\' => \'baz\']', $generator->generate($prop));
 }