public function isTargetObject(PropertyReflection $property)
 {
     if ($class = $this->findClass($property->getDeclaringClass(), $property->getDocBlock()->getTag('var')->getContent())) {
         return true;
     }
     return false;
 }
 /**
  * @param  PropertyReflection $reflectionProperty
  * @return PropertyGenerator
  */
 public static function fromReflection(PropertyReflection $reflectionProperty)
 {
     $property = new static();
     $property->setName($reflectionProperty->getName());
     $allDefaultProperties = $reflectionProperty->getDeclaringClass()->getDefaultProperties();
     $property->setDefaultValue($allDefaultProperties[$reflectionProperty->getName()]);
     if ($reflectionProperty->getDocComment() != '') {
         $property->setDocBlock(DocBlockGenerator::fromReflection($reflectionProperty->getDocBlock()));
     }
     if ($reflectionProperty->isStatic()) {
         $property->setStatic(true);
     }
     if ($reflectionProperty->isPrivate()) {
         $property->setVisibility(self::VISIBILITY_PRIVATE);
     } elseif ($reflectionProperty->isProtected()) {
         $property->setVisibility(self::VISIBILITY_PROTECTED);
     } else {
         $property->setVisibility(self::VISIBILITY_PUBLIC);
     }
     $property->setSourceDirty(false);
     return $property;
 }
Esempio n. 3
0
 /**
  * Extract type of the property from DocBlock
  *
  * @param  \Zend\Code\Reflection\PropertyReflection $prop reflection property object
  * @return string Property type
  */
 protected function _getPropertyType(PropertyReflection $prop)
 {
     $docBlock = $prop->getDocBlock();
     if (!$docBlock) {
         return 'Unknown';
     }
     if (!$docBlock->hasTag('var')) {
         return 'Unknown';
     }
     $tag = $docBlock->getTag('var');
     return trim($tag->getContent());
 }
Esempio n. 4
0
 /**
  * Process class property.
  *
  * @param Zend\Code\Reflection\PropertyReflection $property
  * @param $defaultProperties
  * @param $typeName
  * @throws InvalidArgumentException
  */
 protected function _processProperty(\Zend\Code\Reflection\PropertyReflection $property, $defaultProperties, $typeName)
 {
     $propertyName = $property->getName();
     $propertyDocBlock = $property->getDocBlock();
     if (!$propertyDocBlock) {
         throw new InvalidArgumentException('Each property must have description with @var annotation.');
     }
     $varTags = $propertyDocBlock->getTags('var');
     if (empty($varTags)) {
         throw new InvalidArgumentException('Property type must be defined with @var tag.');
     }
     /** @var \Zend\Code\Reflection\DocBlock\Tag\GenericTag $varTag */
     $varTag = current($varTags);
     $varContentParts = explode(' ', $varTag->getContent(), 2);
     $varType = current($varContentParts);
     $varInlineDoc = count($varContentParts) > 1 ? end($varContentParts) : '';
     $optionalTags = $propertyDocBlock->getTags('optional');
     if (!empty($optionalTags)) {
         /** @var \Zend\Code\Reflection\DocBlock\Tag\GenericTag $isOptionalTag */
         $isOptionalTag = current($optionalTags);
         $isOptional = $isOptionalTag->getName() == 'optional';
     } else {
         $isOptional = false;
     }
     $this->_types[$typeName]['parameters'][$propertyName] = array('type' => $this->process($varType), 'required' => !$isOptional && is_null($defaultProperties[$propertyName]), 'default' => $defaultProperties[$propertyName], 'documentation' => $varInlineDoc . $this->_getDescription($propertyDocBlock));
 }