Download the PHP package php-di/invoker without Composer

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

Invoker

Generic and extensible callable invoker.

CI Latest Version Total Downloads

Why?

Who doesn't need an over-engineered call_user_func()?

Named parameters

Does this Silex example look familiar:

Or this command defined with Silly:

Same pattern in Slim:

You get the point. These frameworks invoke the controller/command/handler using something akin to named parameters: whatever the order of the parameters, they are matched by their name.

This library allows to invoke callables with named parameters in a generic and extensible way.

Dependency injection

Anyone familiar with AngularJS is familiar with how dependency injection is performed:

In PHP we find this pattern again in some frameworks and DI containers with partial to full support. For example in Silex you can type-hint the application to get it injected, but it only works with Silex\Application:

In Silly, it only works with OutputInterface to inject the application output:

PHP-DI provides a way to invoke a callable and resolve all dependencies from the container using type-hints:

This library provides clear extension points to let frameworks implement any kind of dependency injection support they want.

TL/DR

In short, this library is meant to be a base building block for calling a function with named parameters and/or dependency injection.

Installation

Usage

Default behavior

By default the Invoker can call using named parameters:

Dependency injection in parameters is supported but needs to be configured with your container. Read on or jump to Built-in support for dependency injection if you are impatient.

Additionally, callables can also be resolved from your container. Read on or jump to Resolving callables from a container if you are impatient.

Parameter resolvers

Extending the behavior of the Invoker is easy and is done by implementing a ParameterResolver.

This is explained in details the Parameter resolvers documentation.

Built-in support for dependency injection

Rather than have you re-implement support for dependency injection with different containers every time, this package ships with 2 optional resolvers:

These resolvers can work with any dependency injection container compliant with PSR-11.

Setting up those resolvers is simple:

You can also register both resolvers at the same time if you wish by prepending both. Implementing support for more tricky things is easy and up to you!

Resolving callables from a container

The Invoker can be wired to your DI container to resolve the callables.

For example with an invokable class:

The same works for a class method:

That feature can be used as the base building block for a framework's dispatcher.

Again, any PSR-11 compliant container can be provided.


All versions of invoker with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
psr/container Version ^1.0|^2.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 php-di/invoker contains the following files

Loading the files please wait ....