Skip to content

patrickkerrigan/php-di

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Code Climate Coverage PHP 8.4 Packagist

pkerrigan/di

A simple, lightweight PHP 8.4 dependency injector.

Why?

This was for fun, and doesn't really compare to the features offered by the popular dependency injectors. If you just need to inject objects then you may find this useful.

Usage

$injector = Injector::getInstance();
 
$injector->addClassResolver(new ArrayMapClassResolver([
    Interface::class => ConcreteImplementation::class
]));
 
$instance = $injector->get(Interface::class);

By default, all objects are treated as lazy singletons (that is, the same object will be returned for successive calls to get()). If you wish an object to be constructed again for every call of get (or injection) then you can explicitly define it as a Prototype like so:

$injector->addClassResolver(new ArrayMapClassResolver([
    Interface::class => new Prototype(ConcreteImplementation::class)
]));

About

A simple, lightweight PHP 7 dependency injector

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages