brandembassy/nette-di-annotation-extension

1.4-beta 2024-02-08 15:29 UTC

README

Allows you to register class as a service via specific annotation.

Usage

Register extension

extensions:
    discovery: BrandEmbassy\Nette\DI\Extensions\AnnotationExtension('%tempDir%')    

Set up extension

in defines a directory in which the extension will search for possible services.

files is optional (default *.php) and defines a file pattern ny which the extension searches for a possible service

discovery:
    in: '%appDir%'
    files: '*.php'
    excludeClasses: # optional - regex pattern to exclude classes from discovery
        - '/.*Test$/'

Add discovery annotation to your service classes

<?php declare(strict_types = 1);

namespace AwesomeApp;

/**
 * @discovery
 */
class AwesomeService
{
    /* ... */
}

Compatibility with doctrine annotation mapping

Exclude annotation in bootstrap file of your application

\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName(\BrandEmbassy\Nette\DI\Extensions\AnnotationExtension::ANNOTATION_NAME);