예제 #1
0
 /**
  * @see FWS_Module::run()
  */
 public function run()
 {
     $tpl = FWS_Props::get()->tpl();
     if (!$this->class) {
         $this->report_error();
         return;
     }
     $curl = PC_URL::get_mod_url();
     $classname = $this->class->get_name();
     // build class-declaration
     $declaration = '';
     if (!$this->class->is_interface()) {
         if ($this->class->is_abstract()) {
             $declaration .= 'abstract ';
         } else {
             if ($this->class->is_final()) {
                 $declaration .= 'final ';
             }
         }
         $declaration .= 'class ';
     } else {
         $declaration .= 'interface ';
     }
     $declaration .= $classname . ' ';
     if (!$this->class->is_interface() && ($cn = $this->class->get_super_class())) {
         $declaration .= 'extends <a href="' . $curl->set('name', $cn)->to_url() . '">' . $cn . '</a> ';
     }
     if (count($this->class->get_interfaces()) > 0) {
         $declaration .= !$this->class->is_interface() ? 'implements ' : 'extends ';
         foreach ($this->class->get_interfaces() as $if) {
             $declaration .= '<a href="' . $curl->set('name', $if)->to_url() . '">' . $if . '</a>, ';
         }
         $declaration = FWS_String::substr($declaration, 0, -1);
     }
     $declaration = FWS_String::substr($declaration, 0, -1) . ';';
     $tpl->add_variables(array('classname' => $classname, 'declaration' => $declaration));
     $classfile = $this->class->get_file();
     // constants
     $consts = array();
     foreach ($this->class->get_constants() as $const) {
         $consts[] = array('name' => $const->get_name(), 'type' => $const->get_type(), 'line' => $const->get_line(), 'url' => $this->get_url($classfile, $const));
     }
     $tpl->add_variable_ref('consts', $consts);
     // fields
     $fields = array();
     $cfields = $this->class->get_fields();
     ksort($cfields);
     foreach ($cfields as $field) {
         $fields[] = array('name' => $field->get_name(), 'type' => (string) $field, 'line' => $field->get_line(), 'url' => $this->get_url($classfile, $field));
     }
     $tpl->add_variable_ref('fields', $fields);
     // methods
     $methods = array();
     $cmethods = $this->class->get_methods();
     ksort($cmethods);
     foreach ($cmethods as $method) {
         $methods[] = array('name' => $method->get_name(), 'type' => $method->__ToString(), 'line' => $method->get_line(), 'url' => $this->get_url($classfile, $method), 'since' => implode(', ', $method->get_version()->get_min()), 'till' => implode(', ', $method->get_version()->get_max()));
     }
     $tpl->add_variable_ref('methods', $methods);
     if ($this->class->get_file() && $this->class->get_line()) {
         $source = PC_Utils::highlight_file($this->class->get_file());
     } else {
         $source = '';
     }
     $tpl->add_variables(array('source' => $source, 'file' => $this->class->get_file(), 'line' => $this->class->get_line(), 'since' => implode(', ', $this->class->get_version()->get_min()), 'till' => implode(', ', $this->class->get_version()->get_max())));
 }
예제 #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;
 }