PHP code example of bauhaus / service-resolver

1. Go to this page and download the library: Download bauhaus/service-resolver library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bauhaus / service-resolver example snippets




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