hasProperty() public method

public hasProperty ( string $propertyName ) : boolean
$propertyName string
return boolean
    /**
     * @group ZF-7361
     */
    public function testHasProperty()
    {
        $classGenerator = new ClassGenerator();
        $classGenerator->addProperty('propertyOne');

        $this->assertTrue($classGenerator->hasProperty('propertyOne'));
    }
示例#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);
     }
 }
示例#3
0
 /**
  * @group ZF-7361
  */
 public function testHasProperty()
 {
     $property = new PropertyGenerator();
     $property->setName('propertyOne');
     $classGenerator = new ClassGenerator();
     $classGenerator->setProperty($property);
     $this->assertTrue($classGenerator->hasProperty('propertyOne'));
 }
示例#4
0
 /**
  * Handle an associative property field
  * @param string                              $name             - name of the field
  * @param \Zend\Code\Generator\ClassGenerator $cg               - The class generator object to attach to
  * @param \Doctrine\ORM\Mapping\ClassMetadata $ormClassMetaData - The ORM class meta data
  */
 private function handleAssocProperty($name, Generator\ClassGenerator &$cg, ORMClassMetadata $ormClassMetaData)
 {
     $assocMapping = $ormClassMetaData->getAssociationMapping($name);
     $property = $this->createProperty($name);
     if ($assocMapping['type'] & $ormClassMetaData::TO_MANY) {
         // This is a collection (should be an Array)
         $property->setDocBlock('@var array $' . $name);
         $property->setDefaultValue(array());
         $paramType = self::PARAM_TYPE_RELATION_COLLECTION;
     } else {
         // This is a single relation
         $property->setDocBlock('@var ' . $assocMapping['targetEntity'] . ' $' . $name);
         $paramType = self::PARAM_TYPE_RELATION_SINGLE;
     }
     if (!$cg->hasProperty($name)) {
         $cg->addProperties(array($property));
         $cg->addMethods($this->getSetterMethods($cg, $name, $paramType, $assocMapping['targetEntity']));
     }
 }