Download the PHP package bapcat/phi without Composer

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

Build Status Coverage Status License

φhi

An efficient, easy-to-use, open-source PHP dependency injection container, boasting a tiny footprint, powerful features, 100% unit test coverage, and awesome documentation. Phi is compatible with PSR-0 and PSR-4 auto-loading standards, and open to collaboration from anyone who feels they can make an improvement.

Installation

Composer

Composer is the recommended method of installation for BapCat packages.

GitHub

BapCat packages may be downloaded from GitHub.

Features

Phi supports several different ways to inject dependencies, which can all be used alone or in conjunction with one another.

Automatic Injection

Assume you have a class named Foo that depends on a second class, Bar:

You can easily get a new instance of Foo with all required dependencies by doing the following:

You'll get a new instance of Foo with a new instance of Bar automatically injected into the constructor. This, of course, works recursively. If Bar depends on Baz, an instance of Baz will be injected into Bar, and so on.

Passing Parameters

There will be many cases where you need to pass parameters into the constructors as well. Consider the following class (note the order of the parameters):

There are several ways you can request this class from Phi:

You may want to override an automatically injected parameter:

Note that $a was passed in last in the previous example. Phi is smart enough to figure out the correct order to inject parameters of non-scalar types.

Multiple Same-Type Dependencies

Consider the following class:

Parameters of the same type will be passed to the constructor in the order they are given to Phi. If you would like to pass them in a different order, please see the section on named injection.

Named Injection

In some cases, it is useful to be explicit about which parameters you are passing in. Phi makes this easy. Consider the class from the "Passing Parameters" section:

Binding

Many modern applications have pieces that may be swapped out. This is accomplished by using interfaces. Phi allows automatic injection of interfaces using binding:

Binding even allows you to swap one concrete instance of a class for another:

Dependencies With Parameters

Sometimes you may have a dependency that has required parameters. This can be done by binding a class to a callable:

This is also useful if you need to perform logic when instanciating a class:

Any parameters passed to Phi will be passed directly to the callable:

Singletons

Phi also allows binding to real instances of classes. This can be used to create singletons:

Aliases

Sometimes, a codebase will have very commonly used classes with difficult-to remember names. For example, Vendor\Package\Core\Logging\Log. It may be useful to give such classes shorter and easier to type names:

You may also bind aliases to callables or singletons.

Custom Resolvers

There may be times when you want to match far more than a single alias. Custom resolvers were designed with this purpose in mind. When a binding is requested from Phi, any custom resolvers that are registered will be executed one by one in the order they were added, and the first one to return a non-null value is the one that will be used. If all custom resolvers return null, Phi will resolve the binding normally.

Another reason to use custom resolvers is to wrap other IoC containers. For example, if you are using Laravel, you could combine the Laravel container with Phi:

This way, any binding that is registered in the Laravel IoC container will be resolved by it. The rest will be passed on to Phi.

Recursive Resolution

It's possible to bind one binding to another.

php $phi->singleton(FooInterface::class, Foo::class);



The first time an instance of `FooInterface` is requested, `Foo` will be loaded and bound.  From then on, all
requests for `FooInterface` will return the same instance of `Foo`.

### Dependency Injection on Callables
Not only is dependency injection useful when creating objects, it may also be useful when calling methods.  Phi can
perform dependency injection on any method PHP will accept as a `callable` type hint.

You may pass arguments to method injections in the same way as constructor injections.

All versions of phi with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
raphhh/trex-reflection Version ^1.1
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 bapcat/phi contains the following files

Loading the files please wait ....