<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thecodingmachine / service-provider-registry example snippets
$registry = new Registry();
$key = $registry->push(MyServiceProvider::class);
// This will trigger the creation of the MyServiceProvider object and return it.
$serviceProvider = $registry[$key];
$registry = new Registry();
$key = $registry->push(MyServiceProvider::class, "param1", "param2");
$registry = new Registry();
// This is possible, even if we loose the interest of the Registry.
$key = $registry->push(new MyServiceProvider());
$registry = new Registry([
MyServiceProvider::class, // Is you simply want to create an instance without passing parameters
[ MyServiceProvider2::class, [ "param1", "param2 ] ], // Is you simply want to create an instance and pass parameters to the constructor
new MyServiceProvider4('foo') // If you directly want to push the constructed instance.
]);
foreach ($registry as $serviceProvider) {
// Do stuff for each service provider.
// Service providers will be instantiated on the fly if needed.
}
$registry = new Registry([], TheCodingMachine\Discovery::getInstance());
// The registry now contains all the service providers discoverable by thecodingmachine/discovery.