Download the PHP package iviphp/container without Composer
On this page you can find all versions of the php package iviphp/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download iviphp/container
More information about iviphp/container
Files in iviphp/container
Package container
Short Description Dependency injection container for the IviPHP ecosystem.
License MIT
Informations about the package container
Ivi Container
Dependency injection container for the IviPHP ecosystem.
Overview
iviphp/container provides a lightweight dependency injection container for IviPHP packages and applications.
It supports:
- explicit service bindings;
- singleton services;
- existing instances;
- closure factories;
- automatic constructor injection;
- circular dependency detection.
The container can resolve concrete classes automatically through PHP reflection.
Installation
Requirements
- PHP 8.2 or later
- Composer
iviphp/contracts
Creating a container
Automatic constructor injection
Concrete classes do not need to be registered manually when their dependencies can also be resolved.
The container automatically creates Database and injects it into UserRepository.
Registering bindings
An interface can be connected to a concrete implementation.
A binding creates a new instance each time it is resolved.
Singleton services
Singleton services are resolved once and reused.
Closure factories
A closure can be used when service creation requires custom logic.
Factories receive the current container instance.
A factory must return an object.
Registering existing instances
An existing object can be stored directly in the container.
Registered instances are always shared.
Checking services
Concrete classes are considered resolvable even when they have not been explicitly registered.
Removing services
Remove a binding and its resolved singleton instance:
Remove every binding and resolved instance:
Constructor parameter resolution
The container resolves class dependencies automatically.
Parameters with default values are supported.
Nullable unresolved parameters receive null.
Scalar parameters without a default value cannot be resolved automatically.
Resolving this class throws a BindingResolutionException.
Circular dependency detection
Circular dependency chains are detected during resolution.
Resolving either service throws a BindingResolutionException describing the dependency chain.
Available methods
Exceptions
ContainerException
Base exception for container-related failures.
BindingResolutionException
Thrown when the container cannot resolve a service because of:
- a missing class;
- a non-instantiable class or interface;
- an unresolved constructor parameter;
- a circular dependency;
- an invalid factory return value;
- a construction failure.
Design principles
- Small and predictable API
- Automatic constructor injection
- Explicit interface bindings
- No global container instance
- No framework runtime dependency
- Clear dependency resolution errors
- No hidden service locator behavior
This package is responsible only for registering and resolving application dependencies.
Service providers, application bootstrapping and framework lifecycle management belong to higher-level IviPHP packages.
Ecosystem
This package is part of the IviPHP ecosystem:
iviphp/contractsiviphp/supportiviphp/configiviphp/httpiviphp/validationiviphp/databaseiviphp/cacheiviphp/viewiviphp/framework
Contributing
Contributions should preserve the focused scope of this package.
New features should:
- remain independent from the full framework;
- preserve predictable dependency resolution;
- avoid introducing global container state;
- provide clear errors when a dependency cannot be resolved;
- avoid unrelated application lifecycle responsibilities.
Security
Please report security issues privately to the Softadastra maintainers instead of opening a public issue.
License
This project is licensed under the MIT License.
Maintainer
Created and maintained by Softadastra.