A lightweight service container for managing dependencies. This class allows for registering and resolving services or objects, enabling dependency injection and improved application modularity.
$system | bool |
Return | array |
Registers a container by name or object. Usage examples:
$container->register(new FooBar());
$container->register(FooBar::class);
$container->register(FooBarInterface::class, new FooBar());
$container->register(FooBarInterface::class, ['param1' => 'value1', 'param2' => 'value2']);
$container->register(FooBarInterface::class, fn() => new FooBar());
$objectOrName | string|object|callable |
$objectOrParams | object|array|null |
$system | bool |
Return | self |
Resolves a container by its name. If the container is callable, it will be executed and replaced with its result. If it is an array, it will be used to instantiate an object of the specified class.
$name | string |
Return | object |
Ensure input is an object, resolving it if it's a string.
$name | object|string|array |
$instanceOf | string|null |
Return | object |
Checks if a container is registered.
$name | string |
Return | bool |
Removes a container from the registry.
$name | string |
Return | self |
Creates an object of the specified class with the provided parameters. This method uses reflection to handle classes with constructors that require parameters.
$className | string |
$params | array |
Return | object |