PHPackages                             wikimedia/services - 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. wikimedia/services

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wikimedia/services
==================

Generic service to manage named services using lazy instantiation based on instantiator callback functions

4.0.0(1y ago)2466.4k↑31.3%2GPL-2.0-or-laterPHPPHP &gt;=7.4.3

Since Jul 16Pushed 2mo agoCompare

[ Source](https://github.com/wikimedia/mediawiki-libs-Services)[ Packagist](https://packagist.org/packages/wikimedia/services)[ Docs](https://www.mediawiki.org/wiki/Services_(PHP_library))[ RSS](/packages/wikimedia-services/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (9)Versions (6)Used By (2)

[![Latest Stable Version](https://camo.githubusercontent.com/24d8903f8b381718acd847d065eefcfa2f7973059f22bebabcf54fc34568c162/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f73657276696365732f762f737461626c652e737667)](https://packagist.org/packages/wikimedia/services) [![License](https://camo.githubusercontent.com/2b308efa8aa815bf757e5bdce0398974aadae92432e866a6c9bcb2dae9936b5d/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f73657276696365732f6c6963656e73652e737667)](https://packagist.org/packages/wikimedia/services)

Services
========

[](#services)

A [PSR-11](https://www.php-fig.org/psr/psr-11/)-compliant services framework. Services are created by instantiators (callables), which are usually defined in separate wiring files.

Usage
-----

[](#usage)

```
$services = new ServiceContainer();

$services->defineService(
    'MyService',
    static function ( ServiceContainer $services ): MyService {
        return new MyService();
    }
);

$services->loadWiringFiles( [
    'path/to/ServiceWiring.php',
] );
```

Where `ServiceWiring.php` looks like this:

```
return [

    'MyOtherService' => static function ( ServiceContainer $services ): MyOtherService {
        return new MyOtherService( $services->get( 'MyService' ) );
    },

    // ...

];
```

Each instantiator receives the service container as the first argument, from which it may retrieve further services as needed. Additional arguments for each instantiator may be specified when constructing the `ServiceContainer`.

Custom subclasses of `ServiceContainer`may offer easier access to certain services:

```
class MyServiceContainer extends ServiceContainer {

    public function getMyService(): MyService {
        return $this->get( 'MyService' );
    }

    public function getMyOtherService(): MyOtherService {
        return $this->get( 'MyOtherService' );
    }

}

// ServiceWiring.php
return [

    'MyOtherService' => static function ( MyServiceContainer $services ): MyOtherService {
        return new MyOtherService( $services->getMyService() );
    },

];
```

Running tests
-------------

[](#running-tests)

```
composer install --prefer-dist
composer test

```

History
-------

[](#history)

This library was first introduced in [MediaWiki 1.27](https://www.mediawiki.org/wiki/MediaWiki_1.27) ([I3c25c0ac17](https://gerrit.wikimedia.org/r/264403)). It was split out of the MediaWiki codebase and published as an independent library during the [MediaWiki 1.33](https://www.mediawiki.org/wiki/MediaWiki_1.33) and [MediaWiki 1.34](https://www.mediawiki.org/wiki/MediaWiki_1.34) development cycles.

---

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance65

Regular maintenance activity

Popularity38

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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 ~485 days

Total

5

Last Release

556d ago

Major Versions

1.0.0 → 2.0.02020-06-28

2.0.1 → 3.0.02022-07-09

3.0.0 → 4.0.02024-11-08

PHP version history (3 changes)1.0.0PHP &gt;=5.6.99

2.0.0PHP &gt;=7.2.9

4.0.0PHP &gt;=7.4.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/b94d9718c06ec7c3fd7a104bc44966fb7464b9ec7411582343ea35a7a6a85f08?d=identicon)[mediawiki](/maintainers/mediawiki)

![](https://www.gravatar.com/avatar/716c86d71cbf921e7912a505f89d799de398fc0a3af0bd4c8862834b2d642bd7?d=identicon)[wikimedia](/maintainers/wikimedia)

![](https://www.gravatar.com/avatar/f281fc1a5701e1e7002129e0198e12bff5c8ce049377bf1f75b022d588a5bd94?d=identicon)[legoktm](/maintainers/legoktm)

---

Top Contributors

[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (10 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (7 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (6 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (6 commits)")[![thiemowmde](https://avatars.githubusercontent.com/u/6576639?v=4)](https://github.com/thiemowmde "thiemowmde (5 commits)")[![lucaswerkmeister](https://avatars.githubusercontent.com/u/2346599?v=4)](https://github.com/lucaswerkmeister "lucaswerkmeister (4 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (3 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (1 commits)")[![MaxSem](https://avatars.githubusercontent.com/u/1260606?v=4)](https://github.com/MaxSem "MaxSem (1 commits)")[![AaronSchulz](https://avatars.githubusercontent.com/u/1020708?v=4)](https://github.com/AaronSchulz "AaronSchulz (1 commits)")[![ayg](https://avatars.githubusercontent.com/u/940446?v=4)](https://github.com/ayg "ayg (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikimedia-services/health.svg)

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

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

705122.9M10.1k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31178.1M2.0k](/packages/illuminate-container)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)

PHPackages © 2026

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