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(10mo ago)915.1M—1.2%23Apache-2.0PHPPHP ^8.1

Since Dec 26Pushed 3mo ago2 watchersCompare

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

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

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

53

—

FairBetter than 97% of packages

Maintenance67

Regular maintenance activity

Popularity55

Moderate usage in the ecosystem

Community18

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

323d 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

[orchestra/canvas

Code Generators for Laravel Applications and Packages

20917.2M158](/packages/orchestra-canvas)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)[symfony/asset-mapper

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

1656.9M131](/packages/symfony-asset-mapper)[mglaman/composer-drupal-lenient

1317.4M15](/packages/mglaman-composer-drupal-lenient)[drupal/core-composer-scaffold

A flexible Composer project scaffold builder.

5341.9M446](/packages/drupal-core-composer-scaffold)[drupal/core-project-message

Adds a message after Composer installation.

2122.6M172](/packages/drupal-core-project-message)

PHPackages © 2026

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