Exemplo n.º 1
0
 /**
  * Parses the type of a class-field from the given phpdoc
  *
  * @param PC_Obj_Field $field the field
  */
 public function parse_field_doc($field)
 {
     if (isset($this->fieldComments[$field->get_name()])) {
         // if we already know the value, we don't have to use the phpdoc
         // TODO we could issue a warning here if the type differs
         if ($field->get_type()->is_unknown()) {
             $type = $this->parse_var_from($this->fieldComments[$field->get_name()]);
             if ($type !== null) {
                 $field->set_type($type);
             }
         }
         unset($this->fieldComments[$field->get_name()]);
     }
 }
Exemplo n.º 2
0
 /**
  * Parses the given field-description
  * 
  * @param string $desc the description
  * @return PC_Obj_Field|PC_Obj_Constant the field or constant
  * @throws PC_PHPRef_Exception if it fails
  */
 public static function parse_field_desc($desc)
 {
     // prepare description
     $desc = trim(strip_tags($desc));
     $desc = FWS_StringHelper::htmlspecialchars_back($desc);
     // filter out modifier, return-type, name and params
     $match = array();
     $res = preg_match('/^(?:(const|readonly|static|public|protected|private)\\s*)?' . '(?:(const|readonly|static|public|protected|private)\\s*)?' . '(?:(const|readonly|static|public|protected|private)\\s*)?' . '(?:(\\S+)\\s+)?' . '\\$?([a-zA-Z0-9_:]+)\\s*(?:=\\s*([^' . "\n" . ';]+)\\s*)?;$/s', $desc, $match);
     if (!$res) {
         throw new PC_PHPRef_Exception('Unable to parse "' . $desc . '"');
     }
     list(, $modifier1, $modifier2, $modifier3, $type, $name) = $match;
     if ($modifier1 == 'const' || $modifier2 == 'const' || $modifier3 == 'const') {
         $field = new PC_Obj_Constant('', 0, $name);
     } else {
         $field = new PC_Obj_Field('', 0, $name);
         if ($modifier1 == 'static' || $modifier2 == 'static' || $modifier3 == 'static') {
             $field->set_static(true);
         }
         if (in_array($modifier1, array('private', 'protected'))) {
             $field->set_visibility($modifier1);
         } else {
             if (in_array($modifier2, array('private', 'protected'))) {
                 $field->set_visibility($modifier2);
             } else {
                 if (in_array($modifier3, array('private', 'protected'))) {
                     $field->set_visibility($modifier3);
                 }
             }
         }
     }
     if ($type) {
         $field->set_type(PC_Obj_MultiType::get_type_by_name($type));
     }
     if (isset($match[6]) && $match[6] !== '' && !$field->get_type()->is_multiple()) {
         if ($type) {
             $field->get_type()->get_first()->set_value($match[6]);
         } else {
             $field->set_type(new PC_Obj_MultiType(PC_Obj_Type::get_type_by_value($match[6])));
         }
     }
     return $field;
 }