Download the PHP package pyther/ioc without Composer

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

Pyther.Ioc

A simple lightweight PHP Inversion of Control (IoC) container with the following features:

Requirements

Quickstart

Install the Composer Package

composer require pyther/ioc

And here is a fictional example. Inversion of Control is a two way process. First you have to bind implementations of interfaces or classes to the container and then resolve (one or multile times) the creation of instances.

Why using an Ioc container

An IoC Container simplifies the creation of instances. It resolves object dependencies and is optimized to create instances on first use. It also makes it possible to replace classes with other (mock) implementations by changing one line of code. And it works perfectly with constructor dependency injections, forcing you to write cleaner code. It can also replace "global" collection classes.

In short, you define how instances are to be created, not when.

Binding

There are two general ways to bind implementations to the container.

BindSingleton

If you bind using bindSingleton the instance will be created on first use of Ioc::get(ShoppingCart::class). All subsequent calls to the get method will always return the same instance.

BindMultiple

This way any call of Ioc::get(Product::class) will return a new instance of the Product class.

Dependency Injection

A "Inversion of Control" container goes hand in hand with Constructor Dependency Injection.

Let's look at an example. Imagine we have a shopping cart, that depends of the current logged in customer:

If we bind the ShoppingCart and Customer class to the IoC container

and we resolve the ShoppingCart class using

the container want to create a new shopping cart and see it requires a customer class. For this reason, a Customer instance is first created and passed as a parameter to the constructor of the ShoppingCart. This nesting is recursive and takes into account “singletons” and “multiple” instances. Of course, multiple constructor arguments are supported and cyclic dependencies are recognized when resolving via the get method and will fire a Pyther\Ioc\Exceptions\ResolveException exception.

More control

This library gives you a lot control how objects will be instanced.

More binding control

For example you can add your own constructor arguments:

As you can see, the default values for constructors are taken into account if no arguments are found.

Another way is to create a anonymous construct function:

This function is only executed later when the object is first instantiated.

This way you can also have function arguments:

This construct function can be also be a static method of another object:

Or as a method of an already instanced object:

Auch ein binding auf null ist legitim:

In diesem Fall wird beim Auflösen keine Exception ausgelöst, sondern auf null aufgelöst.

And finally you can also bind an already existing objects:

Although this is possible, it should be avoided. On the one hand, the creation of the instances should be left to the container, on the other hand this triggers the autoloader and executes code that may never be used.

More resolve control

For non singleton instances you can specifiy constructor arguments during the resolve phase:

Check if binding exists

To check if a binding exists, you can use the has method:

Multiple Containers

If you have the rare case where you need more than one container, here we are. The static methods of Ioc::bindSingleton(...), Ioc::bindMultiple(...) and Ioc::get(...) are suggar forms of

where Ioc::$default is the default container. This way you can have separated multiple containers:

I'm sure you get it :)


All versions of ioc with dependencies

PHP Build Version
Package Version
Requires php Version >=8.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 pyther/ioc contains the following files

Loading the files please wait ....