league/container
league/container is a lightweight PSR-11 dependency injection container for PHP. Define entries, factories, and autowiring-friendly services to manage application dependencies cleanly, with modern PHP support and solid tooling for testing and analysis.
Container is a small but powerful dependency injection container that allows you to decouple components in your application in order to write clean and testable code.
Container was created by Phil Bennett. Find him on Twitter at [@philipobenito](https://twitter.com/philipobenito).
You need PHP >= 5.4.0 to use League\Container but the latest stable version of PHP is recommended.
Container is available on Packagist and can be installed using Composer:
composer require league/container
Most modern frameworks will include Composer out of the box, but ensure the following file is included:
<?php
// include the Composer autoloader
require 'vendor/autoload.php';
You can also use Container without using Composer by registering an autoloader function:
spl_autoload_register(function ($class) {
$prefix = 'League\\Container\\';
$base_dir = __DIR__ . '/src/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
Or, use any other PSR-4 compatible autoloader.
How can I help you explore Laravel packages today?