Ejemplo n.º 1
0
 /**
  * @param $properties array
  * @param $class      Reflection_Class
  */
 private function scanForImplements(&$properties, Reflection_Class $class)
 {
     // properties from the class and its direct traits
     $implemented_properties = $class->getProperties([T_USE]);
     foreach ($implemented_properties as $property) {
         $expr = '%' . '\\n\\s+\\*\\s+' . '@(getter|link|setter)' . '(?:\\s+' . '(?:([\\\\\\w]+)::)?' . '(\\w+)' . ')?' . '%';
         preg_match_all($expr, $property->getDocComment(), $match);
         foreach ($match[1] as $type) {
             $type = $type == 'setter' ? 'write' : 'read';
             $properties[$property->name]['implements'][$type] = true;
         }
         if ($property->getParent()) {
             $properties[$property->name]['override'] = true;
         }
     }
     // properties overridden into the class and its direct traits
     $documentations = $class->getDocComment([T_USE]);
     foreach ($this->scanForOverrides($documentations, ['getter', 'link', 'setter']) as $match) {
         $properties[$match['property_name']]['implements'][$match['type']] = true;
         if (!isset($implemented_properties[$match['property_name']])) {
             $class_properties = $class->getProperties([T_EXTENDS]);
             $extends = $class;
             while (!isset($class_properties[$match['property_name']])) {
                 // TODO try the error to have a class with @representative and property names that do not exist. That will crash here but the error message is incomprehensible
                 $extends = $extends->source->getOutsideClass($extends->getListAnnotation('extends')->values()[0]);
                 $class_properties = $extends->getProperties([T_EXTENDS]);
             }
             $property = $class_properties[$match['property_name']];
             if (isset($extends)) {
                 $property->final_class = $class->name;
             }
             if (!strpos($property->getDocComment(), '@getter') && !strpos($property->getDocComment(), '@link') && !strpos($property->getDocComment(), '@setter')) {
                 $expr = '%@override\\s+' . $match['property_name'] . '\\s+.*(@getter|@link|@setter)%';
                 preg_match($expr, $property->class->getDocComment(), $match2);
                 if ($match2) {
                     $properties[$match['property_name']]['override'] = true;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param $properties array
  * @param $class      Reflection_Class
  */
 private function scanForSetters(&$properties, Reflection_Class $class)
 {
     foreach ($class->getProperties() as $property) {
         $expr = '%' . '\\n\\s+\\*\\s+' . '@setter' . '(?:\\s+(?:([\\\\\\w]+)::)?' . '(\\w+)?)?' . '%';
         preg_match($expr, $property->getDocComment(), $match);
         if ($match) {
             $advice = [empty($match[1]) ? '$this' : $class->source->fullClassName($match[1]), empty($match[2]) ? Names::propertyToMethod($property->name, 'set') : $match[2]];
             $properties[$property->name][] = ['write', $advice];
         }
     }
     foreach ($this->scanForOverrides($class->getDocComment(), ['setter']) as $match) {
         $advice = [empty($match['class_name']) ? '$this' : $match['class_name'], empty($match['method_name']) ? Names::propertyToMethod($match['property_name'], 'set') : $match['method_name']];
         $properties[$match['property_name']][] = ['write', $advice];
     }
 }