phpolar / property-injector
Provides automatic dependency injection for properties.
1.1.0
2023-09-02 19:49 UTC
Requires
- php: >=8.1
- phpolar/property-injector-contract: ^1.0
- psr/container: ^2.0
Requires (Dev)
- ext-ast: *
- ext-openssl: *
- phan/phan: ^5.4
- php-coveralls/php-coveralls: ^2.5
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: 10.3.2
- squizlabs/php_codesniffer: ^3.7
Provides
This package is auto-updated.
Last update: 2024-12-01 20:34:13 UTC
README
Property Injector
Provides automatic dependency injection for properties.
Quick Start
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 Documentation
Thresholds
- Note: Does not include comments.