2017 © Pedro Peláez
 

library service

A dependency-injection container agnostic service provider

image

icanboogie/service

A dependency-injection container agnostic service provider

  • Thursday, May 25, 2017
  • by olvlvl
  • Repository
  • 0 Watchers
  • 0 Stars
  • 141 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Service

Release Build Status Code Quality Code Coverage Packagist, (*1)

ICanBoogie/Service provides means to reference, resolve, and invoke services using your favorite dependency injection container, in the most transparent way possible., (*2)

Please, consider the following example:, (*3)

<?php

use ICanBoogie\Service\ServiceProvider;
use function ICanBoogie\Service\ref;

ServiceProvider::define(function ($id) {

    if ($id === 'hello')
    {
        return function ($name = "world") {
            return "Hello $name!";
        };
    }

    throw new \LogicException("Unknown service: $id");
});

# getting a service through the provider
$service = ServiceProvider::provide('hello');
echo $service("Madonna");
// Hello Madonna!

# using a reference
$reference = ref('hello');
echo $reference;
// hello
echo $reference("Madonna");
// Hello Madonna! 

References are callables

Service references created with ref are especially useful when you need to provide a callable but you don't want that callable to be instantiated right away:, (*4)

<?php

use function ICanBoogie\Service\ref;

class Compute
{
    public function __construct(callable $computer)
    {
        // …
    }

    // …
}

$compute = new Compute(ref('expansive_instance'));

References can be exported

ServiceReference instances can safely be exported with var_export():, (*5)

<?php

use ICanBoogie\Service\ServiceReference;

$id = 'my_service';
$reference = new ServiceReference($id);
$dump = var_export($reference, true);

$r = eval("return $dump;");

echo get_class($r);   // ICanBoogie\Service\ServiceReference 
echo (string) $r;     // my_service

Requirements

The package requires PHP 5.6 or later., (*6)

Installation

The recommended way to install this package is through Composer:, (*7)

$ composer require ICanBoogie/Service

Cloning the repository

The package is available on GitHub, its repository can be cloned with the following command line:, (*8)

$ git clone https://github.com/ICanBoogie/Service.git

Documentation

The package is documented as part of the [ICanBoogie][] framework documentation. You can generate the documentation for the package and its dependencies with the make doc command. The documentation is generated in the build/docs directory. ApiGen is required. The directory can later be cleaned with the make clean command., (*9)

Testing

The test suite is ran with the make test command. PHPUnit and Composer need to be globally available to run the suite. The command installs dependencies as required. The make test-coverage command runs test suite and also creates an HTML coverage report in build/coverage. The directory can later be cleaned with the make clean command., (*10)

The package is continuously tested by Travis CI., (*11)

Build Status Code Coverage, (*12)

License

ICanBoogie/Service is licensed under the New BSD License - See the LICENSE file for details., (*13)

The Versions

25/05 2017

dev-master

9999999-dev https://icanboogie.org/

A dependency-injection container agnostic service provider

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6

 

The Development Requires

dependency injection provider