getProperty() public method

public getProperty ( string $propertyName ) : Zend\Code\Generator\PropertyGenerator | false
$propertyName string
return Zend\Code\Generator\PropertyGenerator | false
Esempio n. 1
0
 public function testPropertyAccessors()
 {
     $classGenerator = new ClassGenerator();
     $classGenerator->addProperties(array('propOne', new PropertyGenerator('propTwo')));
     $properties = $classGenerator->getProperties();
     $this->assertEquals(count($properties), 2);
     $this->assertInstanceOf('Zend\\Code\\Generator\\PropertyGenerator', current($properties));
     $property = $classGenerator->getProperty('propTwo');
     $this->assertInstanceOf('Zend\\Code\\Generator\\PropertyGenerator', $property);
     $this->assertEquals($property->getName(), 'propTwo');
     // add a new property
     $classGenerator->addProperty('prop3');
     $this->assertEquals(count($classGenerator->getProperties()), 3);
 }
Esempio n. 2
0
 protected function handleProperty(Generator\ClassGenerator $class, PHPProperty $prop)
 {
     $generatedProp = new PropertyGenerator($prop->getName());
     $generatedProp->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED);
     if (!$class->hasProperty($prop->getName())) {
         $class->addPropertyFromGenerator($generatedProp);
     } else {
         $generatedProp = $class->getProperty($prop->getName());
     }
     $docBlock = new DocBlockGenerator();
     $generatedProp->setDocBlock($docBlock);
     if ($prop->getDoc()) {
         $docBlock->setLongDescription($prop->getDoc());
     }
     $tag = new Generator\DocBlock\Tag();
     $tag->setName("@var {$this->getPropertyType($prop)}");
     $docBlock->setTag($tag);
     $type = $prop->getType();
     if ($type->type && $this->isTypeMapped($type->type->getName())) {
         if (!$class->hasProperty('_typeMap')) {
             $generatedProp = new PropertyGenerator('_typeMap');
             $generatedProp->setDefaultValue([]);
             $generatedProp->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED);
             $class->addPropertyFromGenerator($generatedProp);
         }
         $property = $class->getProperty('_typeMap');
         $defaultValue = $property->getDefaultValue()->getValue();
         $defaultValue[$prop->getName()] = $type->type->getName();
         $property->setDefaultValue($defaultValue);
     }
 }