PHPackages                             cubicmushroom/slim-service-manager - 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. [Framework](/categories/framework)
4. /
5. cubicmushroom/slim-service-manager

ActiveLibrary[Framework](/categories/framework)

cubicmushroom/slim-service-manager
==================================

Slim Framework add on to handle loading services from config

1.3.6(11y ago)16411MITPHP

Since Feb 16Pushed 11y ago1 watchersCompare

[ Source](https://github.com/cubicmushroom/slim-service-manager)[ Packagist](https://packagist.org/packages/cubicmushroom/slim-service-manager)[ RSS](/packages/cubicmushroom-slim-service-manager/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (11)Used By (1)

[![Build Status](https://camo.githubusercontent.com/dfdde8f905cae10f5bfa5f6cc59c8a6927e2cadedc5d8db38b471c9bbe29343a/68747470733a2f2f7472617669732d63692e6f72672f63756269636d757368726f6f6d2f736c696d2d736572766963652d6d616e616765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/cubicmushroom/slim-service-manager)

Slim Framework Service Manager
==============================

[](#slim-framework-service-manager)

The Service Loader is used to prepare services for a Slim Framework app based on service config.

The name of all services registered with the service manager are all prefixed with an '@' symbol. Therefore, as service name of `this_service` will be registered as `@this_service`.

Usage
-----

[](#usage)

Here's a quick example of how to use the Service Loader...

```
// Define the services
$config = [
    'services' => [
        'serviceOne' => [
            'class' => 'ServiceOne',
            'arguments' => ['a', 'b', 'c', '@serviceTwo'],
            'tags' => [
                ['tagName', ['tagArg1', 'tagArg2' => 'tagsArg2Value']]
            ],
        ],
        'serviceTwo' => [
            'class' => 'Namespace\ServiceTwo',
            'calls' => [
                ['setServiceThree', ['@ServiceThree']]
            ]
        ],
        'serviceThree' => [
            'class' => 'Namespace\ServiceThree'
        ],
    ]
];

$app = new Slim($config);

$serviceManagerOptions = [
    'registerAsService' => true,              // default value
    'ownServiceName'    => 'service_manager', // default value
    'autoload'          => true               // default value
    'registerApp'       => true               // default value
];

new ServiceManager($app, $serviceManagerOptions);

```

1. First of all, add a `'services'` element to the config that you pass into your Slim object.

    ```
     $config = [
         'services' => [
             'serviceOne' => [
                 'class' => 'ServiceOne',
                 'arguments' => ['a', 'b', 'c', '@serviceTwo'],
             ],
             'serviceTwo' => [
                 'class' => 'Namespace\ServiceTwo',
                 'calls' => [
                     ['setServiceThree', ['@ServiceThree']]
                 ]
             ],
             'serviceThree' => [
                 'class' => 'Namespace\ServiceThree'
             ],
         ]
     ];

     $app = new Slim($config);

    ```
2. Then all you need to do is instantiate the ServiceManager object, passing in the App, with the optional config options. This example shows the default values for the config options.

    ```
     $serviceManagerOptions = [
         'registerAsService' => true,              // default value
         'ownServiceName'    => 'service_manager', // default value
         'autoload'          => true               // default value
         'registerApp'       => true               // default value
     ];

     new ServiceManager($app, $serviceManagerOptions);

    ```

Service Definition
------------------

[](#service-definition)

The Service definition should be an array of items, with the key as the name the service will be registered under, and the value an array of settings as follows...

### class

[](#class)

Require

The full class name to be used to instantiate the service object.

### arguments

[](#arguments)

Optional

An array of arguments that will be passed to the service object constructor.

String values beginning with an '@' will be substituted with the service with the name matching the string, less the leading '@'.

### calls

[](#calls)

Optional

An array containing details of each additional method to be called on the initialised service object. Each entry in the array should be an array with the first item being the name of the method to be called, and an optional second array item that will be used as the arguments for the method call.

As with the `arguments`, any string that begins with an '@' within the arguments array will be substituted with the service registered with the name matching the string, less the leading '@'.

### tags

[](#tags)

Optional

An array of tags that can be used to filter service definitions by.

Each entry in the array should contain the tag name as it's first item, and an optional array of parameters for the second item.

You can then retrieve services tagged with a tag using `$serviceManager->getTaggedServices('tagName')`.

Arguments
---------

[](#arguments-1)

Here's an explanation of each of the options...

### Options

[](#options)

The second argument to the constructor...

#### options.autoload

[](#optionsautoload)

Whether to automatically register the services during instantiation

#### options.ownServiceName

[](#optionsownservicename)

Default: 'service\_manager'

The name to use if/when registering the Service Manager as a service.

#### options.registerApp

[](#optionsregisterapp)

Default: true

If set to true the service manager will register the app as a service using the key `@app`.

#### options.registerAsService

[](#optionsregisterasservice)

Default: true

If set to true the service manager will register itself as a service using the value of the `ownServiceName` setting.

ServiceManager Methods
----------------------

[](#servicemanager-methods)

The following methods are available on the ServiceManager...

### registerApp()

[](#registerapp)

Registers the app as a service. Only needs to be called if `options.registerApp` setting is false, otherwise this is called automatically.

### setupServices()

[](#setupservices)

Loads all the services. This is called automatically if `options.autoload` is set to false

### registerSelfAsService()

[](#registerselfasservice)

Registers the ServiceManager as a service using the `options.ownServiceName` value (or the default). This is automatically called if `options.registerAsService` is true.

### getService($serviceName)

[](#getserviceservicename)

Returns the service with the given name.

### getTaggedServices($tagName)

[](#gettaggedservicestagname)

Returns an array of services that are tagged with the given tag.

The returns array will contain the registered service name, prefixed with an '@' as the key, and the ServiceDefinition object as the value.

Other Classes
-------------

[](#other-classes)

### ServiceDefinition

[](#servicedefinition)

This class is used when registering a service. It's used over a regular closure to allow the service name and config to be stored in the object.

The `__invoke()` method is used to instantiate the service object when requested.

### MethodCallDefinition

[](#methodcalldefinition)

This class stores any calls on the method on instantiation, as defined by the `calls` part of the service definition.

### Tag

[](#tag)

This class stores the name and arguments of each tag as defined by the `tags` part of the service definition.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity69

Established project with proven stability

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

Total

10

Last Release

4095d ago

### Community

Maintainers

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

---

Top Contributors

[![toby-griffiths](https://avatars.githubusercontent.com/u/4817007?v=4)](https://github.com/toby-griffiths "toby-griffiths (48 commits)")

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/cubicmushroom-slim-service-manager/health.svg)

```
[![Health](https://phpackages.com/badges/cubicmushroom-slim-service-manager/health.svg)](https://phpackages.com/packages/cubicmushroom-slim-service-manager)
```

###  Alternatives

[slim/twig-view

Slim Framework 4 view helper built on top of the Twig 3 templating component

3708.0M210](/packages/slim-twig-view)[php-di/slim-bridge

PHP-DI integration in Slim

1786.7M98](/packages/php-di-slim-bridge)[slim/extras

Extras package for the Slim Framework

483504.7k11](/packages/slim-extras)[brandembassy/slim-nette-extension

19190.2k](/packages/brandembassy-slim-nette-extension)[slim/logger

Slim Framework logger

40288.2k1](/packages/slim-logger)[projek-xyz/slim-plates

Render your Slim 3 application views using Plates template engine.

2678.2k3](/packages/projek-xyz-slim-plates)

PHPackages © 2026

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