2017 © Pedro PelĂĄez
 

library services

WOK Service provider and dependency injection

image

wok/services

WOK Service provider and dependency injection

  • Tuesday, March 21, 2017
  • by graphidev
  • Repository
  • 1 Watchers
  • 0 Stars
  • 33 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

Services

This library is lightweight dependency injection., (*1)

SensioLabsInsight, (*2)

Diclaimer : This component is part of the WOK (Web Operational Kit) framework. It however can be used as a standalone library., (*3)

Install

It is recommanded to install that component as a dependency using Composer :, (*4)

composer require wok/services

You're also free to get it with git or by direct download while this package has no dependencies., (*5)

git clone https://github.com/web-operational-kit/services.git

Features

While a lot of dependencies injectors have been developed (such as pimple/pimple, or league/container), this library roadmap has some specificities :, (*6)

  • The Services component is a dependency injector (usual).
  • Depencies instances MUST be cached throughout the Services object life (that's the dependency injection pattern).
  • Dependencies instances constructors CAN accept parameters without having any trouble with the previous points.

Let's see this in usage., (*7)

Usage

Basic usage

``` php use \WOK\Services\Services; $services = new Services();, (*8)

// Sample with Doctrine/Cache as cache service. $services->addService('cache', function() {, (*9)

return new \Doctrine\Common\Cache\FilesystemCache(
    './var/cache');

});, (*10)

// Far far away ..., (*11)

// Retrieve the service $cache = $services->getService('cache');, (*12)


## With parameters ``` php use \WOK\Services\Services; $services = new Services(); // Sample with Symfony/Translation as `translator` service and the locale code as parameter $services->addService('translator', function($locale) { $translator = new \Symfony\Component\Translation\Translator($locale); $translator->addLoader('ini', new \Symfony\Component\Translation\Loader\IniFileLoader()); $files = new DirectoryIterator($path); foreach($files as $resource) { if($resource->getExtension() != 'ini') { continue; } // Only accepted files as `domain.locale.(ini|yml)` $basename = $resource->getBasename(); $domain = mb_substr($basename, 0, mb_strpos($basename, '.')); $translator->addResource($resource->getExtension(), $resource->getPathname(), $locale, $domain); } return $translator; }); // Far far away ... $translator = $services->getService('translator', array('fr_FR'));

The Versions

21/03 2017

dev-master

9999999-dev

WOK Service provider and dependency injection

  Sources   Download

MIT

by SĂ©bastien ALEXANDRE

21/03 2017

dev-develop

dev-develop

WOK Service provider and dependency injection

  Sources   Download

MIT

by SĂ©bastien ALEXANDRE

21/03 2017

v1.1.1

1.1.1.0

WOK Service provider and dependency injection

  Sources   Download

MIT

by SĂ©bastien ALEXANDRE

28/12 2016

v1.1.0

1.1.0.0

WOK Service provider and dependency injection

  Sources   Download

MIT

by SĂ©bastien ALEXANDRE

10/11 2016

v1.0.0

1.0.0.0

WOK Service provider and dependency injection

  Sources   Download

MIT

by SĂ©bastien ALEXANDRE

27/09 2016

v0.2.0

0.2.0.0

WOK Service provider and dependency injection

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE