2017 © Pedro PelĂĄez
 

library service-provider

Little configuration manager and dependency injection

image

crodas/service-provider

Little configuration manager and dependency injection

  • Tuesday, December 22, 2015
  • by crodas
  • Repository
  • 2 Watchers
  • 2 Stars
  • 3,956 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 36 Versions
  • 1 % Grown

The README.md

ServiceProvider

Little configuration manager and dependency injection., (*1)

It is an attempt to build a simple library to define services, and how to consume them. A service is a configurable resource that is consumed by our software, think of it as a mysql_connect resource, where you can have different configuration for you local and production environment., (*2)

A service can be defined using annotations., (*3)

/**
 *  @Service(mysql, {
 *    host: {default:"localhost", type: string},
 *    user: {default:"root", type: string},
 *    pass: {default:"", type: string},
 *    port: {default: 3306, type: integer},
 *    db: {type: string},
 *  })  
 */
function get_mysql_service(Array $config)
{
    return new mysqli(
      $config['host'], 
      $config['user'], 
      $config['pass'], 
      $config['db'],
      $config['port']
    );
}

That's it, we just defined a service which in a reallity it is a function or method which returns something. In its annotation we defined its name and their configuration validation., (*4)

When you want to get access to the mysql service, (*5)

$service = new \ServiceProvider\Provider(
  'production.config.yml',  // the configuration file
  'where/services/are/defined/',  // where the files are defined.  It can use * comodin
  'production.generated.php' // to improve things we generate code, here is where to save it
);
$db = $service->get('mysql');
$db->query("SELECT * FROM users");

Events

As a bonus this library support events triggering/handling the right way. Basically at generation time it would look for @EventSubscriber(<name>, [<preference>=0]) over a method or function. To trigger an event is very simple:, (*6)

$service = new \ServiceProvider\Provider(
  'production.config.yml',  // the configuration file
  'where/services/are/defined/',  // where the files are defined.  It can use * comodin
  'production.generated.php' // to improve things we generate code, here is where to save it
);

$events = $service->get('event_manager');
$result = $events->trigger('foo.bar', array('arg1' => 'foo'));
var_dump('this event had ' . $result->getCalls() . ' handlers');

And somewhere in the code, (*7)

```php /** * @EventSubscriber(foo.bar) / function some_handler($event) { $args = $event->getArguments(); $event->stopPropagation(); / I'm the last one */ }, (*8)

The Versions

22/12 2015

dev-develop

dev-develop

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

22/12 2015

dev-master

9999999-dev

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

22/12 2015

v0.1.32

0.1.32.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

05/07 2015

v0.1.31

0.1.31.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

08/05 2015

v0.1.30

0.1.30.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

07/05 2015

v0.1.29

0.1.29.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

21/03 2015

v0.1.28

0.1.28.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

28/01 2015

v0.1.27

0.1.27.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

19/11 2014

v0.1.26

0.1.26.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

30/10 2014

v0.1.25

0.1.25.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

15/08 2014

v0.1.24

0.1.24.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

15/08 2014

v0.1.23

0.1.23.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

15/08 2014

v0.1.22

0.1.22.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

24/05 2014

v0.1.21

0.1.21.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

24/05 2014

v0.1.20

0.1.20.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

19/05 2014

v0.1.19

0.1.19.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

19/05 2014

v0.1.18

0.1.18.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

12/05 2014

v0.1.17

0.1.17.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

12/05 2014

v0.1.16

0.1.16.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

31/03 2014

v0.1.15

0.1.15.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

02/03 2014

v0.1.14

0.1.14.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

02/03 2014

dev-feature/events

dev-feature/events

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

27/02 2014

v0.1.13

0.1.13.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

24/02 2014

v0.1.12

0.1.12.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

17/12 2013

v0.1.11

0.1.11.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

12/12 2013

v0.1.10

0.1.10.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

12/12 2013

v0.1.9

0.1.9.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

29/11 2013

v0.1.8

0.1.8.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

02/11 2013

v0.1.7

0.1.7.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

01/11 2013

v0.1.6

0.1.6.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

01/11 2013

v0.1.5

0.1.5.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

01/11 2013

v0.1.4

0.1.4.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

28/10 2013

v0.1.3

0.1.3.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

28/10 2013

v0.1.2

0.1.2.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

27/10 2013

v0.1.1

0.1.1.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

27/10 2013

v0.1.0

0.1.0.0

Little configuration manager and dependency injection

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas