Exemplo n.º 1
0
 /**
  * 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*&mdash;\\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];
 }