Service provider loading facility, inspired by Javas ServiceLoader.
If you are seeing the following message when running composer commands, you have probably installed the
OpenTelemetry PHP SDK.
tbachert/spi contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "tbachert/spi" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]
The OpenTelemetry SDK uses this plugin to provide its extensible configuration format. If you are not using SDK autoconfiguration, you can most likely disable this plugin.
composer require tbachert/spiService provider implementations must provide a public zero-arguments constructor.
composer config --json --merge extra.spi.Example\\Service '["Example\\Implementation"]'ServiceLoader::register(Example\Service::class, Example\Implementation::class);ServiceLoader::register() calls can be converted to a precompiled map by setting extra.spi-config.autoload-files to
trueto process allautoload.files(should be used iffautoload.filesis used exclusively for service provider registration),- or a list of files that register service providers.
composer config --json extra.spi-config.autoload-files trueBy default, extra.spi-config.autoload-files files that register service providers are removed from
autoload.files. This behavior can be configured by setting extra.spi-config.prune-autoload-files to
trueto remove allexra.spi-config.autoload-filesfiles fromautoload.files,falseto keep allautoload.filesentries,- or a list of files that should be removed from
autoload.files.
Make sure to allow the composer plugin to be able to load service providers.
composer config allow-plugins.tbachert/spi trueforeach (ServiceLoader::load('Namespace\Service') as $provider) {
// ...
}$loader = ServiceLoader::load('Namespace\Service');
for ($it = $loader->getIterator(); $it->valid(); $it->next()) {
try {
$provider = $it->current();
} catch (ServiceConfigurationError) {}
}