brandembassy / nette-di-annotation-extension
1.4-beta
2024-02-08 15:29 UTC
Requires
- php: >=8.1
- nette/di: ^3.1
- nette/robot-loader: ^3.4
Requires (Dev)
- brandembassy/coding-standard: ^11.0
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2024-12-08 17:45:50 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);