/** * Parses a class from supplied filename * @method parseFromFile * @param string filename * @returns true if successful, false otherwise */ function parseFromFile($filename) { $success = false; if (file_exists($filename) && is_readable($filename)) { $arrContents = file($filename); $parsing = false; $parsingBlocks = array(); $tempBlock = array(); foreach ($arrContents as $line) { if (trim($line) == "/**") { $parsing = true; $blockstart = true; } elseif ($parsing && trim($line) == "*/") { $parsing = false; $parsingBlocks[] = $tempBlock; $tempBlock = array(); } else { if ($parsing) { if ($blockstart) { $tempBlock[] = $line; $blockstart = false; } else { $tempBlock[] = $line; } } } } foreach ($parsingBlocks as $blockLines) { $block = array(); foreach ($blockLines as $line) { $str = strstr($line, "@"); $str = substr($str, 1); if ($str !== false) { $separatorPos = strpos($str, " ") && strpos($str, "\t") ? min(strpos($str, " "), strpos($str, "\t")) : (strpos($str, " ") ? strpos($str, " ") : (strpos($str, "\t") ? strpos($str, "\t") : strlen($str))); $name = trim(substr($str, 0, $separatorPos)); $value = trim(substr($str, $separatorPos)); } else { $name = "description"; $value = trim($line); } if ($name == "param" || $name == "description") { $block[$name][] = $value; } else { $block[$name] = $value; } } //print("<pre>"); //print_r($block); //print("</pre>"); if (array_key_exists("method", $block)) { $tempMethod = new Method($block["method"]); unset($block["method"]); if (isset($block["param"]) && is_array($block["param"])) { foreach ($block["param"] as $param) { $tempMethod->setParam($param, ""); } } unset($block["param"]); foreach ($block as $name => $value) { $tempMethod->setInfo($name, $value); } $this->setMethod($tempMethod); } elseif (array_key_exists("class", $block)) { $this->setInfo("name", $block["class"]); unset($block["class"]); foreach ($block as $name => $value) { $this->setInfo($name, $value); } } } $success = true; } return $success; }