PHPackages                             echo-fusion/servicemanager - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. echo-fusion/servicemanager

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

echo-fusion/servicemanager
==========================

A flexible service management package for PHP applications, providing service registration, lazy loading, and configurable dependency injection support.

v2.1.0(1y ago)18MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0

Since Oct 1Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (6)Versions (7)Used By (0)

Service manager
===============

[](#service-manager)

The ServiceManager package is a lightweight, flexible dependency injection container for managing services in PHP applications. It supports features like singleton services, auto-wiring, and lazy loading, making it easy to define and resolve services of varying complexity.

With ServiceManagerProvider, the package can be seamlessly integrated into applications that use PSR-11-compatible containers.

Install
-------

[](#install)

Via Composer

```
$ composer require echo-fusion/servicemanager
```

Requirements
------------

[](#requirements)

The following versions of PHP are supported by this version.

- PHP 8.1
- PHP 8.2
- PHP 8.3

Key Features
------------

[](#key-features)

- Auto-wiring: Automatically resolves dependencies for class constructors.
- Singleton support: Define services as shared (singleton) instances.
- Lazy loading: Services are instantiated only when requested.
- Configurable overrides: Allow or restrict overriding existing services.

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

- Register Services: Add services to the container with set().
- Resolve Services: Retrieve instances via get().
- Enable Override: Allow service overrides using enableOverride().

This example demonstrates how to register and retrieve services, configure singletons, and enable auto-wiring for classes:

```
use EchoFusion\ServiceManager\ServiceManager;
use EchoFusion\ServiceManager\Exceptions\ServiceManagerException;

$serviceManager = new ServiceManager();

// Register a service with an ID and class name (shared as singleton)
$serviceManager->set(MyServiceInterface::class, MyService::class, true);

// Register a service with a factory (non-singleton)
$serviceManager->set(AnotherServiceInterface::class, function (ServiceManagerInterface $sm) {
    return new AnotherService($sm->get(MyServiceInterface::class));
});

// Retrieve services
$myService = $serviceManager->get(MyServiceInterface::class);
$anotherService = $serviceManager->get(AnotherServiceInterface::class);

// Check if a service exists
if ($serviceManager->has(MyServiceInterface::class)) {
    // ...
}
```

### Using provider

[](#using-provider)

The ServiceManagerProvider integrates ServiceManager into a PSR-11-compatible container and manages service booting and configuration.

**Note:** Copy the config file into your project's config directory and add your application's dependencies following the provided example.

```
use EchoFusion\ServiceManager\DefaultContainer;
use EchoFusion\ServiceManager\Providers\ServiceManagerProvider;
use EchoFusion\ServiceManager\ServiceManagerInterface;

// Initialize a container, falling back to DefaultContainer if $container is not provided
$container = $container ?? new DefaultContainer();

// Initialize the ServiceManagerProvider with the container
$provider = new ServiceManagerProvider();
// Register the ServiceManager within the container
$provider->register($container);
// Define and boot service configurations
$config = require __DIR__ . '/config/servicemanager.config.php';// replace path with your project config directory
$provider->boot($container, $config]);

// Retrieve the service manager from the container
$serviceManager = $container->get(ServiceManagerInterface::class);

// Now you can access services through $serviceManager
if ($serviceManager->has(MyServiceInterface::class)) {
    $myService = $serviceManager->get(MyServiceInterface::class);
}

// or if you want to get exception if service definition doesn't exist
try {
    $serviceManager->get(AnotherServiceInterface::class);
} catch (ServiceManagerException | ReflectionException $e) {
    echo $e->getMessage();
}
```

Testing
-------

[](#testing)

Testing includes PHPUnit and PHPStan (Level 7).

```
$ composer test
```

Credits
-------

[](#credits)

Developed and maintained by [Amir Shadanfar](https://github.com/amir-shadanfar).
Connect on [LinkedIn](https://www.linkedin.com/in/amir-shadanfar).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/echo-fusion/servicemanager/blob/main/LICENSE) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~7 days

Total

6

Last Release

556d ago

Major Versions

v0.x-dev → v1.0.02024-10-01

v1.x-dev → v2.0.02024-11-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/b8a199998d8b5af726b9c5062f97228244822eb7b64b51adf7b050ff4bee378f?d=identicon)[echo-fusion](/maintainers/echo-fusion)

---

Top Contributors

[![echo-fusion](https://avatars.githubusercontent.com/u/182804396?v=4)](https://github.com/echo-fusion "echo-fusion (33 commits)")

---

Tags

containerPSR-11service-manager

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/echo-fusion-servicemanager/health.svg)

```
[![Health](https://phpackages.com/badges/echo-fusion-servicemanager/health.svg)](https://phpackages.com/packages/echo-fusion-servicemanager)
```

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[laminas/laminas-servicemanager

Factory-Driven Dependency Injection Container

15955.1M694](/packages/laminas-laminas-servicemanager)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[chubbyphp/chubbyphp-container

A simple PSR-11 container implementation.

1978.4k14](/packages/chubbyphp-chubbyphp-container)[phpwatch/simple-container

A fast and minimal PSR-11 compatible Dependency Injection Container with array-syntax and without auto-wiring

1810.1k2](/packages/phpwatch-simple-container)[selective/container

A simple PSR-11 container implementation with autowiring.

1220.4k4](/packages/selective-container)

PHPackages © 2026

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