Download the PHP package temant/container without Composer

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

Temant Container

CI Latest Stable Version Total Downloads License PHP Version Require PHPStan Level PSR-11

A lightweight, PSR-11 compliant dependency injection container for PHP 8.2+ with autowiring support.

Features

Requirements

Installation

Quick Start

Usage

Creating the Container

Registering Services

Shared (Singleton)

Registered with set() or its alias singleton(). The factory is called once on first get(), and the result is cached for all subsequent calls.

Factory

Registered with factory(). A new instance is created on every get() call.

Pre-built Instance

Registered with instance(). The given object is returned as-is on every get() call.

Bulk Registration

Register multiple shared services at once with multi().

Note: Duplicate registration throws a ContainerException. Use remove() first if you need to replace an entry.

Conditional Registration

Register only if the ID is not already bound. Useful in service providers or packages that shouldn't override user configuration.

Interface Binding

Map an interface (or any abstract ID) to a concrete class. Supports chained bindings.

Aliases

alias() is identical to bind() -- use whichever reads better in context.

Contextual Binding

Provide different implementations depending on which class is consuming the dependency. Uses a fluent when()->needs()->give() API.

You can also pass a closure factory:

Contextual bindings take precedence over global bindings. If no contextual binding matches, the container falls back to global bindings and autowiring as usual.

Tagging

Group related services under a tag name and resolve them all at once.

Tags also power variadic resolution -- when a constructor has a typed variadic parameter, the container looks for services tagged with that type name.

Extending / Decorating Services

Wrap or modify a service after it is resolved. Multiple extenders per service are applied in registration order.

Inflectors

Apply common operations to any resolved service that matches a given type. Ideal for setter injection driven by interfaces.

Multiple inflectors for the same type are applied in registration order. Unlike extend(), inflectors:

Container Events

Register callbacks that fire during service resolution. Useful for logging, debugging, or cross-cutting concerns.

Callbacks do not fire for cached singleton hits -- only on actual resolution.

Service Providers

Organize related service registrations into reusable provider classes.

Providers registered after boot() has been called are booted immediately.

Autowiring

When enabled (the default), the container uses reflection to automatically resolve constructor dependencies without manual registration.

Autowiring can be toggled at runtime:

Resolution Rules

For object types (class/interface), the resolver tries in order:

  1. Contextual binding for the current consumer class
  2. Explicitly registered entry in the container
  3. Autowire if enabled and the class exists
  4. Return null if the parameter is nullable
  5. Return the default value if one is declared
  6. Throw UnresolvableParameterException

For built-in types (string, int, array, etc.):

  1. Return the default value if one is declared
  2. Return null if nullable
  3. Throw UnresolvableParameterException

Not supported (by design): union types and intersection types throw UnresolvableParameterException.

Variadic Parameter Support

Typed variadic parameters (e.g., LoggerInterface ...$loggers) are resolved automatically:

  1. If services are tagged with the parameter's type name, all tagged services are injected.
  2. Otherwise, if a single instance of the type is registered, it is injected as a one-element array.
  3. If nothing matches, an empty array is used (variadic allows zero arguments).

Callable Invocation

Invoke any callable with auto-resolved parameters. Override specific parameters by name.

Works with closures, static methods, invokable objects, and [$object, 'method'] callables.

Class@method Syntax

Resolve a class from the container and invoke a method on it in one step:

This is equivalent to:

Fresh Instances with make()

make() always creates a new instance, bypassing the singleton cache. Accepts named parameter overrides for constructor arguments.

make() respects bindings, extenders, and inflectors -- it just skips the instance cache.

Lazy Proxies

Defer instantiation of heavy services until they are actually used. The factory does not run on get() -- it runs on the first method call, property access, or explicit getTarget().

You can inspect proxy state:

Limitation: The proxy delegates via __call() / __get() / __set() magic methods. instanceof checks against the proxied type will return false. For transparent lazy objects, PHP 8.4+ native lazy objects are recommended.

Child Containers (Scoped)

Create a child container that inherits the parent's registrations. The child can add or override bindings without affecting the parent. Unresolved entries fall back to the parent.

Navigate the hierarchy:

Checking & Removing Entries

Freeze & Warm-Up

Freezing

Lock the container to prevent any further modifications. Resolution continues to work normally.

All mutation methods throw when frozen: set(), singleton(), factory(), instance(), bind(), alias(), tag(), extend(), inflect(), resolving(), afterResolving(), remove(), lazy(), and contextual bindings.

Warm-Up

Pre-resolve all registered singletons to move instantiation overhead to startup time. Useful before freeze() in production.

Already-resolved singletons are skipped.

Introspection

Definition Introspection

Inspect a service's registration details without resolving it:

Exception Handling

All exceptions implement Psr\Container\ContainerExceptionInterface for PSR-11 interoperability.

Exception When
NotFoundException Entry not found and cannot be autowired. Implements NotFoundExceptionInterface.
ContainerException Duplicate registration, binding loop, frozen container, non-object return, or general resolution error.
ClassResolutionException Class not found, not instantiable, or circular dependency detected. Extends ContainerException.
UnresolvableParameterException Parameter has no type hint, unsupported type, or cannot be resolved. Extends ContainerException.

API Reference

Registration

Method Description
set(id, factory) Register a shared (singleton) service
singleton(id, factory) Alias for set()
factory(id, factory) Register a factory (new instance each get())
instance(id, object) Register a pre-built instance
multi(definitions) Bulk-register shared services
lazy(id, factory) Register a lazy-loaded service (deferred instantiation)
setIf(id, factory) Register shared only if not already registered
singletonIf(id, factory) Alias for setIf()
factoryIf(id, factory) Register factory only if not already registered
instanceIf(id, object) Register instance only if not already registered

Binding & Context

Method Description
bind(abstract, target) Bind an abstract ID to a concrete target
alias(alias, target) Alias for bind()
when(consumer) Begin a contextual binding (returns builder)

Tagging & Extension

Method Description
tag(id, tag) Tag a service with a group name
tagged(tag) Resolve all services under a tag
extend(id, closure) Decorate a service after resolution
inflect(type, closure) Apply a callback to any matching type after resolution

Events

Method Description
resolving(id\|closure, callback?) Register a resolving callback (ID-specific or global)
afterResolving(id\|closure, callback?) Register an after-resolving callback (ID-specific or global)

Resolution

Method Description
get(id) Retrieve an entry (PSR-11)
has(id) Check if an entry can be resolved (PSR-11)
make(id, parameters?) Create a fresh instance (bypasses cache)
call(callable, overrides?) Invoke a callable with DI-resolved parameters

Service Providers

Method Description
register(provider) Register a service provider
boot() Boot all registered providers

Lifecycle

Method Description
remove(id) Remove an entry from the container
clear() Remove everything and reset state
flushInstances() Clear cached instances only
freeze() Prevent further modifications
isFrozen() Check if frozen
warmUp() Pre-resolve all singletons

Container Hierarchy

Method Description
createChild() Create a child container with parent fallback
getParent() Get the parent container (or null)

Autowiring

Method Description
setAutowiring(bool) Enable/disable autowiring at runtime
hasAutowiring() Check if autowiring is enabled

Introspection

Method Description
keys() List all registered service IDs
all() Structured snapshot of all registrations
allShared() All shared definitions
allFactories() All factory definitions
allInstances() All cached instances
allBindings() All bindings/aliases
getDefinition(id) Inspect a service's registration details

Testing

License

MIT License. See LICENSE for details.


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 temant/container contains the following files

Loading the files please wait ...