Download the PHP package sanmai/di-container without Composer

On this page you can find all versions of the php package sanmai/di-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package di-container

sanmai/di-container

A straightforward PSR-11 dependency injection container with automatic constructor dependency resolution.

I designed the autowiring initially for Infection's own use with focus on simplicity and zero configuration, building on the existing implementation by Maks Rafalko and Théo Fidry.

Installation

Features

Quick Start

The order in which you define your services is not important, as dependencies are only resolved when they are requested.

Builder Objects

Builder objects can encapsulate arbitrary complex construction logic. They can use dependency injection, which makes them cohesive, independently testable, and reusable.

The Builder interface uses a covariant template (@template-covariant T), so PHPStan correctly validates that your builder's return type matches the declared template parameter.

When you implement the Builder interface, you can simply provide the builder class name instead of a closure. The container automatically detects builder classes and handles the instantiation and build() method call.

For setting dependencies on the fly, there's a handy set() method that accepts both callables and builders.

Non-Class Service IDs

For non-class service IDs (e.g., 'app.repository'), use the bind() method or the $bindings constructor parameter:

The bind() method and $bindings parameter accept both callables and builder class names, just like set(), but without class-string type constraints on the service ID.

Pre-Built Instances

Use inject() to store objects that were created outside the container:

Design Philosophy

This container prioritizes simplicity, predictability, and architectural purity. It achieves this through:

The container resolves interfaces using a straightforward rule: when a dependency is an interface, it looks for exactly one registered factory or a builder that produces a compatible object.

This approach allows you to wire dependencies without explicitly linking an implementation to an interface; the container connects them logically as long as the relationship is unambiguous.

The container omits circular dependency checks for simplicity, an issue that even the most minimal automatic test will immediately reveal.

Testing

Benchmarking

Runs PHPBench with OPcache and JIT enabled.


All versions of di-container with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
psr/container Version ^1.1.2 || ^2.0
sanmai/pipeline Version ^6.17 || ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sanmai/di-container contains the following files

Loading the files please wait ...