Skip to content

Commit e6fe1e6

Browse files
committed
Initial commit
0 parents  commit e6fe1e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3774
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.
2+
..
3+
.idea
4+
.phpunit.cache
5+
.phpunit.result.cache
6+
build/
7+
vendor/

README.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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:

composer.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "cspray/annotated-injector",
3+
"description": "Create Auryn Injector based off annotated classes and interfaces",
4+
"require": {
5+
"php": "^8.0",
6+
"rdlowrey/auryn": "^1.4",
7+
"nikic/php-parser": "^4.10",
8+
"monolog/monolog": "^2.2"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "^9.5"
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"Cspray\\AnnotatedInjector\\": "src"
16+
}
17+
},
18+
"autoload-dev": {
19+
"psr-4": {
20+
"Cspray\\AnnotatedInjector\\": "test",
21+
"Acme\\AnnotatedInjectorDemo\\": "examples/getting_started/src"
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)