Download the PHP package vection-framework/di-container without Composer

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

release QA PHPStan

PHP DI - Dependency Injection Container

:warning: Vection Dependency Injection is currently in development stage, so atm only pre-releases are available. Breaking changes may be made until a stable release!

Dependency Injection Container for PHP

This vection component provides a powerful dependency injection container for PHP. It supports several ways of automatic injection like annotations, attributes and injection by interfaces. An optional configuration allows the mapping of interfaces and concrete implementation.

Supported injection types

Installation

Vection Components supports only installation via composer. So first ensure your composer is installed, configured and ready to use.

How to use

First we take a look how to use the DI container before start explaining the setup.

Constructor injection

This DI container supports the automatically injection of construct properties insofar as the properties are objects with type hints, means no primitive types! The following example would injection the object of type FooBar at creation.

Annotation / Attribute injection

The annotation injection provides a powerful possibility to injection dependencies into protected object properties by using the #[Inject] attribute on properties. The usage of annotation injection requires the use of the AnnotationInjection trait. Annotations also requires the fully qualified class names (< PHP 7.4)

Important notice
Injected properties cannot be accessed from constructor. If you need to access an injected property from the constructor you can use the alternative construction method __init() in your class. This method will be called immediately after the object is created with its dependencies.

Interface injection

The interface injection is a great way to decouple the concrete implementation with its interfaces. It provides the injection by using the interfaces instead of concrete implementations.

This kind of injection requires the following entry in the configuration file. (Detailed documentation of the configuration file you can read in the Setup -> Configuration section)

Interface aware injection

This injection type provides the injection of dependencies by its aware interfaces. This injection requires an configuration entry to map the interface with the concrete implementation.

This kind of injection requires the following entries in the configuration file.

The second parameter (Logger) defined the name of the setter method.

Explicit injection

This kind of injection provides an alternative way of injection if the constructor of all other injection types does not fit any use case.

Injection by parent class inheritance

This feature allows subclasses to get automatically dependency injection by parent classes, if the parent class uses any injection type.

Setup

The setup of the container is simple and takes only a few lines of code. Optional related of the use case and injection type you have to define a container configuration.

Create the container

The following snipped shows the fastest way of creating a working container.

If the class have some parameters which you have to pass manually, you can use the create method on the container. The second parameter is an array that will pass to the constructor of the class, the third parameter can be used to set this object as shared object or not. Shared objects will be reused by the container, non shared object will be create every time it is requested.

Configuration

The fasted way of setup does not fit the best way of usage, so lets take a look at some optional setup steps. The use of interface injection or some special object creations requires a configuration. This can be done by a configuration file (e.g. container.php). The benefit of a php config is the autocompletion and use of functions. The configuration file just returns an array with some definitions.

To load this configuration file you have to add it to the container. You can also add multiple config files in the case of modular development.

The configuration use the set function defined by the DI. This method takes the class as injection subject and returns an definition object on which you can define the injection. In common way it would look like the following snipped:

The right way would look like this:

[MORE CONFIGURATION DOC COMMING SOON...]

Third party library injection

The DI container creates an internal tree of dependencies. This can end up in the resolving of third party library classes with unresolvable parameters (e.g. in case of primitive construct parameters of unknown library class) and exits with an error. To avoid this, it is recommended to restrict the di container to the own applications namespace.

But if you want to use a third party library by injection, YOU CAN. In this case you should manually create the third party library object and just add this object to the container, now you this class can be used for injection.

This will register the object by its class name and provide it as injectable object.

Caching

It is recommended to use the cache to avoid performance issues on large applications. The DI component uses the Cache contracts of the Vection Contracts. So you can use an own cache implementation by implementing the CacheInterface from Vection\Contracts\Cache or use one of the already existed Vection Cache provider (Redis, Memcache, APCu). You can also use the Symfony Bridge (Vection\Bridge\Symfony\Cache\SymfonyCacheProviderBridge).

Support

Support Vection via Ko-fi:

Ko-fi


All versions of di-container with dependencies

PHP Build Version
Package Version
Requires vection-framework/contracts Version dev-master
php Version ^7.2
psr/log Version ~1.0
psr/container Version ^1.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 vection-framework/di-container contains the following files

Loading the files please wait ....