public function isTargetObject(PropertyReflection $property)
 {
     if ($class = $this->findClass($property->getDeclaringClass(), $property->getDocBlock()->getTag('var')->getContent())) {
         return true;
     }
     return false;
 }
Esempio n. 2
0
    /**
     * fromReflection()
     *
     * @param PropertyReflection $reflectionProperty
     * @return PropertyGenerator
     */
    public static function fromReflection(PropertyReflection $reflectionProperty)
    {
        $property = new self();

        $property->setName($reflectionProperty->getName());

        $allDefaultProperties = $reflectionProperty->getDeclaringClass()->getDefaultProperties();

        $property->setDefaultValue($allDefaultProperties[$reflectionProperty->getName()]);

        if ($reflectionProperty->getDocComment() != '') {
            $property->setDocBlock(DocBlockGenerator::fromReflection($reflectionProperty->getDocComment()));
        }

        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;
    }
 /**
  * @param AnnotationCollection $annotations
  * @param PropertyReflection   $reflection
  * @param ArrayObject          $spec
  */
 protected function configureProperty($annotations, $reflection, $spec)
 {
     $name = $reflection->getName();
     $propertySpec = new ArrayObject();
     $events = $this->getEventManager();
     foreach ($annotations as $annotation) {
         $events->trigger(__FUNCTION__, $this, ['annotation' => $annotation, 'spec' => $propertySpec, 'name' => $name]);
     }
     if (!isset($spec['properties'])) {
         $spec['properties'] = [];
     }
     $spec['properties'][] = $propertySpec;
 }
Esempio n. 4
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. 5
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));
 }