Skip to content
/ Di Public
forked from mrprompt/Silex-Di

A simple dependency injection container builder provider to Silex based projects

License

Notifications You must be signed in to change notification settings

kinncj/Di

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Silex DI Builder

Build Status SensioLabsInsight Dependency Status Average time to resolve an issue Percentage of issues still open Codacy Badge Code Climate

A simple dependency injection builder to Silex based on YAML file config.

Install

composer require mrprompt/silex-di-builder

Usage

Simple create a di.yml - or other name, of course - file with the structure:

services:
  alias1:
    - Full\Class\Name
    - dependency1

  alias2:
    - Full\ClassTwo\Name
    - dependency1
    - dependency2

When:

  • alias1 - Is the alias from Silex
  • Full\Class\Name and Full\ClassTwo\Name - The class name to initialize
  • dependency1 and dependecy2 - Dependencies from the class, must be an alias previously created or anything

In your application bootstrap, register YAML Config Service Provider, with your DI file


use DerAlex\Silex\YamlConfigServiceProvider;
use SilexFriends\DI\Container as DiServiceProvider;

....

$app->register(new YamlConfigServiceProvider(__DIR__ . '/../Resources/di.yml'));
$app->register(new DiServiceProvider($app['config']['services']));
 
# $app['config']['services'] is an array with yml content, created by YamlConfigServiceProvider

Now, your services is available on $app container.

Testing

Just run phpunit without parameters

phpunit

Happy Silex Coding :)

About

A simple dependency injection container builder provider to Silex based projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%