Download the PHP package ascetic-soft/wirebox without Composer

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

Wirebox

CI codecov PHPStan Level 9 Latest Stable Version Total Downloads PHP Version License

Lightweight PHP 8.4 DI container with autowiring, directory scanning, PHP attributes, and dotenv support.

πŸ“– Full Documentation | ДокумСнтация Π½Π° русском | δΈ­ζ–‡ζ–‡ζ‘£

Features

Requirements

Installation

Quick Start

Configuration

ContainerBuilder

The ContainerBuilder is the main entry point for configuring the container.

The projectDir is used as the base path for resolving .env files.

Directory Scanning

Scan directories to auto-register all concrete classes (abstract classes, interfaces, traits, and enums are skipped):

Exclude files by glob pattern:

Classes marked with #[Exclude] are skipped automatically:

Interface Binding

Bind an interface to a concrete implementation:

When scanning, if an interface has exactly one implementation in the scanned directory, it is auto-bound automatically. If two or more implementations of the same interface are found, the auto-binding becomes ambiguous and build() will throw a ContainerException. Use an explicit bind() call to resolve the ambiguity:

Alternatively, if you don't need a specific binding but want to suppress the ambiguity error (e.g. the interface is resolved at runtime, or you only use tagged iteration), use excludeFromAutoBinding():

Multiple interfaces can be excluded at once:

Note: Unlike registerForAutoconfiguration(), this does not apply any autoconfiguration rules (tags, lifetime, etc.) β€” it only suppresses the ambiguity error.

Factory Registration

Register a service with a custom factory closure:

Fluent Definition API

Override or configure individual service definitions:

Parameters and Environment Variables

Set parameters that can reference environment variables:

Supported type casts: string (default), int, float, bool.

Parameters can also contain env expressions embedded in a larger string:

Environment Variables

Wirebox resolves environment variables with 3-level priority (highest first):

Priority Source Description
1 .env.local.php Generated by composer dump-env. A PHP file returning an array. Fastest.
2 $_ENV / getenv() Real system environment variables.
3 .env Parsed by built-in DotEnvParser. Development fallback.

All files are resolved relative to projectDir.

.env File Format

Production: composer dump-env

For production, use Symfony's composer dump-env to generate .env.local.php:

This creates a PHP file that returns an array β€” no file parsing at runtime.

PHP Attributes

#[Singleton]

Marks a class as singleton (this is the default behavior, use for explicitness):

#[Transient]

A new instance is created on every get() call:

#[Lazy]

Return a lightweight proxy immediately; the real instance is created only when a property or method is first accessed. Uses PHP 8.4 native lazy objects (ReflectionClass::newLazyProxy):

Can be combined with #[Transient] to create a new lazy proxy on every get() call.

The same behavior is available via the fluent API:

Lazy proxies are fully supported by the compiled container.

Default lazy mode

ContainerBuilder enables lazy mode by default β€” all services without an explicit #[Lazy] or #[Eager] attribute are created as lazy proxies. You can disable this:

#[Eager]

Opt out of lazy instantiation when the container's default lazy mode is enabled:

The same behavior is available via the fluent API:

#[Tag]

Tag a class for grouped retrieval. Repeatable:

Retrieve tagged services:

#[AutoconfigureTag]

Automatically tag all classes that implement an interface or are decorated with a custom attribute. Place #[AutoconfigureTag] on the interface or attribute class.

On an interface β€” all implementing classes receive the tag:

On a custom attribute β€” all classes decorated with that attribute receive the tag:

Repeatable β€” multiple tags can be applied:

Programmatic Autoconfiguration

For more control (lifetime, lazy, multiple tags), use registerForAutoconfiguration() on the builder:

Any class implementing EventListenerInterface found during scan() will automatically get the event.listener tag, be configured as a singleton, and use lazy proxies.

This also works with attributes:

CQRS Example

Autoconfiguration makes it easy to set up command and query handlers:

Build and retrieve. Autoconfigured interfaces are excluded from the ambiguous auto-binding check, so multiple implementations work seamlessly:

#[Inject]

Specify a concrete implementation for a type-hinted parameter:

#[Param]

Inject a scalar value from environment variables:

The value is automatically cast to the parameter's type hint (string, int, float, bool).

#[Exclude]

Exclude a class from auto-registration during directory scanning:

Container API

PSR-11

Tagged Services

Parameters

Self-Resolution

The container registers itself under three keys, so you can type-hint whichever you prefer:

WireboxContainerInterface extends PSR-11 with getTagged(), getParameter(), and getParameters(). Both Container and CompiledContainer implement it.

Compiled Container

For production, compile the container to a PHP class. This eliminates reflection at runtime:

Use the compiled container in production:

The compiled container:

Circular Dependencies

Wirebox detects circular dependencies at build time (build() / compile()) and throws CircularDependencyException for unsafe cycles before the container is ever used.

When is a cycle safe?

A circular dependency is safe only when all services in the cycle are lazy singletons. The proxy is cached before real instantiation begins, so when the dependency chain loops back, it finds the proxy in the cache instead of re-entering construction:

When is a cycle unsafe?

Scenario Result
All services are lazy singletons Safe β€” proxy cached before instantiation
Any service is eager Unsafe β€” Autowirer hits the same class twice
Any service is lazy transient Unsafe β€” proxy is not cached, infinite recursion

Unsafe cycles are reported with a clear message:

Note: Factory-based definitions (register(..., fn() => ...)) are skipped during cycle analysis because their dependencies cannot be determined statically.

Error Handling

Wirebox throws specific exceptions for common issues:

Exception When
NotFoundException Service not found and cannot be auto-wired
AutowireException Cannot resolve a constructor parameter
CircularDependencyException Unsafe circular dependency detected at build or runtime
ContainerException General container error (e.g. ambiguous bindings)

All exceptions implement Psr\Container\ContainerExceptionInterface.

Full Example

Testing

License

MIT


All versions of wirebox with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
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 ascetic-soft/wirebox contains the following files

Loading the files please wait ...