1

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?

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 Answers 2

2

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];
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. What's the regex to get everything between a // and a newline?
preg_match("@//(.+)$@",$line,$match)
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.