Download the PHP package mattferris/di without Composer

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

DI

Build Status SensioLabsInsight

DI is a dependency injection container library for PHP.

Registering Services

To start out, create an instance of MattFerris\Di\Di. Use the set() method to register services, passing an instance of the service, or use a Closure are used to return an instance of the service and accomplish any appropriate intialization. You can get an instance of the container by specifying an argument named $di, or by specyfing any argument with a type-hint of MattFerris\Di\Di or MattFerris\Di\ContainerInterface.

An instance of the service can now be retrieved via get().

Each request for the service will return the same instance of FooService. By default, all definitions are singletons. A third argument can be used to disable this behaviour.

Now every call to $di->get('FooService') will return a new instance of \FooService();

If your service relies on another service, a reference to the other service can easily be retrieved from within the definition either by manually retrieving it from the container or by having it injected.

You can check if a service has been defined using has().

You can use find() to return all services matching a prefix. This is useful if you have multiple services of a similar type and their definitions are named similarly. For example, if you have two remote FTP servers and you wanted to save a file to both of them, you could register the FTP services as FTP.host1' andFTP.host2. Usingfind()` to pull instances of these services allows you application to remain host agnostic, allow you to seamlessly configure additional hosts in the future.

$services would look like:

If you attempt to set a definition using a key that already exists, a DuplicateDefinitionException will be throw. The duplicate key can be retrieved using the DuplicateDefinitionException::getKey() method.

Type-Based Injection

In some cases, you may require a specific type of object for your service definition, but may not know what the name of the service's definition is within the container. Instead of requesting the directly from the container, you can have the service injected into your the closure of your service definition by type-hinting the argument.

If a definition exists that has an instance of \Bar\Service\Class, it will injected into the closure for consumption by your defined service. Likewise, you could also specify an interface or a trait name to inject.

If a dependency can't be resolved, a DependencyResolutionExceptioon will be thrown. The type that couldn't be resolved can be retrieved using the DependencyResolutionException::getType() method.

Optionally, Di can use deep resolution of a dependency. This can be enabled by calling $di->setDeepTypeResolution(true). When enabled, for type-based dependencies that can't be satisfied using definitions within the container, Di will attempt to instantiate an new instance of the type directly and use the new instance to satisfy the dependency. Constructor arguments will attempt to be satisfied using dependency injection as well.

Service Providers

You can use providers to isolate service configuration within your domains. A service provider is any class that extends MattFerris\Di\ServiceProvider, or implements MattFerris\Provider\ProviderInterface. When registered via register($provider), the provider's provides() method is passed an instance of the container and can then register services.

Defining Parameters

You can define parameters for any service definitions to use via setParameter() and getParameter(). This allows you to create more dynamic service definitions and configurations.

The database connection settings can now be defined dynamically. Also notice the DB service is defined as a singleton.

Delegation

Key prefixes can be delegated to other containers for lookup. This allows parts of your application, or third party components, to configure their own local containers, but plug them into a central container.

Now, any key beginning with Foo. will be delegated to $container for handling.

Custom Injection

In some cases, you may want to dynamically instantiate a class, or call a method (static or otherwise), closure or function. The methods injectConstructor(), injectionMethod(), injectStaticMethod(), and injectFunction() can accomplish this in a flexible way.

The above example returns an instance of FooClass with injected constructor arguments. Take note that the second argument passed to injectConstructor() is an array, and this array defines which arguments get which values. These values can be specified in any order, and the method will match the keys with the actual argument names in the contructors signature. The following example would have the same result.

injectConstructor() assigns the appropriate keys to their corresponding arguments. Keys with no corresponding argument are ignored. This principle is the same for the other inject methods.

Of course, you could inject defined services and parameters as well.

For convenience, the inject methods understand placeholders for services and parameters.

Services can be referenced by prefixing the service name with a percent sign (%), and parameters can be referenced by prefixing the parameter name with a colon (:).

Type-based injection occurs in all cases when using the inject* methods unless the argument is supplied when invoking the method. In this way, you can override type-based injection for particular arguments. You can also force type-based injection on arguments by supplying a type for an argument.

Argument values starting with a backslash are assumed to be type-hinted arguments.


All versions of di with dependencies

PHP Build Version
Package Version
Requires psr/container Version ~1.0
mattferris/provider Version ~0.3
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 mattferris/di contains the following files

Loading the files please wait ....