phpolar/property-injector

提供属性的自动依赖注入。

1.1.0 2023-09-02 19:49 UTC

This package is auto-updated.

Last update: 2024-08-28 01:55:42 UTC


README

属性注入器

提供属性的自动依赖注入。

Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require PHP Build Latest and Nightly PHPMD

快速开始

class Example1
{
    /**
     * Will set this property with the
     * value in the DI container
     * that is registered with 'DEPENDENCY_ID'
     */
    #[Inject("DEPENDENCY_ID")]
    public string $property;
}

class Example2
{
    /**
     * Will set this property with the
     * value in the DI container
     * that is registered with the claass name
     * in the type hint
     */
    #[Inject]
    public SomeDependency $property;
}

class Example3
{
    /**
     * Will ignore protected properties.
     */
    #[Inject]
    protected SomeDependency $property;

    /**
     * Will ignore private properties.
     */
    #[Inject]
    private SomeDependency $property;
}

$injectee = new Example1();
(new PropertyInjector($psr11Container))->inject($injectee);

$injectee->property === $psr11Container->get("DEPENDENCY_ID"); // true

API 文档

阈值

  • 注意:不包括注释。