Download the PHP package sodaho/container without Composer

On this page you can find all versions of the php package sodaho/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 container

php-container

Lightweight PSR-11 dependency injection container for PHP. Autowiring, caching, zero bloat.

Why This Library?

What it does:

What it deliberately does not:

If you need those, use Symfony DI or PHP-DI.

Installation

Usage

Basic Autowiring

The container analyzes constructor parameters and recursively resolves all dependencies:

Manual Definitions

For services that need configuration or primitives:

Interface Binding

Bind interfaces to concrete implementations:

Singleton Behavior

All resolved instances are cached (singleton pattern):

Caching

The container can cache Reflection metadata to avoid analyzing classes on every request.

Enable via Config

Security: A signature key is required when caching is enabled (debug=false). This prevents RCE attacks via tampered cache files. See Security section below.

Enable via Fluent API

Enable via Environment Variables

Generate a secure key: php -r "echo bin2hex(random_bytes(32));"

Configuration Priority

Priority: $config array > $_ENV > getenv() > default

The library checks $_ENV first (thread-safe), then falls back to getenv() for legacy compatibility. Use a library like sodaho/env-loader to load .env files into $_ENV.

How Caching Works

  1. First request: Reflection analyzes classes, stores metadata
  2. Following requests: Metadata loaded from cache, no Reflection needed
  3. OPcache: Cache file is PHP code, optimized by OPcache

The cache stores "build instructions" (which dependencies each class needs), not the instances themselves.

Cache Management

Debug Mode

Debug mode disables caching for development:

Hooks

The container fires events at key points, allowing you to add logging, monitoring, or debugging without modifying your services.

Available Events

Event When Data
resolve New instance created ['id' => string, 'instance' => object]
error Exception during resolution ['id' => string, 'exception' => Throwable]
cacheHit Class metadata found in cache ['id' => string]
cacheMiss Class metadata not in cache ['id' => string]

Usage

Note: Hooks only fire when a new instance is created. Singleton cache hits (returning an already-resolved instance) do not trigger resolve.

Security

Cache Signature Key (Required in Production)

When caching is enabled (debug=false), a signature key is required. This prevents Remote Code Execution (RCE) attacks via tampered cache files in shared hosting environments.

Why? The cache file contains PHP code that gets executed via require. An attacker with write access to the cache file could inject malicious code. The HMAC-SHA256 signature ensures the file hasn't been modified.

Exception Debug Messages

Exceptions have two messages:

Exceptions

All exceptions implement PSR-11 interfaces:

Exception When
NotFoundException Class doesn't exist or service not defined
ContainerException Class not instantiable, unresolvable parameter, factory error, circular dependency
CacheException Cache write failed, directory not writable, invalid signature, missing signature key

Limitations

The container is intentionally minimal. It does not support:

Feature Status Alternative
Interface binding Supported bind() method
Autowiring Supported Automatic via Reflection
Singleton Supported Default behavior
Factories Supported set() method
Caching Supported enableCache() / config
Union types Default only Use set() for manual definition
Intersection types Default only Use set() for manual definition
Attributes Not supported Use set() for configuration
Tagged services Not supported Not needed for simple DI
Lazy proxies Not supported Would require code generation
Compiler passes Not supported Framework territory

Requirements

License

MIT

Acknowledgments

Parts of this project (refactoring, documentation, code review) were developed with AI assistance (Claude).


All versions of container with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
psr/container Version ^2.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 sodaho/container contains the following files

Loading the files please wait ...