2017-25 © Pedro Peláez
 

library service-locator

A simple dependency injection library for php

image

rehmat/service-locator

A simple dependency injection library for php

  • Tuesday, April 3, 2018
  • by RehmatFalcon
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHP-SERVICE-LOCATOR

A simple and light weight Dependency Injection library for PHP projects., (*1)

Requires

composer autoloading, (*2)

How to use?

In your php code, make sure to require composer's autoload, (*3)

require 'vendor/autoload.php';

You have to import the Rehmat\ServiceLocator\ServiceLocator namespace, (*4)

use Rehmat\ServiceLocator\ServiceLocator;
//instantiate ServiceLocator
$serviceLocator = ServiceLocator::getInstance();

//add configuration through which ServiceLocator can locate the factory to create your desired classes
// the ::class is required for retrieving the Fully Qualified Class Name (FQCN)
$serviceLocator->register(MyClassInterface::class, MyClassFactory::class, 'prod' );

The first parameter is the class that we want to register, the second parameter is the factory that we want to use when locating our class, the third parameter is used as a mode, while retrieving our class, if same class is registered twice but under different mode, the mode we specify takes precedence., (*5)

$myClassObj = $serviceLocator->create(MyClassInterface::class, 'prod');

Or, you can use our config reader and do it in a much quicker way., (*6)

//change this line to use ConfigReader too
use Rehmat\ServiceLocator\{ServiceLocator, ConfigReader};

$configs = [
    'prod'  => [
        MyClassInterface::class => MyClassFactory::class
    ]
];

(new ConfigReader())->fromArray($configs);

The Versions

03/04 2018

dev-master

9999999-dev

A simple dependency injection library for php

  Sources   Download

The Requires

  • php ^5.3.3 || ^7.0

 

The Development Requires

by Kushal

03/04 2018

v1.0

1.0.0.0

A simple dependency injection library for php

  Sources   Download

The Requires

  • php ^5.3.3 || ^7.0

 

The Development Requires

by Kushal