Пример #1
0
 /**
  * Parse the comment of the var (field)
  * @param string $var the name of the var
  * @param string $comment the comment associated to the var
  * @return epFieldMap
  */
 protected function parseVarComment($var, $comment)
 {
     $class_var = $this->cm->getName() . '::' . $var;
     // parse var comment
     $c = new epComment($comment);
     if (!$c) {
         throw new epExceptionParser('Cannot parse comment for var [' . $class_var . ']');
         return false;
     }
     // get the @orm tag value
     if (!($value = $c->getTagValue('orm'))) {
         //warn('No @orm tag for var [' . $class_var . ']. Ignored.');
         return false;
     }
     // parse var tag
     if (!($t = new epVarTag())) {
         throw new epExceptionParser('Cannot parse @orm tag for var [' . $class_var . ']');
         return false;
     }
     $error = $t->parse($value);
     if (is_string($error)) {
         throw new epExceptionParser('Error in parsing @orm tag for var [' . $class_var . ']: ' . $error);
         return false;
     }
     // call field map factory to create a field map
     if (!($fm = epFieldMapFactory::make($var, $t->get('type'), $t->get('params')))) {
         return false;
     }
     // always harvest 'raw' customer tags
     $fm->setTags($c->getTags());
     // set column name if set
     if ($column_name = $t->get('name')) {
         $fm->setColumnName($column_name);
     }
     // get key type
     if ($key_type = $t->get('keytype')) {
         // get key name
         if (!($key_name = $t->get('keyname'))) {
             $key_name = $var;
         }
         switch ($key_type) {
             case 'unique':
                 $this->cm->addUniqueKey($key_name, $var);
                 break;
             case 'index':
                 $this->cm->addIndexKey($key_name, $var);
                 break;
         }
     }
     return $fm;
 }