Skip to content

Commit

Permalink
Prioritized Profiles and ContainerFactory improvements (#401)
Browse files Browse the repository at this point in the history
* Prioritized Profiles and ContainerFactory improvements

- Allow for prioritized profile services and injects
- Share code when possible for common ContainerFactory functionality

* Remove readonly class, not allowed in 8.2

* Add new phpunit vendor lib

* Remove override attribute not available in 8.2
  • Loading branch information
cspray authored Dec 14, 2024
1 parent 4d533e8 commit 2dab801
Show file tree
Hide file tree
Showing 76 changed files with 1,640 additions and 1,382 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Composer (Annotated Container)
run: composer install
- name: Composer (Static Analysis Tools)
- name: Composer (Code Linting)
run: cd tools/labrador-cs && composer install
- name: Code Linting
run: phpcs -q --standard=./tools/labrador-cs/vendor/cspray/labrador-coding-standard/ruleset.xml --exclude=Generic.Files.LineLength --report=checkstyle src test | cs2pr
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A Dependency Injection framework for creating an autowired, feature-rich, [PSR-1
- Use Profiles to easily use different services in different runtimes
- Create type-safe, highly flexible configuration objects
- Easily include third-party services that cannot be easily annotated
- Bring Your Own Container!
- Support for a variety of different Dependency Injection containers

## Quick Start

Expand Down Expand Up @@ -70,18 +70,18 @@ Be sure to review the generated configuration! A "normal" Composer setup might r

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<annotatedContainer xmlns="https://annotated-container.cspray.io/schema/annotated-container.xsd">
<annotatedContainer xmlns="https://annotated-container.cspray.io/schema/annotated-container.xsd" version="3.0">
<scanDirectories>
<source>
<dir>src</dir>
<dir>tests</dir>
</source>
</scanDirectories>
<cacheDir>.annotated-container-cache</cacheDir>
</annotatedContainer>
```

Now, bootstrap your Container in your app.
Now, bootstrap your Container in your app. In this example, we're going to assume that you
have `php-di/php-di` installed.

```php
<?php declare(strict_types=1);
Expand All @@ -92,16 +92,17 @@ require __DIR__ . '/vendor/autoload.php';
use Cspray\AnnotatedContainer\Bootstrap\Bootstrap;
use Cspray\AnnotatedContainer\Event\Emitter;
use Cspray\AnnotatedContainer\Profiles;
use Cspray\AnnotatedContainer\ContainerFactory\PhpDiContainerFactory;

$emitter = new Emitter();

// Add whatever Listeners are required for your application

// Include other active profiles in this list
// If the only active profile is default you can call this method without any arguments
$container = Bootstrap::from($emitter)->bootstrapContainer(
Profiles::fromList(['default'])
);
$container = Bootstrap::fromAnnotatedContainerConventions(
new PhpDiContainerFactory($emitter), $emitter
)->bootstrapContainer(Profiles::fromList(['default']));

$storage = $container->get(BlobStorage::class); // instanceof FilesystemStorage
```
Expand Down
Loading

0 comments on commit 2dab801

Please sign in to comment.