Пример #1
0
 /**
  * Test the comment parser
  */
 function testComment()
 {
     // make a random array of tag_value pairs
     $tag_values = array();
     for ($i = 0; $i < self::MAX_REPEATS; $i++) {
         $tag_values[md5(rand(1, self::MAX_REPEATS))] = (string) md5(md5(time()));
     }
     // make a comment block
     $comment = $this->randDocBlockStart();
     foreach ($tag_values as $tag => $value) {
         $comment .= $this->randTagValue($tag, $value);
     }
     $comment .= $this->randDocBlockEnd();
     // now parse the comment
     $this->assertTrue($c = new epComment($comment));
     $this->assertTrue($tags = $c->getTags());
     foreach ($tags as $tag => $value) {
         $this->assertTrue($c->getTagValue($tag) == $tag_values[$tag]);
     }
 }
Пример #2
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;
 }
Пример #3
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($value))) {
         throw new epExceptionParser('Cannot parse @orm tag for var [' . $class_var . ']');
         return false;
     }
     // call field map factory to create a field map
     if (!($fm = epFieldMapFactory::make($var, $t->get('type'), $t->get('params')))) {
         return false;
     }
     // set column name if set
     if ($column_name = $t->get('name')) {
         $fm->setColumnName($column_name);
     }
     return $fm;
 }