bauhaus / service-resolver
Yet another PSR-11 implementation
v0.2.0
2022-02-21 07:39 UTC
Requires
- php: ^8.1
- psr/container: ^2.0.2
Requires (Dev)
- phpunit/phpunit: ^9.5
README
Warning! This package won't worry about backward compatibily for
v0.*
.
Service Locator
Yet another service resolver (aka service container) implementation following PSR-11 Container interface.
Installation
$ composer require bauhaus/service-resolver
Using it
<?php use Bauhaus\ServiceResolverSettings; $psrContainer = ServiceResolverSettings::new() ->withDefintionFiles( 'path/file-1.php', 'path/file-2.php', ) ->withServices([ 'service-id-1' => fn () => YourService(), // lazy loaded 'service-id-2' => new YourService(), ]) ->withDiscoverableNamespaces( 'App\\Namespace1', 'App\\Namespace2', ) ->build(); $psrContainer->has($serviceId); $psrContainer->get($serviceId);