Download the PHP package pierredup/di without Composer

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

Dynamic Dependency Injection

Build Status Scrutinizer Quality Score Code Coverage

This library provides a class to handle dependency injection dynamically.

Dynamic dependency injection means you don't have to define services or define which dependencies needs to be injected. The dependencies is dynamically created based on the constructor parameters.

This means you only need to add type-hints for the classes you want to inject into your class constructor.

Installation

Composer

To install this library using composer, add the following to your composer.json:

Make sure you are using composer's autoloader to include the file:

Download the file

Download Di.phar from the repo and save the file into your project path somewhere.

Usage

Getting a class with dependencies

This will give you an instance of Foo\Bar with the Baz class dynamically created and injection into the constructor.

Getting a new instance of a class

By default, the same instance for each class will be returned every time you call Di::get If you want to return a new instance of a class, you need to pass a second parameter to the get method

This will return a new instance of the Foo\Bar class, but the dependencies will always return the same instance.

If you want to ensure that every object returns a new instance, you need to pass the Di::DEEP flag:

This will return a new instance of Foo\Bar, as well as new instances for each dependency.

Parameters

Setting parameters

If you have values in your constructor that can not be type-hinted by an object ( E.G database settings), you use can use the map method to set the values for those parameters:

Note: If you don't specify a value for a parameter that doesn't have a type-hint, NULL will be passed as the value. If you set a default value for the parameter, then the default value will be used instead.

Lazy loading parameters

If you want parameters to be lazy-loaded (only load when needed, E.G get value from a database or a session ), you can use a closure or valid callback as the parameter:

The function or callback will only be executed when the parameter is needed, and the value will then be cached for any further calls.

Getting parameters

To get a parameter value, just pass the Di::PARAM flag to the get method:

Over writing classes

You can also use the map method to over write a class name. This is useful if you want to over write a core class of a library with your own implementation. Note that your class needs to extend from the class you are over writing, otherwise you might get an error or unexpected results.

TODO


All versions of di with dependencies

PHP Build Version
Package Version
No informations.
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 pierredup/di contains the following files

Loading the files please wait ....