Exemple #1
0
 /**
  * Retrieve the properties for the class.
  *
  * @return array A list of properties.
  */
 public function getProperties()
 {
     $rproperties = $this->class->getProperties();
     foreach ($rproperties as $rproperty) {
         if (!isset($this->properties['count'])) {
             $this->properties['count'] = count($rproperties);
         }
         if (!isset($this->properties['property'])) {
             $this->properties['property'] = array();
         }
         $rproperty = InheritdocHandler::resolve($rproperty);
         $_tags = new TagHandler($rproperty->getDocComment(), $this->ancestry);
         $property_docblock = new DocBlock($rproperty->getDocComment());
         // Property-specific data
         $entry = array();
         $entry['name'] = $rproperty->getName();
         $entry['visibility'] = $this->access($rproperty);
         // Where are we?
         SystemStore::add('_.current', $this->class->getName() . '::$' . $rproperty->getName());
         if ($description = $_tags->getDescription()) {
             $entry['description'] = $description;
         }
         // Property inheritance
         if (($declaring_class = $rproperty->getDeclaringClass()->getName()) !== $this->class->getName()) {
             if (!isset($entry['inheritance'])) {
                 $entry['inheritance'] = array();
             }
             if (!isset($entry['inheritance']['class'])) {
                 $entry['inheritance']['class'] = array();
             }
             $declaring_class = $rproperty->getDeclaringClass();
             $subentry = array();
             $subentry['name'] = $declaring_class->getName();
             if ($declaring_class->getFileName()) {
                 $subentry['path'] = str_replace(VANITY_PROJECT_WORKING_DIR . '/', '', $declaring_class->getFileName());
             }
             $entry['inheritance']['class'][] = $subentry;
         }
         // Default value, if accessible
         if ($rproperty->isPublic()) {
             $rvalue = $rproperty->getValue($this->class);
             $adjusted_rvalue = null;
             switch (strtolower(gettype($rvalue))) {
                 case 'boolean':
                     $adjusted_rvalue = $rvalue == 1 ? 'true' : 'false';
                     break;
                 case 'null':
                     $adjusted_rvalue = 'null';
                     break;
                 case 'string':
                     $adjusted_rvalue = $rvalue;
                     break;
                 case 'integer':
                     $adjusted_rvalue = (int) $rvalue;
                     break;
                 case 'array':
                     $adjusted_rvalue = ParseUtil::unwrapArray($rvalue);
                     break;
             }
             $entry['initializer'] = array();
             $entry['initializer']['type'] = gettype($rvalue);
             $entry['initializer']['value'] = $adjusted_rvalue;
         }
         // Property tags
         if ($t = $_tags->getTags()) {
             $entry['metadata'] = $t;
         }
         $this->properties['property'][] = $entry;
     }
     return $this->properties;
 }
Exemple #2
0
 /**
  * Retrieve the properties for the class.
  *
  * @return array A list of properties.
  */
 public function getMethods()
 {
     $rclass_methods = $this->class->getMethods();
     // Add methods and parameters
     $rclass_methods = array_values(array_filter($rclass_methods, function ($rmethod) {
         if ($exclusions = ConfigStore::get('source.exclude.methods')) {
             return !preg_match($exclusions, $rmethod->getName());
         }
         return true;
     }));
     foreach ($rclass_methods as $rmethod) {
         $documentThis = true;
         if (!isset($this->methods['count'])) {
             $this->methods['count'] = count($rclass_methods);
         }
         if (!isset($this->methods['method'])) {
             $this->methods['method'] = array();
         }
         $rmethod = InheritdocHandler::resolve($rmethod);
         $_tags = new TagHandler($rmethod->getDocComment(), $this->ancestry);
         $method_docblock = new DocBlock($rmethod->getDocComment());
         $entry = array();
         $entry['name'] = $rmethod->getName();
         $entry['visibility'] = $this->methodAccess($rmethod);
         if ($extension = $rmethod->getExtensionName()) {
             $entry['extension'] = $extension;
             DependencyCollector::add($extension);
         }
         if ($rmethod->getFileName()) {
             $entry['path'] = str_replace(array(VANITY_SYSTEM . '/', VANITY_PROJECT_WORKING_DIR . '/'), '', $rmethod->getFileName());
             $entry['lines'] = array('start' => $rmethod->getStartLine(), 'end' => $rmethod->getEndLine());
             if ($viewsource = ConfigStore::get('source.viewsource')) {
                 $entry['viewsource'] = str_replace(array('%PATH%', '%LINE%'), array($entry['path'], $entry['lines']['start']), $viewsource);
             }
         }
         if ($description = $_tags->getDescription()) {
             $entry['description'] = $description;
         }
         // Method inheritance
         if (($declaring_class = $rmethod->getDeclaringClass()->getName()) !== $this->class->getName()) {
             if (!isset($entry['inheritance'])) {
                 $entry['inheritance'] = array();
             }
             if (!isset($entry['inheritance']['class'])) {
                 $entry['inheritance']['class'] = array();
             }
             $declaring_class = new ReflectionClass($declaring_class);
             $subentry = array();
             $subentry['name'] = $declaring_class->getName();
             if ($declaring_class->getFileName()) {
                 $subentry['path'] = str_replace(VANITY_PROJECT_WORKING_DIR . '/', '', $declaring_class->getFileName());
             }
             $entry['inheritance']['class'][] = $subentry;
         }
         // Method tags
         if (count($method_docblock->getTags())) {
             if (!isset($entry['metadata'])) {
                 $entry['metadata'] = array();
             }
             if (!isset($entry['metadata']['tag'])) {
                 $entry['metadata']['tag'] = array();
             }
             foreach ($method_docblock->getTags() as $rtag) {
                 $dtag = new Tag($rtag, $this->ancestry);
                 $tagData = $dtag->determine()->process(ConfigStore::get('source.resolve_aliases'));
                 if ($tagData['name'] === 'alias') {
                     SystemStore::add('alias.' . $tagData['entity'], $this->class->getName() . '::' . $rmethod->getName());
                     $documentThis = false;
                 }
                 $entry['metadata']['tag'][] = $tagData;
             }
         }
         // Method parameters
         if ($count = count($rmethod->getParameters())) {
             if (!isset($entry['parameters'])) {
                 $entry['parameters'] = array();
             }
             if (!isset($entry['parameters']['count'])) {
                 $entry['parameters']['count'] = $count;
             }
             if (!isset($entry['parameters']['parameter'])) {
                 $entry['parameters']['parameter'] = array();
             }
             foreach ($rmethod->getParameters() as $rparameter) {
                 $tag_finder = new TagFinder($entry);
                 $param = array();
                 $param['name'] = $rparameter->getName();
                 $param['required'] = !$rparameter->isOptional();
                 $param['passed_by_reference'] = $rparameter->isPassedByReference();
                 if ($rparameter->isDefaultValueAvailable()) {
                     $param['default'] = $rparameter->getDefaultValue();
                 }
                 // Pull-in from @tags
                 if ($_description = $tag_finder->find('description', $param['name'])) {
                     $param['description'] = $_description;
                 }
                 if ($_type = $tag_finder->find('type', $param['name'])) {
                     $param['type'] = $this->ancestry->resolveNamespace($_type);
                 }
                 if ($_types = $tag_finder->find('types', $param['name'])) {
                     $param['types'] = $_types;
                 }
                 // Clean-up parameter metadata tags
                 if (isset($entry['metadata']) && isset($entry['metadata']['tag'])) {
                     foreach ($entry['metadata']['tag'] as $index => $tag) {
                         if ($tag['name'] === 'param' && $tag['variable'] === $param['name']) {
                             unset($entry['metadata']['tag'][$index]);
                         }
                     }
                 }
                 // Type hinting trumps docblock
                 if ($rparameter->getClass()) {
                     if (isset($param['type']) && $param['type'] !== $rparameter->getClass()->getName()) {
                         // @todo: Resolve namespace of declaring class.
                         Inconsistency::add($this->class->getName() . '::' . $rmethod->getName() . '($' . $rparameter->getName() . ') [' . $param['type'] . ' => ' . $rparameter->getClass()->getName() . ']');
                     }
                     $param['type'] = $rparameter->getClass()->getName();
                     if (isset($param['types'])) {
                         unset($param['types']);
                     }
                 }
                 $entry['parameters']['parameter'][] = $param;
             }
         }
         // Return value
         $entry['return'] = array('type' => 'void');
         if (isset($entry['metadata']) && isset($entry['metadata']['tag'])) {
             foreach ($entry['metadata']['tag'] as $index => $tag) {
                 if ($tag['name'] === 'return') {
                     $entry['return'] = $tag;
                     unset($entry['return']['name']);
                     // Clean-up return metadata tags
                     unset($entry['metadata']['tag'][$index]);
                 }
             }
         }
         if ($documentThis) {
             $this->methods['method'][] = $entry;
         }
     }
     return $this->methods;
 }