phine/locator

This package is abandoned and no longer maintained. No replacement package was suggested.

An implementation of the service locator design pattern.

1.1.0 2013-09-18 18:53 UTC

This package is not auto-updated.

Last update: 2021-12-07 01:41:36 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads

An implementation of the service locator design pattern.

Usage

use Phine\Locator\Locator;
use Phine\Locator\Service\AbstractService;
use Phine\Locator\Service\ResolvableInterface;

/**
 * A service that simply gets returned.
 */
class SimpleService extends AbstractService
{
}

/**
 * A service that causes the locator to return something else.
 */
class ResolvedService extends AbstractService implements ResolvableInterface
{
    /**
     * {@inheritDoc}
     */
    public function getResolvedValue()
    {
        return 'Something else.';
    }
}

// create my locator
$locator = new Locator();

// register my services
$locator->registerService('simple', new SimpleService());
$locator->registerService('resolved', new ResolvedService());

// access my services
echo get_class($locator->getService('simple')); // "SimpleService"
echo $locator->resolveService('resolved'); // "Something else."

Array accessible version of above:

use Phine\Locator\ArrayLocator;

// create my locator
$locator = new ArrayLocator();

// register my services
$locator['simple'] = new SimpleService();
$locator['resolved'] = new ResolvedService();

// access my services
echo get_class($locator['simple']); // "SimpleService"
echo $locator['resolved']; // "Something else."

Examples

Please see the wiki for examples.

Requirement

Installation

Via Composer:

$ composer require "phine/locator=~1.0"

Documentation

You can find the documentation in the docs/ directory.

License

This library is available under the MIT license.