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-09-08 17:15:19 UTC
README
允许您通过特定的注解将类注册为服务。
用法
注册扩展
extensions: discovery: BrandEmbassy\Nette\DI\Extensions\AnnotationExtension('%tempDir%')
设置扩展
in
定义了扩展将在其中搜索可能服务的目录。
files
是可选的(默认 *.php
)并定义了扩展通过该文件模式搜索可能服务的模式
discovery: in: '%appDir%' files: '*.php' excludeClasses: # optional - regex pattern to exclude classes from discovery - '/.*Test$/'
将 discovery
注解添加到您的服务类中
<?php declare(strict_types = 1); namespace AwesomeApp; /** * @discovery */ class AwesomeService { /* ... */ }
与 doctrine 注解映射的兼容性
在您的应用程序引导文件中排除注解
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName(\BrandEmbassy\Nette\DI\Extensions\AnnotationExtension::ANNOTATION_NAME);