This is the repository for the DI Container used in the PHP-Fox framework.
You should not need to install this package when using the PHP-Fox framework, however if you wish to use this outside of the framework please use:
composer require phpfox/container
To use the container, all you need to do is:
$container = Container::getInstance();
$container->bind(
abstract: Abstract::class,
concrete: Concrete::class,
shared: false, // defaults to false - true turns this into a singleton.
);
/**
* @var bool
*/
$exists = $container->has(
id: Abstract::class,
);
/**
* @var Concrete
*/
$concrete = $container->make(
abstract: Abstract::class,
);
Container implementation inspired by example repo from Jess Archer, which provides a great and simple base.