create() 공개 정적인 메소드

Creates a new PHP constant
public static create ( string $name = null, mixed $value = null, boolean $isExpression = false ) : static
$name string
$value mixed
$isExpression boolean
리턴 static
 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));
 }
예제 #3
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;
 }
예제 #4
0
 /**
  * @return PhpConstant
  */
 private function getConstant()
 {
     return PhpConstant::create(self::CONSTANT)->setDescription('my constant')->setLongDescription('my very long contstant')->setType('boolean', 'this constant is a boolean');
 }
 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));
 }