PHPackages                             tbachert/spi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tbachert/spi

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

tbachert/spi
============

Service provider loading facility

v1.0.5(1y ago)1323.1M—7.2%35Apache-2.0PHPPHP ^8.1

Since Dec 26Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/Nevay/spi)[ Packagist](https://packagist.org/packages/tbachert/spi)[ RSS](/packages/tbachert-spi/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (10)Used By (5)

Service Provider Interface
==========================

[](#service-provider-interface)

Service provider loading facility, inspired by Javas `ServiceLoader`.

Usage in OpenTelemetry PHP
--------------------------

[](#usage-in-opentelemetry-php)

If you are seeing the following message when running `composer` commands, you have probably installed the [`OpenTelemetry PHP SDK`](https://github.com/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](https://opentelemetry.io/docs/languages/php/sdk/#autoloading), you can most likely disable this plugin.

Install
-------

[](#install)

```
composer require tbachert/spi
```

Usage
-----

[](#usage)

### Registering service providers

[](#registering-service-providers)

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

#### Registering via composer.json `extra.spi`

[](#registering-via-composerjson-extraspi)

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

#### Registering via php

[](#registering-via-php)

```
ServiceLoader::register(Example\Service::class, Example\Implementation::class);
```

###### Converting `ServiceLoader::register()` calls to precompiled map

[](#converting-serviceloaderregister-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`

[](#removing-obsolete-entries-from-autoloadfiles)

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

[](#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

[](#loading-service-providers)

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

#### Handling invalid service configurations

[](#handling-invalid-service-configurations)

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

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance57

Moderate activity, may be stable

Popularity57

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~68 days

Total

9

Last Release

414d ago

Major Versions

v0.2.1 → v1.0.02024-06-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d96445384720ee37aa71d5ddd7b5a5d159558200b15b8a1b14e65e6095f2a7a?d=identicon)[tbachert](/maintainers/tbachert)

---

Top Contributors

[![Nevay](https://avatars.githubusercontent.com/u/22509671?v=4)](https://github.com/Nevay "Nevay (20 commits)")[![andypost](https://avatars.githubusercontent.com/u/73713?v=4)](https://github.com/andypost "andypost (1 commits)")

---

Tags

service provider

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tbachert-spi/health.svg)

```
[![Health](https://phpackages.com/badges/tbachert-spi/health.svg)](https://phpackages.com/packages/tbachert-spi)
```

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k199.6M3.4k](/packages/composer-composer)[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k257.0M28.0k](/packages/friendsofphp-php-cs-fixer)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k39.6k](/packages/matomo-matomo)[symfony/asset-mapper

Maps directories of assets &amp; makes them available in a public directory with versioned filenames.

1669.5M285](/packages/symfony-asset-mapper)[drupal/core-composer-scaffold

A flexible Composer project scaffold builder.

5346.5M600](/packages/drupal-core-composer-scaffold)[drupal/core-project-message

Adds a message after Composer installation.

2125.4M213](/packages/drupal-core-project-message)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
