/**
  * @return array {[ className => ReflectionProperties[] ]}
  */
 public function getInheritedProperties()
 {
     $properties = [];
     $allProperties = array_flip(array_map(function (ReflectionProperty $property) {
         return $property->getName();
     }, $this->reflectionClass->getOwnProperties()));
     foreach ($this->reflectionClass->getParentClasses() as $class) {
         $inheritedProperties = [];
         foreach ($class->getOwnProperties() as $property) {
             if (!array_key_exists($property->getName(), $allProperties) && !$property->isPrivate()) {
                 $inheritedProperties[$property->getName()] = $property;
                 $allProperties[$property->getName()] = NULL;
             }
         }
         $properties = $this->sortElements($inheritedProperties, $properties, $class);
     }
     return $properties;
 }
 /**
  * @return array {[ traitName => ReflectionProperty[] ]}
  */
 public function getUsedProperties()
 {
     $allProperties = array_flip(array_map(function (ReflectionProperty $property) {
         return $property->getName();
     }, $this->reflectionClass->getOwnProperties()));
     $properties = [];
     foreach ($this->reflectionClass->getTraits() as $trait) {
         if (!$trait instanceof ReflectionClass) {
             continue;
         }
         $usedProperties = [];
         foreach ($trait->getOwnProperties() as $property) {
             if (!array_key_exists($property->getName(), $allProperties)) {
                 $usedProperties[$property->getName()] = $property;
                 $allProperties[$property->getName()] = NULL;
             }
         }
         if (!empty($usedProperties)) {
             ksort($usedProperties);
             $properties[$trait->getName()] = array_values($usedProperties);
         }
     }
     return $properties;
 }
Esempio n. 3
0
 /**
  * Prepares and returns used class lists.
  *
  * @return array
  */
 protected function parseClassLists()
 {
     $allClasses = array(self::TOKENIZED_CLASSES => array(), self::INTERNAL_CLASSES => array(), self::NONEXISTENT_CLASSES => array());
     $declared = array_flip(array_merge(get_declared_classes(), get_declared_interfaces()));
     foreach ($this->getNamespaces() as $namespace) {
         foreach ($namespace->getClasses() as $name => $trClass) {
             $class = new Reflection\ReflectionClass($trClass, $this->generator);
             $allClasses[self::TOKENIZED_CLASSES][$name] = $class;
             if (!$class->isDocumented()) {
                 continue;
             }
             foreach (array_merge($trClass->getParentClasses(), $trClass->getInterfaces()) as $parentName => $parent) {
                 if ($parent->isInternal()) {
                     if (!isset($allClasses[self::INTERNAL_CLASSES][$parentName])) {
                         $allClasses[self::INTERNAL_CLASSES][$parentName] = $parent;
                     }
                 } elseif (!$parent->isTokenized()) {
                     if (!isset($allClasses[self::NONEXISTENT_CLASSES][$parentName])) {
                         $allClasses[self::NONEXISTENT_CLASSES][$parentName] = $parent;
                     }
                 }
             }
         }
     }
     foreach ($allClasses[self::TOKENIZED_CLASSES] as $class) {
         if (!$class->isDocumented()) {
             continue;
         }
         foreach ($class->getOwnMethods() as $method) {
             $allClasses = $this->processFunction($declared, $allClasses, $method);
         }
         foreach ($class->getOwnProperties() as $property) {
             $annotations = $property->getAnnotations();
             if (!isset($annotations['var'])) {
                 continue;
             }
             foreach ($annotations['var'] as $doc) {
                 foreach (explode('|', preg_replace('~\\s.*~', '', $doc)) as $name) {
                     if ($name = rtrim($name, '[]')) {
                         $name = Resolver::resolveClassFQN($name, $class->getNamespaceAliases(), $class->getNamespaceName());
                         $allClasses = $this->addClass($declared, $allClasses, $name);
                     }
                 }
             }
         }
     }
     foreach ($this->getFunctions() as $function) {
         $allClasses = $this->processFunction($declared, $allClasses, $function);
     }
     array_walk_recursive($allClasses, function (&$reflection, $name, Generator $generator) {
         if (!$reflection instanceof Reflection\ReflectionClass) {
             $reflection = new Reflection\ReflectionClass($reflection, $generator);
         }
     }, $this->generator);
     return $allClasses;
 }