PHP code example of comphp / service-management

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

    

comphp / service-management example snippets


$services = new CommonPHP\ServiceManager\ServiceManager();

$services->register(MyClass::class);

$instance = $services->get(MyClass::class);

$services->aliases->register(MyInterface::class, MyClass::class);

$services->namespaces->register('MyNamespace');

$services->providers->registerProvider(MyServiceProvider::class);

class MyService implements BootstrapperContract
{
    public function bootstrap(ServiceManager $serviceManager): void
    {
        // Bootstrap logic goes here
    }
}

$services->register(MyService::class);
$instance = $services->get(MyService::class); // MyService's bootstrap method will be called

class MyServiceProvider implements ServiceProviderContract, BootstrapperContract
{
    public function bootstrap(ServiceManager $serviceManager): void
    {
        // Bootstrap logic goes here
    }

    // Implement other methods from ServiceProviderContract...
}

$services->providers->registerProvider(MyServiceProvider::class); // MyServiceProvider's bootstrap method will be called