Download the PHP package dc/ioc without Composer

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

Installation

Or add it to composer.json:

Registering

You can register objects, classes and factory functions with the container.

Registering a class:

Registering an instance (instance registrations do not support lifetimes, they always live as long as the container does):

Registering a factory function:

Understanding lifetimes

There are 3 possible lifetime registrations: withPerResolveLifetime(), withContainerLifetime() and withSingletonLifetime(). You can use these when you pass a class name or factory function to register(), but not if you pass an instance of an object.

Resolving services

You can resolve services by querying the container directly:

If you have multiple registrations for the same interface or class name, you can use resolveAll().

Constructor injection

Use type hints to inject a dependency into a class.

If you don't want to use type hints, you can use PhpDoc comments instead. This is particularly useful when you want to get an array of something, as this is not supported by PHPs type-hinting syntax.

Or even simpler:

Property injection

All objects resolved through the container will have their non-static properties scanned for possible dependencies. To mark a property as injectable, it needs both a @var and a @inject PhpDoc declaration:

For objects that haven't been resolved through the container (meaning objects you have constructed yourself), you can apply property injection using the inject() method:

Factory injection

When you provide a factory function to registration, you can have other services injected as in a constructor. You can as before, either rely on type hints, or on PhpDoc comments (for injecting arrays).

Modules

If you have a large project that needs to register a lot of services, implementing a module may be the way to go.

Extend \DC\IoC\Modules\Module and specify a name for your module and which modules it depends on.

When (preferably before) registering your services, register all the modules first:

The container will try to register any dependencies in the correct order.

Performance

Some crude performance tests can be found in the perf/ folder of this repos. They show the following (numbers from a VM running on my machine):


All versions of ioc 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 dc/ioc contains the following files

Loading the files please wait ....