|
| 1 | +# Annotated Injector |
| 2 | + |
| 3 | +A PHP8 library that will wire an [Auryn Injector](https://github.com/rdlowrey/auryn) based off of objects annotated with |
| 4 | +[Attributes](https://www.php.net/manual/en/language.attributes.php). Aims to provide functionality that enables |
| 5 | +configuring all Injector options through Attributes. |
| 6 | + |
| 7 | +**Supported functionality** |
| 8 | + |
| 9 | +- Share an interface annotated with `Service`. |
| 10 | +- Alias concrete implementations of interfaces annotated with `Service`. |
| 11 | +- Swap out concrete implementations based on environment. For example, run a cloud based storage in production, a |
| 12 | +local filesystem based storage in development, and a virtual filesystem in test. |
| 13 | +- Execute arbitrary methods after service creation by annotating a method with `ServiceSetup` |
| 14 | + |
| 15 | +This is a new library still in active development! Many features are planned for the future... please check out the |
| 16 | +Roadmap for more details on what's coming. Additionally, only the most basic use cases have been tested. It is not |
| 17 | +recommended using this library in production at this time. We're aiming to be production ready soon though! |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +``` |
| 22 | +composer require cspray/annotated-injector |
| 23 | +``` |
| 24 | + |
| 25 | +## Getting Started |
| 26 | + |
| 27 | +For a more complete, working example check out the `examples/` directory. To get this example to work in your environment |
| 28 | +you'd have to move the interface and class definitions into the appropriate directory structure. |
| 29 | + |
| 30 | +```php |
| 31 | +<?php |
| 32 | + |
| 33 | +require __DIR__ . '/vendor/autoload.php'; |
| 34 | + |
| 35 | +// interfaces and classes in src/ |
| 36 | + |
| 37 | +use Cspray\AnnotatedInjector\Attribute\Service; |
| 38 | + |
| 39 | +#[Service] |
| 40 | +interface Foo {} |
| 41 | + |
| 42 | +#[Service] |
| 43 | +class FooImplementation {} |
| 44 | + |
| 45 | +use Cspray\AnnotatedInjector\InjectorDefinitionCompiler; |
| 46 | + |
| 47 | +$compiler = new InjectorDefinitionCompiler(); |
| 48 | +$injectorDefinition = $compiler->compileDirectory(__DIR__ . '/src', 'environment_identifier'); |
| 49 | +$injector = \Cspray\AnnotatedInjector\AnnotatedInjectorFactory::fromInjectorDefinition($injectorDefinition); |
| 50 | + |
| 51 | +var_dump($injector->make(Foo::class)); |
| 52 | +``` |
| 53 | + |
| 54 | +## Roadmap |
| 55 | + |
| 56 | +### 0.1.x |
| 57 | + |
| 58 | +- Compiler to parse Attributes from source directories ... :heavy_check_mark: |
| 59 | +- Factory to create Injector based on parsed Attributes ... :heavy_check_mark: |
| 60 | +- Support methods invoked in Injector::prepares ... :heavy_check_mark: |
| 61 | +- Support defining scalar values on parameters ... :x: |
| 62 | +- Support defining specific Service on parameters ... :x: |
| 63 | + |
| 64 | +### 0.2.x |
| 65 | + |
| 66 | +- Improved conflict resolution when multiple Services could satisfy an alias ... :x: |
| 67 | +- Improve checks against erroneous uses of the library's attributes ... :x: |
| 68 | +- Ensure that complex scenarios that could lead to Injector failure are accounted for ... :x: |
| 69 | + |
| 70 | +### 0.3.x |
| 71 | + |
| 72 | +- Support the concept of a Service factory ... :x: |
| 73 | +- Support serializing and caching InjectorDefinition ... :x: |
| 74 | + |
| 75 | +### 0.4.x |
| 76 | + |
| 77 | +- Support defining scalar values from an arbitrary source ... :x: |
0 commit comments