/** * 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; }
/** * Fetches the page from the specified file and parses it for information about the function * * @return array an array of the type and other information. * @throws PC_PHPRef_Exception if it failed */ public function get_method() { $content = file_get_contents($this->file); $funcname = preg_replace('/^.*?function\\.(.*?)\\.html$/', '\\1', $this->file); $funcname = str_replace('-', '_', $funcname); // check whether this function is just an alias or deprecated $match = array(); if (preg_match('/<p class="refpurpose">(.*?)<\\/p>/s', $content, $match)) { $match = strip_tags($match[1]); $alias = array(); $res = preg_match('/' . preg_quote($funcname, '/') . '\\s*—\\s*Alias\\s*of\\s*' . '(?:([a-zA-Z0-9_]+)(?:::|->))?([a-zA-Z0-9_]+)/s', $match, $alias); if ($res) { return array('alias', $funcname, $alias[1], $alias[2]); } if (preg_match('/\\[deprecated\\]/', $match)) { return array('deprecated', $funcname); } } // find method-description $matches = array(); $res = preg_match_all('/<div class="(?:methodsynopsis|constructorsynopsis) dc-description">(.*?)<\\/div>/s', $content, $matches); if (!$res) { return array(); } // find version-information $vinfo = ''; $vmatch = array(); if (preg_match('/<p class="verinfo">\\s*\\((.*?)\\)\\s*<\\/p>/', $content, $vmatch)) { $vinfo = trim($vmatch[1]); } $methods = array(); foreach (array_keys($matches[0]) as $k) { $methods[] = PC_PHPRef_Utils::parse_method_desc($this->file, $matches[1][$k]); } $version = PC_PHPRef_Utils::parse_version($vinfo); // if we've found more than one synopsis, we have to merge them into one. this is, of course, // not perfect, but adding multiple methods with the same name would break the current concept if (count($methods) > 1) { $method = PC_PHPRef_Utils::merge_methods($methods); $method->get_version()->set($version['min'], $version['max']); return array($methods[0][0], $methods[0][1], $method); } $methods[0][2]->get_version()->set($version['min'], $version['max']); return $methods[0]; }