PHP code example of widi / service-locator

1. Go to this page and download the library: Download widi/service-locator 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/ */

    

widi / service-locator example snippets



Widi\Components\ServiceLocator\ServiceLocator;

$services = [
    InvokableService::class => [
        'instance' => InvokableService::class,
    ],
    AnotherInvokableService::class => [
        'instance' => InvokableService::class,
        'options' => [
            'factory'   => false,
            'shared'    => false,
            'parameter' => [],
        ],
    ],
    FactoryService::class   => [
        'instance' => ServiceFactory::class,
        'options' => [
            'factory'   => true,
            'parameter' => [],
        ],
    ],
];

$serviceLocator = new ServiceLocator();
$serviceLocator->setArray($services);