* @version 1.0.0 * @param string $path The path to the file */ function fetch_docblock($path) { // Load and tokenize $source = file_get_contents($path); $tokens = token_get_all($source); // Get the docblock comment $score = 0; foreach ($tokens as $token) { ++$score; if (is_string($token)) { continue; } // Ensure only the first function or class docblock is used list($id, $text) = $token; switch ($id): case T_COMMENT: case T_DOC_COMMENT: $synopsis = $text; $score = -10; break; case T_FUNCTION: case T_CLASS: if ($score == -8) { break 2; } break; default: break; endswitch; } if (!isset($synopsis)) { return false; } // Line ending $synopsis = str_replace("\r", '', $synopsis); $lines = explode("\n", $synopsis); unset($lines[0]); // Grab the lines and bangs $description = array(); $tags = array(); foreach ($lines as $line) { if (substr($line, 0, 4) === ' * @') { $tag = explode(' ', substr($line, 4), 2); if ($tag[0] !== 'param') { $tags[] = $tag; } } else { $description[] = substr($line, 3); } } // Format $synopsis = trim(implode("\n", $description)) . "\n\n"; $synopsis = preg_replace("#([^\n])\n([^\n])#", '\1 \2', $synopsis); $synopsis = preg_replace("#([^\n\n]+)\n\n#", "

\\1

\n", $synopsis); return array($synopsis, $tags); } ?>