dev-master
9999999-dev https://icanboogie.org/A dependency-injection container agnostic service provider
BSD-3-Clause
The Requires
- php >=5.6
The Development Requires
dependency injection provider
A dependency-injection container agnostic service provider
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!
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'));
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
The package requires PHP 5.6 or later., (*6)
The recommended way to install this package is through Composer:, (*7)
$ composer require ICanBoogie/Service
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
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)
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)
ICanBoogie/Service is licensed under the New BSD License - See the LICENSE file for details., (*13)
A dependency-injection container agnostic service provider
BSD-3-Clause
dependency injection provider