Пример #1
0
 /**
  * Declares an interface
  * 
  * @param string $name the name
  * @param array $extends an array of extended interface-names
  * @param array $stmts an array of statements from the interface-body
  */
 public function declare_interface($name, $extends, $stmts)
 {
     $class = new PC_Obj_Class($this->get_file(), $this->get_last_class_line());
     $class->set_name($name);
     $class->set_interface(true);
     $class->set_abstract(true);
     foreach ($extends as $if) {
         $class->add_interface($if);
     }
     $this->handle_class_stmts($class, $stmts);
     $this->env->get_types()->add_classes(array($class));
 }
Пример #2
0
 /**
  * Fetches the page from the specified file and parses it for information about the class
  * 
  * @return PC_Obj_Class the class that was foudn
  * @throws PC_PHPRef_Exception if it failed
  */
 public function get_class()
 {
     $match = array();
     $content = file_get_contents($this->file);
     if (!preg_match('/<strong class="classname">(.*?)<\\//s', $content, $match)) {
         throw new PC_PHPRef_Exception('Unable to find class-name in file "' . $this->file . '"');
     }
     $name = $match[1];
     $class = new PC_Obj_Class($this->file, 0);
     $class->set_name($name);
     // determine super-class
     $res = preg_match('/<span class="modifier">extends<\\/span>\\s*<a href=".*?" class=".*?">(.*?)<\\/a>/s', $content, $match);
     if ($res) {
         $class->set_super_class($match[1]);
     }
     // determine interfaces
     $matches = array();
     $res = preg_match_all('/<span class="interfacename"><a href=".*?" class=".*?">(.*?)<\\/a><\\/span>/s', $content, $matches);
     if ($res) {
         foreach (array_keys($matches[0]) as $k) {
             $class->add_interface($matches[1][$k]);
         }
     }
     if (preg_match('/<h2 class="title">Interface synopsis<\\/h2>/s', $content)) {
         $class->set_interface(true);
     }
     // TODO
     $class->set_abstract(false);
     $class->set_final(false);
     if (preg_match_all('/<div class="fieldsynopsis">(.*?)<\\/div>/s', $content, $matches)) {
         foreach (array_keys($matches[0]) as $k) {
             $obj = PC_PHPRef_Utils::parse_field_desc($matches[1][$k]);
             if ($obj instanceof PC_Obj_Field) {
                 $class->add_field($obj);
             } else {
                 if ($obj instanceof PC_Obj_Constant) {
                     $class->add_constant($obj);
                 }
             }
         }
     }
     if (preg_match_all('/<div class="constructorsynopsis dc-description">(.*?)<\\/div>/s', $content, $matches)) {
         foreach (array_keys($matches[0]) as $k) {
             list(, , $method) = PC_PHPRef_Utils::parse_method_desc($this->file, $matches[1][$k]);
             $class->add_method($method);
         }
     }
     if (preg_match_all('/<div class="methodsynopsis dc-description">(.*?)<\\/div>/s', $content, $matches)) {
         foreach (array_keys($matches[0]) as $k) {
             list(, , $method) = PC_PHPRef_Utils::parse_method_desc($this->file, $matches[1][$k]);
             $class->add_method($method);
         }
     }
     // find version-information
     $vinfo = '';
     $vmatch = array();
     if (preg_match('/<p class="verinfo">\\s*\\((.*?)\\)\\s*<\\/p>/', $content, $vmatch)) {
         $vinfo = trim($vmatch[1]);
     }
     $version = PC_PHPRef_Utils::parse_version($vinfo);
     $class->get_version()->set($version['min'], $version['max']);
     return $class;
 }
Пример #3
0
 /**
  * Builds an instance of PC_Obj_Class from the given row
  *
  * @param array $row the row from the db
  * @param int $pid the project-id
  * @param bool $lazy whether to load it lazy
  * @return PC_Obj_Class the class
  */
 private function build_class($row, $pid, $lazy = true)
 {
     $c = new PC_Obj_Class($row['file'], $row['line'], $row['id'], $pid, $lazy);
     $c->set_name($row['name']);
     $c->set_super_class($row['superclass']);
     $c->set_abstract($row['abstract']);
     $c->set_interface($row['interface']);
     $c->set_final($row['final']);
     $c->get_version()->set(unserialize($row['min_version']), unserialize($row['max_version']));
     foreach (FWS_Array_Utils::advanced_explode(',', $row['interfaces']) as $if) {
         $c->add_interface($if);
     }
     return $c;
 }