Download the PHP package stubbles/ioc without Composer

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

stubbles/ioc

Dependency injection.

Build status

Tests

Latest Stable Version

Installation

stubbles/ioc is distributed as Composer package. To install it as a dependency of your package use the following command:

composer require "stubbles/ioc": "^11.0"

Requirements

stubbles/ioc requires at least PHP 8.2.

Inversion of Control

stubbles/ioc provides a very simple-to-use but still powerful inversion of control container, which supports constructor and setter based dependency injection. The IoC container of stubbles/ioc is modeled after Google Guice and makes use of type hinting annotations. If you've never heard of type hinting or annotations, you should at first read the sections on these two topics:

The example code

Imagine, you are building a car configurator. To follow the rules of good design, you define interfaces for all components of a car and provide several classes that implement these components.

The interfaces in you application include:

The implementations are:

Without the dependency injection framework

To create a new instance of an implementation of Car the following code is required:

Creating objects manually like this has several drawbacks:

Of course, real applications have a lot more classes, so things only get worse then.

Enter 'Inversion of Control'

stubbles/ioc tries to solve these problems by providing functionality to handle all dependency injections for you. This keeps your application clean of boilerplate code.

Furthermore, it allows you to centralize and/or modularize the definition of the concrete implementations for your interfaces or abstract types.

A simple example

To define the concrete implementations is done using an instance of stubbles\ioc\Binder:

In this short code snippet, you bound the interfaces from the example above to their concrete implementations.

If you now need an instance of the engine, you use the binder to create a stubbles\ioc\Injector, which can be used to create the desired Engine:

This code snippet will now display:

As desired, it created an instance of the concrete implementation, that you bound to the interface.

Next, you probably want to get an instance of Car using the same approach:

stubbles/ioc created a new instance of BMW, as you bound it to Car, and as the constructor of BMW requires a Tire and an Engine instance, it created these instances as well. To determine the concrete classes to use, stubbles/ioc used the bindings you defined in the stubbles\ioc\Binder instance.

What you also can see is, that Stubbles did not inject an object into the $driver property, although you specified a binding for Person. stubbles/ioc will never inject any dependencies via setter methods.

Further features


All versions of ioc with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
stubbles/sequence Version ^10.1
stubbles/values Version ^11.0
stubbles/reflect Version ^10.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 stubbles/ioc contains the following files

Loading the files please wait ....