views:

32

answers:

2

I'm looking to create an on-site API reference for my framework and application.

Basically, say I have a class file model.class.php:

class Model extends Object {

    ... code here ...

    // Separates results into pages.
    // Returns Paginator object.

    final public function paginate($perpage = 10) {

        ... more code here ...

    }

}

and I want to be able to generate a reference that my developers can refer to quickly in order to know which functions are available to be called. They only need to see the comments directly above each function and the declaration line. Something like this (similar to a C++ header file):

// Separates results into pages.
// Returns Paginator object.

final public function paginate($perpage = 10);

I've done some research and this answer looked pretty good (using Reflection classes), however, I'm not sure how I can keep the comments in.

Any ideas?

EDIT: Sorry, but I want to keep the current comment formatting. Myself and the people who are working on the code hate the verbosity associated with PHPDocumentor. Not to mention a comment-rewrite of the entire project would take years, so I want to preserve just the // comments in plaintext.

+2  A: 

Why don't you just run PHPDocumenter on the code?

PHPDoc is identical to JavaDoc, and will retain all the parameters and comments in the docblock above the function.

EDIT: Since you don't want PHPDoc, I think it would probably be easiest to write a RegEx parser to do it, since Reflection won't provide you with any surrounding comments.

PHP code to get the comment:

if(preg_match("@//(.+)$@",$line,$match)>0)
{
echo "Comment is: ".$match[1];
}
webdestroya
Thanks. What's the regex to get everything between a `//` and a newline?
Lotus Notes
`preg_match("@//(.+)$@",$line,$match)`
webdestroya
Thank you very much for the quick response.
Lotus Notes
@byronh thanks for the upvote!
webdestroya
+1  A: 

this is what phpdoc is for. you comment your code a specific way, following certain rules, and when you're done you run your code through a parser. It outputs exactly what you're looking for.

Galen