Download the PHP package yii1tech/di without Composer

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

Yii1 Dependency Injection Extension


This extension provides Dependency Injection support for Yii1 application.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the "require" section of your composer.json.

Usage

This extension provides Dependency Injection support for Yii1 application using PSR-11 compatible container.

This extension introduces static facade class \yii1tech\di\DI, which provides global access to PSR container and injector. All dependency injection features provided in this extension relies on this facade. It provides easy way for container entity retrieval and dependency injection. For example:

Container Setup

The actual dependency injection container should be set via \yii1tech\di\DI::setContainer() method. It should be done at the Yii bootstrap stage before the application is created. For example:

Instead of creating container instance right away, you may specify a PHP callback, which will instantiate it. For example:

Dependency Injection for Application Components

This extension allows configuration of the Application (Service Locator) components via DI container. In order to make it work, you need to use one of application classes provided within this extension - feature will not function automatically on the standard ones.

Following classes are provided:

If you use your own custom application class, you may apply DI component resolution to it using \yii1tech\di\base\ResolvesComponentViaDI trait.

For example:

Being DI-aware, application will resolve configured components via DI Container according to their configured class. This allows you moving configuration into DI Container from Service Locator without breaking anything. For example:

Heads up! Be careful while moving Yii component definitions into DI container: remember to invoke method init() manually on them. Yii often places crucial initialization logic into component's init(), if you omit its invocation you may receive broken component instance, while fetching it directly from the container.

Heads up! If you move application component config to DI container, make sure to clean up its original configuration at Service Locator. Any remaining "property-value" definition will be applied to the object fetched from container. It may be useful, when you define container entity via factory, but in most cases it will cause you trouble.

Tip: component placed into Yii Application (Service Locator) via DI container is not required to implement \IApplicationComponent interface, since method init() will never be automatically invoked on it.

Dependency Injection in Web Application

This extension allows injection of DI container entities into controller constructors and action methods based on arguments' type-hints. However, this feature will not work on standard controllers extended directly from CController - you'll need to extend \yii1tech\di\web\Controller class or use \yii1tech\di\web\ResolvesActionViaDI trait. For example:

Heads up! While declaring your own controller's constructor, make sure it accepts parent's arguments $id and $module and passes them to the parent constructor. Otherwise, controller may not function properly.

Dependency Injection in Console Application

This extension allows injection of DI container entities into console commands constructors and action methods based on arguments' type-hints. However, this feature will not work on standard console commands extended directly from CConsoleCommand - you'll need to extend \yii1tech\di\console\ConsoleCommand class or use \yii1tech\di\console\ResolvesActionViaDI trait. For example:

Heads up! While declaring your own console command's constructor, make sure it accepts parent's arguments $name and $runner and passes them to the parent constructor. Otherwise, console command may not function properly.

External (3rd party) Container Usage

Container \yii1tech\di\Container is very basic, and you may want to use something more sophisticated like PHP-DI instead of it. Any PSR-11 compatible container can be used within this extension. All you need is pass your container to \yii1tech\di\DI::setContainer(). For example:

Many existing PSR-11 compatible solutions are coming with built-in injection mechanism, which you may want to utilize instead of the one, provided by this extension. In order to do this, you should create your own injector, implementing \yii1tech\di\InjectorContract interface, and pass it to \yii1tech\di\DI::setInjector().

Many of the existing PSR-11 containers (including the 'PHP-DI') already implements dependency injection methods make() and call(). You can use \yii1tech\di\external\ContainerBasedInjector to utilize these methods. For example:

Heads up! Many of the existing PSR-11 containers, which provide built-in injection methods, implements method \Psr\Container\ContainerInterface::has() in inconsistent way. While standard demands: it should return true only, if there is explicit binding inside the container - many solutions return true even, if binding does not exist, but requested class can be resolved, e.g. its constructor arguments can be filled up using other bindings from container. Such check is always comes with extra class and method reflection creation, which reduces the overall performance. This may cause a significant impact, while resolving Yii application components via DI container.

It is recommended to resolve any inconsistency in \Psr\Container\ContainerInterface::has() implementation before using container with this extension. This can be easily achieved using \yii1tech\di\external\ContainerProxy class. For example:


All versions of di with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
yiisoft/yii Version ~1.1.0
psr/container Version >=1.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 yii1tech/di contains the following files

Loading the files please wait ....