Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

looking to list classes with their methods and properties #5

Closed
mackenza opened this issue Aug 29, 2014 · 3 comments
Closed

looking to list classes with their methods and properties #5

mackenza opened this issue Aug 29, 2014 · 3 comments

Comments

@mackenza
Copy link

Hi, I was looking at xref to help me produce an output file of classes in a set of source files, which I can see plainly exists. However, I would also like to nest within those class reports the methods that belong to a specific class and properties of the class.

The current doc plugin group seems to not have a defined way of getting the methods/properties associated with a class. There seems to be a list of classes, a list of methods, and a list of properties, unless I am missing something.

Any idea how I would achieve this? Do I need to write my own plugin set for this?

Thanks... oh and I love this project.

@gariev
Copy link
Owner

gariev commented Aug 30, 2014

Hi Andrew!

Yes, you need to create your own plugin (say, MyPlugin.class.php) and load it via config file:

## xref.ini
[xref]
plugins-dir = /path/to/dir/with/your/plugin
[doc]
plugins[] = MyPlugin

If you're overriding this setting, you may also need to include all default doc plugins

The plugin itself may look something like:

<?php
class MyPlugin extends XRef_APlugin implements XRef_IDocumentationPlugin {

    public function __construct() {
        parent::__construct('my-id', "list of classes with their methods");
    }

    // process each source file
    public function generateFileReport(XRef_IParsedFile $pf) {
        foreach ($pf->getClasses() as $classObj) {
            foreach ($classObj->methods as $methodObj) {
                echo $classObj->name . "::" . $methodObj->name;
                // TODO: save classes/methods names
            }
        }
     }

    // generate total report
    public function generateTotalReport() {

        list($fh, $root) = $this->xref->getOutputFileHandle($this->reportId, null);
        fwrite($fh,
            $this->xref->fillTemplate(
                '<your-template-name-here>.tmpl',
                array(
                    'reportName' => $this->getName(),
                    'reportId'   => $this->getId(),
                    'root'       => $root,
                    // TODO: use saved classes/method names as template params
                )
            )
        );
        fclose($fh);
    } 
}

I haven't tested it yet and oh, you'll need to a template file to produce html output.

Good luck and thanks,
I.

@mackenza
Copy link
Author

thanks for the quick reply and the sample code... I think I see what is going on more now.

One thing I was thinking was in order to get an actual list of all methods of a class, I would need to also retrieve methods of classes ,y class extends and list the ones not overridden by the extending class. I guess I will need to do some recursive logic with getclasses() to do that.

@gariev
Copy link
Owner

gariev commented Aug 30, 2014

Yes, inherited methods require more logic: array $classObj->extends contains names of the parent classes (there can be multiple parents for interfaces and single element for regular classes), but it's name only. The actual definition of the parent class and it's methods can be in file different from current $parsedFile object.
So yes, logic of generateTotalReport() will be more complicated but it's definitely possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants