2017 © Pedro Peláez
 

library servicelocator

A basic ServiceLocator for PHP inspired by ZendFramework2

image

slidesworker/servicelocator

A basic ServiceLocator for PHP inspired by ZendFramework2

  • Thursday, March 6, 2014
  • by ClemensSahs
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

SlidesWorker - ServiceLocator

Latest Stable Version, (*1)

Build Status Code Coverage Scrutinizer Quality Score Dependency Status, (*2)

How to use

simple use

You can simple register your service to this ServiceLocator Fore more example see this file, (*3)

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

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

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

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

A working example you find here, (*6)

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

For more example see this file, (*8)

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');

The Versions

06/03 2014

dev-master

9999999-dev http://www.github.com/SlidesWorker/ServiceLocator

A basic ServiceLocator for PHP inspired by ZendFramework2

  Sources   Download

LGPL-3.0+

The Requires

  • php >=5.2.0

 

The Development Requires

factory servicelocator

03/03 2014

v1.0.0-rc1

1.0.0.0-RC1 http://www.github.com/SlidesWorker/ServiceLocator

A basic ServiceLocator for PHP inspired by ZendFramework2

  Sources   Download

LGPL-3.0+

The Requires

  • php >=5.2.0

 

The Development Requires

factory servicelocator