2017 © Pedro Peláez
 

library service-locator

Service locator for Hack

image

hhpack/service-locator

Service locator for Hack

  • Friday, June 22, 2018
  • by holyshared
  • Repository
  • 1 Watchers
  • 2 Stars
  • 7 Installations
  • Hack
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

service-locator

Latest Stable Version CircleCI Dependency Status License, (*1)

Basic usage

Implementing a factory of creating service., (*2)

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., (*3)

use HHPack\ServiceLocator\ServiceLocator;

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

Module of service factory

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

use HHPack\ServiceLocator\{ ServiceFactory, Module };

final class CustomModule implements Module
{

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

}

Using the defined modules, and generates a new service locator., (*5)

use HHPack\ServiceLocator\ServiceLocator;

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

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

Module for environment

By using the EnvironmentModule, you will be able to load a module based on the setting of HHVM_ENV., (*6)

When HHVM_ENV is the production looks for a module named Production from the specified directory., (*7)

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., (*8)

  • development, (*9)

    $ HHVM_ENV=development hhvm example/environment.hack
    $ development - logger loaded
  • production, (*10)

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

Run the test

You can run the test with the following command., (*11)

composer install
composer test

The Versions

22/06 2018

dev-master

9999999-dev

Service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

22/06 2018

2.0.5

2.0.5.0

Service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container hack service locator registry

09/05 2018

2.0.4

2.0.4.0

Service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container hack service locator registry

25/01 2018

2.0.3

2.0.3.0

Service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container hack service locator registry

25/01 2018

dev-feature/hhvm3.24

dev-feature/hhvm3.24

Service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container hack service locator registry

04/10 2017

2.0.2

2.0.2.0

Service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container hack service locator registry

11/09 2017

2.0.1

2.0.1.0

Service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container hack service locator registry

11/09 2017

2.0.0

2.0.0.0

Service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container hack service locator registry

11/09 2017

dev-develop

dev-develop

Service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container hack service locator registry

10/09 2017

1.2.1

1.2.1.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

12/08 2017

1.2.0

1.2.0.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

12/08 2017

dev-feature/autoload

dev-feature/autoload

Lightweight service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

06/07 2017

1.1.0

1.1.0.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

28/01 2017

1.0.0

1.0.0.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

24/04 2016

0.3.0

0.3.0.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

24/04 2016

0.2.0

0.2.0.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

01/04 2016

0.1.4

0.1.4.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Requires

 

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

23/03 2016

0.1.3

0.1.3.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

23/03 2016

0.1.2

0.1.2.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

23/03 2016

0.1.1

0.1.1.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry

22/03 2016

0.1.0

0.1.0.0

Lightweight service locator for Hack

  Sources   Download

MIT

The Development Requires

by Noritaka Horio

service container lightweight hack service locator registry