Skip to content

Commit 7232fe6

Browse files
authored
Implement compile command (#13)
* Implement compile command * use better virtual fs
1 parent 1878d74 commit 7232fe6

Some content is hidden

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

41 files changed

+1695
-536
lines changed

KNOWN_ISSUES.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ a type that's not valid for the parameter it is annotating. Take the following e
1515
```php
1616
<?php
1717

18-
use Cspray\AnnotatedContainer\Attribute\UseScalar;
18+
use Cspray\AnnotatedContainer\Attribute\InjectScalar;
1919
use Cspray\AnnotatedContainer\Attribute\Service;
2020

2121
#[Service]
@@ -24,7 +24,7 @@ class Foo {
2424
private string $bar;
2525

2626
public function __construct(
27-
#[UseScalar(42)]
27+
#[InjectScalar(42)]
2828
string $bar
2929
) {
3030
$this->bar = $bar;
@@ -51,16 +51,16 @@ There are currently multiple ways to define a scalar value on a param; with eith
5151
```php
5252
<?php
5353

54-
use Cspray\AnnotatedContainer\Attribute\UseScalar;
55-
use Cspray\AnnotatedContainer\Attribute\UseScalarFromEnv;
54+
use Cspray\AnnotatedContainer\Attribute\InjectScalar;
55+
use Cspray\AnnotatedContainer\Attribute\InjectEnv;
5656
use Cspray\AnnotatedContainer\Attribute\Service;
5757

5858
#[Service]
5959
class Foo {
6060

6161
public function __construct(
62-
#[UseScalar('user')]
63-
#[UseScalarFromEnv('USER')]
62+
#[InjectScalar('user')]
63+
#[InjectEnv('USER')]
6464
private string $user
6565
) {}
6666

@@ -86,13 +86,13 @@ Take the following example:
8686
```php
8787
<?php
8888

89-
use Cspray\AnnotatedContainer\Attribute\UseScalar;
89+
use Cspray\AnnotatedContainer\Attribute\InjectScalar;
9090
use Cspray\AnnotatedContainer\Attribute\ServicePrepare;
9191

9292
class Foo {
9393

9494
public function __construct(
95-
#[UseScalar('cspray')]
95+
#[InjectScalar('cspray')]
9696
public string $user
9797
) {}
9898

README.md

+26-19
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ at our example but resolve the problem with `FooConsumer` for this specific para
180180
```php
181181
<?php
182182

183-
use Cspray\AnnotatedContainer\Attribute\UseService;
183+
use Cspray\AnnotatedContainer\Attribute\InjectService;
184184
use Cspray\AnnotatedContainer\Attribute\Service;
185185

186186
#[Service]
@@ -201,7 +201,7 @@ class FooConsumer {
201201
private Foo $foo;
202202

203203
public function __construct(
204-
#[UseService(Qux::class)]
204+
#[InjectService(Qux::class)]
205205
Foo $foo
206206
) {
207207
$this->foo = $foo;
@@ -253,7 +253,7 @@ Attribute on the parameter with the desired value. Our previous example, properl
253253
```php
254254
<?php
255255

256-
use Cspray\AnnotatedContainer\Attribute\UseScalar;
256+
use Cspray\AnnotatedContainer\Attribute\InjectScalar;
257257
use Cspray\AnnotatedContainer\Attribute\Service;
258258

259259
#[Service]
@@ -263,9 +263,9 @@ class FooWebClient {
263263
private string $apiSecret;
264264

265265
public function __construct(
266-
#[UseScalar("my-client-id")]
266+
#[InjectScalar("my-client-id")]
267267
string $clientId,
268-
#[UseScalar("my-api-secret")]
268+
#[InjectScalar("my-api-secret")]
269269
string $apiSecret
270270
)
271271
{
@@ -290,7 +290,7 @@ Let's take our previous example and improve it by reading in our client id and s
290290
```php
291291
<?php
292292

293-
use Cspray\AnnotatedContainer\Attribute\UseScalarFromEnv;
293+
use Cspray\AnnotatedContainer\Attribute\InjectEnv;
294294
use Cspray\AnnotatedContainer\Attribute\Service;
295295

296296
#[Service]
@@ -300,9 +300,9 @@ class FooWebClient {
300300
private string $apiSecret;
301301

302302
public function __construct(
303-
#[UseScalarFromEnv('MY_CLIENT_ID')]
303+
#[InjectEnv('MY_CLIENT_ID')]
304304
string $clientId,
305-
#[UseScalarFromEnv('MY_API_SECRET')]
305+
#[InjectEnv('MY_API_SECRET')]
306306
string $apiSecret
307307
) {
308308
$this->clientId = $clientId;
@@ -428,26 +428,33 @@ The following Attributes are made available through this library. All Attributes
428428
### 0.1.x
429429

430430
- Compiler to parse Attributes from source directories ... :heavy_check_mark:
431-
- Factory to create Injector based on parsed Attributes ... :heavy_check_mark:
431+
- Factory to create Container based on parsed Attributes ... :heavy_check_mark:
432432
- Support methods invoked in Injector::prepares ... :heavy_check_mark:
433433
- Support defining scalar values on parameters ... :heavy_check_mark:
434434
- Support defining specific Service on parameters ... :heavy_check_mark:
435435

436436
### 0.2.x
437437

438438
- Support the concept of a Service factory ... :heavy_check_mark:
439-
- Support serializing and caching InjectorDefinition ... :x:
440-
- Improve handling of low-hanging fruit logical errors... :x:
439+
- Support a PSR ContainerInterface Factory ... :heavy_check_mark:
440+
- Support serializing and caching ContainerDefinition ... :x:
441+
- Handle when abstract Service does not have corresponding alias ... :x:
442+
- Handle when an abstract Service might have more than 1 alias ... :x:
443+
- Handle when Attributes on parameters and methods are not annotated with correct class Attributes ... :x:
441444

442445
### 0.3.x
443446

444-
- Support defining scalar values from an arbitrary source ... :x:
445-
- Improve handling of logical errors... :x:
446-
- Harden library for production use ... :x:
447+
- Support for amphp/injector ... :x:
448+
- Support for PrototypeServices, or an unshared Service ... :x:
449+
- Support Profiles instead of Environments ... :x:
450+
451+
### 0.4.x
447452

448-
### 0.4.x and beyond
453+
- Support creating a ContainerDefinition for libraries that can't be Annotated ... :x:
454+
- Support a Service having an explicit name that is not the FQCN ... :x:
455+
- Have convenience functions that abstracts away common boilerplate ... :x:
449456

450-
- Add support for amphp/injector ... :x:
451-
- Support working with identifiers once feature is in amphp/injector ... :x:
452-
- Research potentially supporting other containers ... :question:
453-
- Further improve library's use in production environment ... :x:
457+
### 1.0 and beyond
458+
459+
- Improve handling of logical errors... :x:
460+
- Support defining scalar values from an arbitrary source ... :question_mark:

bin/annotated-container

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require dirname(__DIR__) . '/vendor/autoload.php';
5+
6+
use Symfony\Component\Console\Application;
7+
8+
$app = new Application('annotated-container', '0.1.0');
9+
10+
$app->add(new \Cspray\AnnotatedContainer\Console\CompileContainerCommand(
11+
new \Cspray\AnnotatedContainer\PhpParserContainerDefinitionCompiler(),
12+
new \Cspray\AnnotatedContainer\JsonContainerDefinitionSerializer(),
13+
getcwd()
14+
));
15+
16+
$app->run();

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
"role": "Project Maintainer"
1212
}
1313
],
14+
"bin": ["bin/annotated-container"],
1415
"require": {
1516
"php": "^8.0",
1617
"psr/container": "^2.0",
1718
"rdlowrey/auryn": "^1.4",
18-
"nikic/php-parser": "^4.10"
19+
"nikic/php-parser": "^4.10",
20+
"symfony/console": "^6.0",
21+
"mikey179/vfsstream": "^1.6"
1922
},
2023
"require-dev": {
2124
"phpunit/phpunit": "^9.5"

0 commit comments

Comments
 (0)