PHPackages                             hhpack/service-locator - 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. hhpack/service-locator

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

hhpack/service-locator
======================

Service locator for Hack

2.2.0(7y ago)39MITShell

Since Mar 22Pushed 6y agoCompare

[ Source](https://github.com/hhpack/service-locator)[ Packagist](https://packagist.org/packages/hhpack/service-locator)[ RSS](/packages/hhpack-service-locator/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (5)Versions (25)Used By (0)

service-locator
===============

[](#service-locator)

[![Latest Stable Version](https://camo.githubusercontent.com/2b4bcf00180990f638c5795b0b0651f5d9aa64d4abf7b7b241e6efeaf0ad6dfb/68747470733a2f2f706f7365722e707567782e6f72672f68687061636b2f736572766963652d6c6f6361746f722f762f737461626c65)](https://packagist.org/packages/hhpack/service-locator)[![CircleCI](https://camo.githubusercontent.com/8f1a9367af9134fca526a4037a0df8fde8ba9981395532571fc0cf57788642b9/68747470733a2f2f636972636c6563692e636f6d2f67682f68687061636b2f736572766963652d6c6f6361746f722f747265652f6d61737465722e7376673f7374796c653d737667)](https://circleci.com/gh/hhpack/service-locator/tree/master)[![Dependency Status](https://camo.githubusercontent.com/f59000e78dd8e56b87d5576edc60c57dfcfe68d81df5bb51b45743d927491ccc/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3536656661373865333536333065303033383838393763332f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/56efa78e35630e00388897c3)[![License](https://camo.githubusercontent.com/f74716ed661a0ca852e96855236e36c8d760c118e84874ee4c6851d9b1c5b31c/68747470733a2f2f706f7365722e707567782e6f72672f68687061636b2f736572766963652d6c6f6361746f722f6c6963656e7365)](https://packagist.org/packages/hhpack/service-locator)

Basic usage
-----------

[](#basic-usage)

Implementing a factory of creating service.

```
use HHPack\ServiceLocator\{ Service, ServiceFactory, Locator };

interface Logger implements Service
{
}

final class LoggerService implements Logger
{
}

final class LoggerFactory implements ServiceFactory {
  const type T = Logger;

  public function createService(Locator $locator): this::T {
    return new LoggerService();
  }
}
```

Specify the **ServiceFactory**, to create a service locator.

```
use HHPack\ServiceLocator\ServiceLocator;

$locator = ServiceLocator::fromItems([
    new LoggerFactory()
]);
$logger = $locator->lookup(Logger::class);
```

Module of service factory
-------------------------

[](#module-of-service-factory)

By using the modules that provide **ServiceFactory**, you can generate a new service locator.

```
use HHPack\ServiceLocator\{ ServiceFactory, Module };

final class CustomModule implements Module
{

    public function getIterator() : Iterator
    {
        yield new LoggerFactory();
    }

}
```

Using the defined modules, and generates a new service locator.

```
use HHPack\ServiceLocator\ServiceLocator;

$locator = ServiceLocator::fromModule(new CustomModule());

$logger = $locator->lookup(Logger::class);
$logger->put('logger loaded');
```

Module for environment
----------------------

[](#module-for-environment)

By using the **EnvironmentModule**, you will be able to load a module based on the setting of **HHVM\_ENV**.

When HHVM\_ENV is the **production** looks for a module named **Production** from the specified directory.

```
use HHPack\ServiceLocator\ServiceLocator;
use HHPack\ServiceLocator\Module\EnvironmentModule;

$module = new EnvironmentModule([
    Pair { 'HHPack\\Service\\Example\\', __DIR__ } // autoload for module
]);

$locator = ServiceLocator::fromModule($module);

$logger = $locator->lookup(Logger::class);
$logger->put('logger loaded');
```

By executing the **environment.hack** of example, it can be confirmed.

- development

    ```
      $ HHVM_ENV=development hhvm example/environment.hack
      $ development - logger loaded

    ```
- production

    ```
      $ HHVM_ENV=production hhvm example/environment.hack
      $ production - logger loaded

    ```

Run the test
------------

[](#run-the-test)

You can run the test with the following command.

```
composer install
composer test

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity73

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

Recently: every ~111 days

Total

19

Last Release

2626d ago

Major Versions

0.3.0 → 1.0.02017-01-28

1.2.1 → 2.0.02017-09-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/70c299d6d6015ee714954aa05e4d0e9c7b1d31318a5d7db5e9bb4e1f70f78afc?d=identicon)[holyshared](/maintainers/holyshared)

---

Top Contributors

[![holyshared](https://avatars.githubusercontent.com/u/167190?v=4)](https://github.com/holyshared "holyshared (83 commits)")

---

Tags

hacklanghhvmservice-locatorcontainerservicehackregistryservice locator

### Embed Badge

![Health badge](/badges/hhpack-service-locator/health.svg)

```
[![Health](https://phpackages.com/badges/hhpack-service-locator/health.svg)](https://phpackages.com/packages/hhpack-service-locator)
```

###  Alternatives

[league/container

A fast and intuitive dependency injection container.

86792.2M396](/packages/league-container)[acclimate/container

Provides adapters for various third-party service containers.

219394.9k15](/packages/acclimate-container)

PHPackages © 2026

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