noccylabs/service-tags-bundle

$ git tag
0.1.0

$ git branch
* master

NoccyLabs ServiceTagsBundle

This bundle adds some magic tags to abstract working with self-registering extensions, such as plugins or modules that use the service container to publish themselves to a manager.

Installation

$ composer require noccylabs/service-tags-bundle

Using the servicetag.bind tag

This example shows how you could register a set of file readers to a generic reader class. Assuming an interface and implementation like this:

interface FileReaderInterface {
    public function read($filename);
}

class XmlFileReader implements FileReaderInterface {
    ...
}

class FileReaderService {
    public function registerReader(FileReaderInterface $reader, $extension, $options) {
        ...
    }
}

And using the following service definitions:

services:
    vendor.filereader:
        class:  FileReaderService
        tags:
            - { name:servicetag.bind, tag:filereader.reader, call:registerReader, args:[extension,options] }

    filereader.xml:
        tags:   XmlFileReader
            - { name:filereader.reader, extension:xml, options:{ local:true, remote:true } }

You would get the following method call on your service:

$filereader->addMethodCall("registerReader", $xmlfilereader, "xml", [ "local"=>true, "remote"=>true ]);