Download the PHP package quellabs/dependency-injection without Composer

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

Quellabs Dependency Injection

A lightweight, PSR-compliant dependency injection container for PHP with advanced autowiring capabilities and a unique contextual container pattern that allows interface-first service resolution without requiring knowledge of specific service IDs.

Features

Installation

Basic Usage

Service Resolution Methods

The container provides three primary methods for resolving dependencies:

has() - Checking Service Availability

Use has() to check if a service can be resolved:

Note: has() returns true if the container can attempt resolution. Concrete classes always return true (handled by DefaultServiceProvider), while interfaces require a registered provider.

get() - Service Provider Resolution

The get() method uses the full service provider pattern and is the recommended approach for most use cases:

When to use get():

make() - Direct Instantiation

The make() method bypasses service providers and creates instances directly using reflection:

When to use make():

Key Differences

Feature get() make()
Service Providers Uses registered providers Bypasses providers
Singleton Behavior Depends on service provider (DefaultServiceProvider uses singleton) Always creates new instances
Contextual Resolution Supports for() contexts No context support
Custom Instantiation Provider-defined logic Direct reflection only
Interface Resolution Via providers Cannot resolve interfaces
Performance Optimized (caching) Slightly faster per call

Practical Examples

Contextual Service Resolution

The container supports contextual service resolution through the for() method, allowing you to specify which implementation to use when multiple service providers support the same interface.

Service Providers

Service providers allow you to customize how services are created. A service provider can:

Default Service Provider

By default, all classes without a dedicated service provider are handled by the DefaultServiceProvider, which implements a singleton pattern. This means that for any given class, only one instance will ever be created and shared across the application.

Creating a Service Provider

Registering a Service Provider

Multiple Implementations with Context

When you have multiple service providers that support the same interface, you can use contextual resolution to specify which implementation to use:

Simple Bindings

For straightforward interface-to-concrete mappings where no custom instantiation logic is needed, you can use the SimpleBinding helper class instead of creating a full service provider:

This is equivalent to:

When to use SimpleBinding:

When to use a full ServiceProvider:

Automatic Service Discovery

The container can automatically discover and register service providers through multiple methods. The Dependency Injection package integrates the Quellabs Discover functionality, giving you powerful service discovery capabilities right out of the box.

Basic Discovery with Composer Configuration

Project-Level Configuration

In your composer.json:

For registering just one service provider:

Note the difference between the plural "providers" key (for an array of providers) and the singular "provider" key (for a single provider class).

For more information about Quellabs Discover and its advanced features, visit https://github.com/quellabs/discover.

Singleton and Transient Patterns

Since the default provider already implements the singleton pattern, you may want to create a custom provider for transient (non-singleton) services:

Alternatively, you can use the make() method for simple transient behavior without creating a custom service provider:

The $__all__ Magic Parameter

The dependency injection container supports a special magic parameter named $__all__ that provides access to all parameters passed to the container during method resolution. This is particularly useful for services that need flexible configuration or want to access additional context data.

How It Works

When the container encounters a parameter named $__all__ in a constructor or method signature, it automatically injects the complete parameters array that was passed to the container, giving you access to all available data, including parameters that don't have corresponding method arguments.

Basic Example

Important Notes

Advanced Configuration

Debug Mode

Enable debug mode to see detailed error information:

Custom Base Path

Specify a custom base path for service discovery:

Custom Configuration Key

Use a custom key for service discovery in composer.json:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License


All versions of dependency-injection with dependencies

PHP Build Version
Package Version
Requires quellabs/discover Version ^1.
quellabs/contracts Version ^1.
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 quellabs/dependency-injection contains the following files

Loading the files please wait ...