tomrf/autowire
Composer 安装命令:
composer require tomrf/autowire
包简介
autowire dependency injection from PSR-11 containers
README 文档
README
A simple PHP library that facilitates autowired dependency injection by fetching class constructor dependencies from one or more PSR-11 containers.
Autowire uses the PHP reflection API to peek at constructor parameter types and injects required and optional dependencies from assigned containers.
Installation
Installation via composer:
composer require tomrf/autowire
Usage
$autowire = new \Tomrf\Autowire\Autowire(); $instance = $autowire->instantiateClass(MyClassWithDependencies::class, $container);
Testing
composer test
License
This project is released under the MIT License (MIT). See LICENSE for more information.
Documentation
📂 Tomrf\Autowire\Autowire::class
Minimal class that facilitates dependency injection by autowiring class constructor dependencies from one or more PSR-11 containers.
resolveDependencies()
Returns array of resolved dependencies for a class constructor.
Dependencies are resolved from one or more PSR-11 containers.
Throws AutowireException if a required dependency could not be met using available containers.
public function resolveDependencies( object|string $classOrObject, Psr\Container\ContainerInterface $containers ): array @throws \Tomrf\Autowire\AutowireException @return (null|object)[]
instantiateClass()
Return a new instance of a class after successfully resolving all required dependencies using provided containers.
Throws AutowireException if the class does not exist or if a required dependency could not be met using available containers.
public function instantiateClass( string $class, Psr\Container\ContainerInterface $containers ): object @throws \Tomrf\Autowire\AutowireException
listDependencies()
Returns an array of all dependencies (method parameters) and relevant attributes for a given class or object/callable.
public function listDependencies( object|string $classOrObject, string $methodName = '__construct' ): array @throws \Tomrf\Autowire\AutowireException @return array<string,bool|string>[] Array of parameters with attributes
Generated 2022-06-28T01:41:09+02:00 using 📚tomrf/readme-gen
统计信息
- 总下载量: 639
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-21