Skip to content

5. Plugins

Marco Muths edited this page Sep 13, 2015 · 8 revisions

Write your own Namespace Filter

Just implement PhpDA\Parser\Filter\NamespaceFilterInterface to your filter class to modify the namespace of collected dependencies.

After that you can set it in the configuration.

How to add plugins to composer autoloader?

Write your own Reference Validator

Just implement PhpDA\Reference\ValidatorInterface to your reference validator class to verify each dependency.

After that you can set it in the configuration. See here for instance.

How to add plugins to composer autoloader?

Write your own Visitors

Visitors are provided by Visitor-Pattern implemented by Nikic's Php-Parser. Read the docs to get into the idea of visitor.

To get your own visitor, just create a new one by extending PhpDA\Parser\Visitor\AbstractVisitor. Beside this you have to implement one of the following Interfaces to declare the concern by contract:

  • PhpDA\Parser\Visitor\Feature\UsedNamespaceCollectorInterface
  • PhpDA\Parser\Visitor\Feature\UnsupportedNamespaceCollectorInterface
  • PhpDA\Parser\Visitor\Feature\NamespacedStringCollectorInterface

After that you can add it to the configuration.

How to add plugins to composer autoloader?

Write your own Formatters

To get your own Formatter to create other reports, just implement PhpDA\Writer\Strategy\StrategyInterface to a new one.

After that you can set it in the configuration.

How to add plugins to composer autoloader?

How to add plugins to composer autoloader?

Adding classes to the composer autoloader mapping is well defined here.

For instance your plugin has the FQCN MyPhpDA\MyPlugin and is located in path/to/src/MyPhpDA/MyPlugin.php. In this case you have to add the reference in your composer.json:

{
    "autoload-dev": {
        "psr-0": {
            "MyPhpDA\\": "path/to/src/"
        }
    }
}

After that you have to execute a composer update to regenerate the autoloader map:

composer update -o

Clone this wiki locally