Download the PHP package p810/ioc-container without Composer

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

ioc-container

A dependency injection container that can autowire your objects with PHP's Reflection API

Getting started

This package is available via Packagist.

p810\Container\Resolver describes any class that contains functionality to automatically resolve (autowire) classes in your codebase. p810\Container\Container is an abstract class that may be used as a base for resolvers, providing storage functionality for instances of p810\Container\Entry, which is a value object used to describe classes in the container.

The default resolver shipped with this package is p810\Container\ReflectionContainer, which uses the Reflection extension.

Adding classes to the container

You can add classes to the container with p810\Container\Container::set(), providing a fully qualified class name. This will return an instance of p810\Container\Entry for your class:

You can specify a custom factory for any given class by passing a callable value as the second argument. By default, p810\Container\ReflectionContainer::resolve() is used. This method will pass your class's dependencies into the container for automatic resolution, a process known as autowiring.

:bulb: Note: Any classes whose constructor contains parameters that are not objects must explicitly define those parameters via the p810\Container\Entry instance returned by the container. This is covered below, under "Specifying default values for parameters".

Adding a singleton to the container

If you want an entry to only ever return one, specific object, either pass that object as the third argument to p810\Container\Container::set() or call p810\Container\Container::singleton():

For your class to be resolved by the container, supplying an instance may be skipped by omitting the second argument, or setting it to null.

A callable may be passed as the third argument to use as the factory for instantiating your singleton. This is only used if you haven't already passed an instance.

A fourth parameter, $resolveNow, is an optional boolean that will tell the container either to delay instantiation until the object is requested, or to do it immediately. This is set to false by default for delayed instantiation.

Getting objects from the container

A class can be resolved from the container by calling p810\Container\Container::get(). The Resolver will attempt to automatically resolve any type hinted classes it finds in the class's constructor, either in the method signature or as an @param annotation in its docblock.

Default arguments may be passed to p810\Container\Container::get() after the name of the class being resolved. If an associative array is the only given argument after the class name, it will be treated as a dictionary of named parameters; otherwise values will be looked up numerically.

Argument values may also be bound to the p810\Container\Entry instance for a given class.

Specifying default values for parameters

p810\Container\Entry::param() allows you to bind values to parameters of your constructor by name:

You can also use the plural counterpart p810\Container\Entry::params() to set multiple parameters with one call, by passing an associative array:

Binding a specific class to an interface

The container can be configured to return an object of a specific class when a given interface is requested by means of p810\Container\Container::bind(). Give it the fully qualified class names of both the interface and its implementor:

:bulb: Note: If the class you pass to p810\Container\Container::bind() has not already been registered to the container, it will be registered with the default settings. To customize a class's configuration you must register it before binding it to an interface.

License

This package is free and open source under the MIT License.


All versions of ioc-container with dependencies

PHP Build Version
Package Version
Requires ext-reflection Version *
php Version ^7.2
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 p810/ioc-container contains the following files

Loading the files please wait ....