https://github.com/bauhausphp/service-resolver
https://github.com/bauhausphp/service-resolver
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bauhausphp/service-resolver
- Owner: bauhausphp
- License: mit
- Created: 2021-02-25T20:11:00.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-22T22:40:39.000Z (over 3 years ago)
- Last Synced: 2025-05-16T11:37:55.750Z (about 1 year ago)
- Language: PHP
- Size: 67.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status]](https://github.com/bauhausphp/service-resolver/actions)
[![Coverage]](https://coveralls.io/github/bauhausphp/service-resolver?branch=main)
[![Stable Version]](https://packagist.org/packages/bauhaus/service-resolver)
[![Downloads]](https://packagist.org/packages/bauhaus/service-resolver)
[![PHP Version]](composer.json)
[![License]](LICENSE)
[Build Status]: https://img.shields.io/github/workflow/status/bauhausphp/service-resolver/CI?style=flat-square
[Coverage]: https://img.shields.io/coveralls/github/bauhausphp/service-resolver?style=flat-square
[Stable Version]: https://img.shields.io/packagist/v/bauhaus/service-resolver?style=flat-square
[Downloads]: https://img.shields.io/packagist/dt/bauhaus/service-resolver?style=flat-square
[PHP Version]: https://img.shields.io/packagist/php-v/bauhaus/service-resolver?style=flat-square
[License]: https://img.shields.io/github/license/bauhausphp/service-resolver?style=flat-square
> **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](https://www.php-fig.org/psr/psr-11/).
## Installation
```sh
$ composer require bauhaus/service-resolver
```
## Using it
```php
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);
```