示例#1
0
 /**
  * Parse the comment of the class
  * @param epClassMap the class map 
  * @param string the comment of the class
  * @return bool
  */
 protected function parseClassComment(&$cm, $comment)
 {
     if (!($c = new epComment($comment))) {
         throw new epExceptionParser('Cannot parse comment for class [' . $cm->getName() . ']');
         return false;
     }
     // always harvest 'raw' customer tags
     $cm->setTags($c->getTags());
     if (!($value = $c->getTagValue('orm'))) {
         return true;
     }
     if (!($t = new epClassTag())) {
         throw new epExceptionParser('Cannot parse @orm tag for class [' . $cm->getName() . ']');
         return false;
     }
     if (!$t->parse($value)) {
         throw new epExceptionParser('Cannot parse @orm tag for class [' . $cm->getName() . ']');
         return false;
     }
     // database table name
     if ($table = $t->get('table')) {
         // append prefix to table name
         if ($prefix = $this->getConfigOption('table_prefix')) {
             $table = epUnquote($prefix) . $table;
         }
         $cm->setTable($table);
     }
     // dsn of the database
     if ($dsn = $t->get('dsn')) {
         $cm->setDsn($dsn);
     } else {
         $cm->setDsn($this->getConfigOption('default_dsn'));
     }
     // oid column of the class
     if ($oid = $t->get('oid')) {
         $cm->setOidColumn($oid);
     } else {
         $cm->setOidColumn($this->getConfigOption('default_oid_column'));
     }
     return true;
 }
 /**
  * Test class orm tag
  */
 function testClassTag()
 {
     // dsn and table
     $dsn = 'mysql://*****:*****@localhost/ezpdo';
     $table = "mytable";
     $oid = md5(rand(0, 1000000));
     // make a "wild" docblock
     $comment = $this->randDocBlockStart();
     $comment .= $this->randTagValue('@orm', $table . $this->randSpaces() . $dsn . $this->randSpaces() . "oid({$oid})");
     $comment .= $this->randDocBlockEnd();
     // parse orm tag parser
     $c = new epComment($comment);
     $this->assertTrue($c);
     // get orm tag value
     $value = $c->getTagValue('orm');
     $this->assertTrue(stristr($value, $dsn) != false);
     $this->assertTrue(stristr($value, $table) != false);
     // parse tag value
     $this->assertTrue($t = new epClassTag());
     $this->assertTrue(true === $t->parse($value));
     // check dsn
     $this->assertTrue($t->get('dsn') == $dsn);
     $this->assertTrue($t->get('table') == $table);
     $this->assertTrue($t->get('oid') == $oid);
 }