psr/container
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The psr/container is a PHP package that facilitates the definition of interfaces as per the PHP Standard Rrecommendation 11 (PSR-11). It's not a standalone Container implementation, but rather an abstraction that outlines the components of a Dependency Injection Container. The principal function of this package is to standardize how developers design containers to manage dependencies, ensuring a uniform coding experience.
Utilizing the psr/container in your PHP projects is straightforward. Firstly, ensure that you have Composer installed to manage dependencies. Afterward, you can add the package to your project by running the following command:
composer require psr/container
And then in your PHP file:
<?php
use Psr\Container\ContainerInterface;
class MyClass {
private $container;
public function __construct(ContainerInterface $container) {
$this->container = $container;
}
public function doSomething() {
$service = $this->container->get('my_service');
$service->execute();
}
}
In this example, MyClass
depends on my_service
. Instead of creating my_service
directly in MyClass
, we inject the container, and the container can provide my_service
.
Remember that every service or component interacting with the container should comply with the interfaces defined in PSR-11.
The psr/container package doesn't have separate official documentation as its paradigm and usage is documented in PSR-11. You can find the relevant information and understand its usage on the official PSR-11 page available at https://www.php-fig.org/psr/psr-11/. All necessary details about how to implement a conforming Container are present in these PSR-11 guidelines.