Skip to content

Latest commit

 

History

History
69 lines (53 loc) · 2.58 KB

extensions.md

File metadata and controls

69 lines (53 loc) · 2.58 KB

Extensions

You might have a custom tasks or event listeners that is not included in the default GrumPHP project. It is possible to group this additional GrumPHP configuration in an extension. This way you can centralize this custom logic in your own extension package and load it wherever you need it.

The configuration looks like this:

# grumphp.yml
grumphp:
    extensions:
        - My\Project\GrumPHPExtension

The configured extension class needs to implement GrumPHP\Extension\ExtensionInterface. Since GrumPHP is using the symfony/dependency-injection internally to configure all resources, a GrumPHP extension can append multiple configuration files to the container configuration.

We support following loaders: YAML, XML, INI, GLOB, DIR. Note: We don't support the PHP or CLOSURE loaders to make sure your extension is compatible with our grumphp-shim PHAR distribution. All dependencies get scoped with a random prefix in the PHAR, making these loaders not usable in there.

Example extension:

<?php
namespace My\Project;

use GrumPHP\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class MyAwesomeGrumPHPExtension implements ExtensionInterface
{
    public function imports(): iterable
    {
        $configDir = dirname(__DIR).'/config';
    
        yield $configDir.'/my-extension.yaml';
        yield $configDir.'/my-extension.xml';
        yield $configDir.'/my-extension.ini';
        yield $configDir.'/my-extension/*';
    }
}

Example config file in which you enable a custom task:

# my-extension.yaml
services:
  My\CustomTask:
    arguments: []
    tags:
      - {name: grumphp.task, task: myCustomTask}

Third Party Extensions

This page lists third party extensions implementing useful GrumPHP tasks.

Did you write your own extension? Feel free to add it to this list!