A very basic and minimalist PSR-11 implementation for config management and dependency injection.
PSR-11 refers to "PHP Standard Recommendation 11," which is a PHP specification that defines a common interface for implementing dependency injection containers in PHP applications. Dependency injection is a design pattern that allows objects to be provided with their dependencies from an external source, rather than creating those dependencies internally.
Here's a summary of PSR-11:
Purpose: PSR-11 aims to provide a standardized way of implementing and using dependency injection containers in PHP applications.
Container Interface: PSR-11 defines the Psr\Container\ContainerInterface, which specifies methods for retrieving instances of objects (dependencies) from the container.
Container Operations: The interface includes methods such as get($id) to retrieve an instance by its identifier (usually a string), has($id) to check if an instance exists in the container, and set($id, $value) to manually register an instance with the container.
Implementing Containers: Developers can create their own containers by implementing the ContainerInterface and providing the necessary methods for managing and retrieving instances.
Interoperability: PSR-11 promotes interoperability between different PHP frameworks and libraries by providing a common interface. Applications built using PSR-11 containers can switch between different containers without needing to modify the application code.
Autowiring: PSR-11 does not explicitly define autowiring (automatic resolution of dependencies), but containers implementing this specification can choose to include autowiring functionality if desired.
Extension: PSR-11 can be extended by other PSR specifications to provide additional features or standards related to dependency injection.
Overall, PSR-11 standardizes the way dependency injection containers are implemented and used in PHP, promoting code reusability, flexibility, and interoperability between different components of PHP applications.
Follow the steps below:
composer require "byjg/config=4.9.*"
Open source ByJG