Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Spi Laravel Package

tbachert/spi

Composer-powered Service Provider Interface loader inspired by Java’s ServiceLoader. Register providers via composer.json extra.spi or PHP, optionally precompile registrations from autoload files, and load implementations at runtime. Used by OpenTelemetry PHP SDK autoconfiguration.

View on GitHub
Deep Wiki
Context7

Service Provider Interface

Service provider loading facility, inspired by Javas ServiceLoader.

Usage in OpenTelemetry PHP

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.

Install

composer require tbachert/spi

Usage

Registering service providers

Service provider implementations must provide a public zero-arguments constructor.

Registering via composer.json extra.spi

composer config --json --merge extra.spi.Example\\Service '["Example\\Implementation"]'

Registering via php

ServiceLoader::register(Example\Service::class, Example\Implementation::class);
Converting ServiceLoader::register() calls to precompiled map

ServiceLoader::register() calls can be converted to a precompiled map by setting extra.spi-config.autoload-files to

  • true to process all autoload.files (should be used iff autoload.files is used exclusively for service provider registration),
  • or a list of files that register service providers.
composer config --json extra.spi-config.autoload-files true
Removing obsolete entries from autoload.files

By 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

  • true to remove all exra.spi-config.autoload-files files from autoload.files,
  • false to keep all autoload.files entries,
  • or a list of files that should be removed from autoload.files.

Application authors

Make sure to allow the composer plugin to be able to load service providers.

composer config allow-plugins.tbachert/spi true

Loading service providers

foreach (ServiceLoader::load('Namespace\Service') as $provider) {
    // ...
}

Handling invalid service configurations

$loader = ServiceLoader::load('Namespace\Service');
for ($it = $loader->getIterator(); $it->valid(); $it->next()) {
    try {
        $provider = $it->current();
    } catch (ServiceConfigurationError) {}
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport