bauhaus/service-resolver

Yet another PSR-11 implementation

v0.2.0 2022-02-21 07:39 UTC

This package is auto-updated.

Last update: 2024-04-23 01:24:48 UTC


README

Build Status Coverage

Stable Version Downloads PHP Version License

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);