PHPackages                             slidesworker/servicelocator - 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. slidesworker/servicelocator

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

slidesworker/servicelocator
===========================

A basic ServiceLocator for PHP inspired by ZendFramework2

v1.0.0-rc1(12y ago)05LGPL-3.0+PHPPHP &gt;=5.2.0

Since Mar 3Pushed 12y ago1 watchersCompare

[ Source](https://github.com/SlidesWorker/ServiceLocator)[ Packagist](https://packagist.org/packages/slidesworker/servicelocator)[ Docs](http://www.github.com/SlidesWorker/ServiceLocator)[ RSS](/packages/slidesworker-servicelocator/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

SlidesWorker - ServiceLocator
=============================

[](#slidesworker---servicelocator)

[![Latest Stable Version](https://camo.githubusercontent.com/9150f7058eba284a0ce6345892c2789f63faa3a3e7bf48bf03e38b8959c4eddd/68747470733a2f2f706f7365722e707567782e6f72672f736c69646573776f726b65722f736572766963656c6f6361746f722f762f737461626c652e706e67)](https://packagist.org/packages/slidesworker/servicelocator)

[![Build Status](https://camo.githubusercontent.com/aefaae5bada9b58666b735dabcaaf806384412393002bd87ea09accaa4e74334/68747470733a2f2f7472617669732d63692e6f72672f536c69646573576f726b65722f536572766963654c6f6361746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/SlidesWorker/ServiceLocator)[![Code Coverage](https://camo.githubusercontent.com/3875d3ae5b59678bd397f41326f145de5ca49ff5a72c459e998c811873f94357/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536c69646573576f726b65722f536572766963654c6f6361746f722f6261646765732f636f7665726167652e706e673f733d37643833653262356334383238336366323033363663306435653462323839326362373130326533)](https://scrutinizer-ci.com/g/SlidesWorker/ServiceLocator/)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/85bbc7fdb9e3a3f498f29ea689be4476030bb061c033b284ef23920a03b8a393/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536c69646573576f726b65722f536572766963654c6f6361746f722f6261646765732f7175616c6974792d73636f72652e706e673f733d38623562313235396634653166363436663731303238646636303433333938306564356361313262)](https://scrutinizer-ci.com/g/SlidesWorker/ServiceLocator/)[![Dependency Status](https://camo.githubusercontent.com/e596d21ca16faad1a8271ac5c7bb5cd85004d69133648175a3b08a320b40201c/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3533313833396139656331333735356266613030303633642f62616467652e706e67)](https://www.versioneye.com/user/projects/531839a9ec13755bfa00063d)

How to use
==========

[](#how-to-use)

simple use
----------

[](#simple-use)

You can simple register your service to this ServiceLocator Fore more example see [this file](https://github.com/SlidesWorker/ServiceLocator/blob/master/example/SimpleWork.php)

```
namespace Example;

use SlidesWorker\ServiceLocator\ServiceLocator;

class Service1
{
}
class Service2
{
}

// setup ServiceLocator
$serviceLocator = new ServiceLocator();

$serviceLocator->set('service1', new Service1());
$serviceLocator->set('service2', new Service2());

$service1 = $serviceLocator->get('service1');
$service2 = $serviceLocator->get('service2');
```

with factory
------------

[](#with-factory)

The ServiceLocator can work with a some few factories. Classes that implements `SlidesWorker\ServiceLocator\FactoryInterface` and function or closure. Fore more example see [this file](https://github.com/SlidesWorker/ServiceLocator/blob/master/example/WorkWithFactory.php)

```
namespace Example;

use SlidesWorker\ServiceLocator\ServiceLocator;
use SlidesWorker\ServiceLocator\ServiceLocatorInterface;

class Service {}

// setup ServiceLocator
$serviceLocator = new ServiceLocator();

// factory as closure
$serviceLocator->setFactory('service', function (ServiceLocatorInterface $locator) {
    return Service();
});

// get a service
$service = $serviceLocator->get('service');
```

Initialzer and ServiceLocator
-----------------------------

[](#initialzer-and-servicelocator)

If you have the need that one objects must hold some other object Initializer is the right feature. In the case that ServiceLocator create the Object for you it run a Stack of few Initializer. You can add your own Initializer to this system, too.

A working example you find [here](https://github.com/SlidesWorker/ServiceLocator/blob/master/example/WorkWithInitializer.php)

give service the ability to handle the ServiceLocator
-----------------------------------------------------

[](#give-service-the-ability-to-handle-the-servicelocator)

ServiceLocator has the ability to add him self to a object. For this feature the object must be a instance of `SlidesWorker\ServiceLocator\ServiceLocatorAwareTrait` or `SlidesWorker\ServiceLocator\ServiceLocatorAwareInterface`

For more example see [this file](https://github.com/SlidesWorker/ServiceLocator/blob/master/example/ServiceCanHoldServiceLocator.php)

```
namespace Example;

use SlidesWorker\ServiceLocator\ServiceLocator;
use SlidesWorker\ServiceLocator\ServiceLocatorInterface;
use SlidesWorker\ServiceLocator\ServiceLocatorAwareInterface;
use SlidesWorker\ServiceLocator\ServiceLocatorAwareTrait;

// only php 5.4 and higher
class ServiceCanHoldServiceLocator1
{
    use ServiceLocatorAwareTrait;
}

// setup ServiceLocator
$serviceLocator = new ServiceLocator();

// factory as closure
$serviceLocator->setFactory('service', function (ServiceLocatorInterface $locator) {
    return new ServiceCanHoldServiceLocator1();
});

$serviceLocator->get('service');
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Unknown

Total

1

Last Release

4501d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/423633?v=4)[ClemensSahs](/maintainers/ClemensSahs)[@ClemensSahs](https://github.com/ClemensSahs)

---

Top Contributors

[![ClemensSahs](https://avatars.githubusercontent.com/u/423633?v=4)](https://github.com/ClemensSahs "ClemensSahs (15 commits)")

---

Tags

factoryserviceLocator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/slidesworker-servicelocator/health.svg)

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

###  Alternatives

[aura/dispatcher

Creates objects from a factory and invokes methods using named parameters; also provides a trait for invoking closures and object methods with named parameters.

3696.9k3](/packages/aura-dispatcher)[nikolaposa/cascader

Utility for creating objects in PHP from constructor parameters definitions.

12258.3k3](/packages/nikolaposa-cascader)[illuminatech/array-factory

Allows DI aware object creation from array definition

2163.5k6](/packages/illuminatech-array-factory)[aerni/factory

Quickly whip up fake content

193.5k](/packages/aerni-factory)

PHPackages © 2026

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