brandembassy/nette-di-annotation-extension

1.4-beta 2024-02-08 15:29 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);