Download the PHP package miladrahimi/phpcontainer without Composer

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

Build codecov Scrutinizer Code Quality

PhpContainer

A dependency injection (Inversion of Control) container written in PHP programming language, compliant with PSR-11 standards.

Features:

Overview

Dependency Inversion is a fundamental concept in Object-oriented design.

It leads to important ideas like Dependency Injection, Inversion of Control, and the creation of an IoC Container.

For PHP projects, there's the PhpContainer, a handy tool that provides a dependency injection container (IoC Container) conforming to PSR-11 standards.

Installation

To integrate PhpContainer into your project, use the following Composer command:

Documentation

Explicit Binding

Explicit binding involves directly linking an abstraction to a concrete implementation. This binding can be achieved by using the singleton(), transient(), and closure() methods.

Binding Methods

The following example demonstrates the differences between singleton and transient binding.

Implicit Binding

When the container needs a class without a specific binding, it tries to create an instance. In the example below, it instantiates the MySQL class in the provided code. But if it encounters an abstract class or an interface that can't be instantiated directly, an error occurs.

Binding to Objects

You can connect abstracts to specific objects. Using singleton binding gives you the original object when required, while transient binding offers a fresh copy of the object every time you ask for it.

Constructor Auto-injection

Concrete classes might contain constructor parameters that either possess default values or can be resolved by the container.

Binding Using Closure

The following example illustrates how to bind using Closure.

In singleton binding, the container executes the Closure once and retrieves the result whenever needed. Conversely, in transient binding, the container invokes the Closure each time it's required. If you intend to bind an abstraction to a Closure without immediate invocation by the container, you can use the closure() method instead.

Resolving Using Closure

You have the option to use the call method, allowing the container to execute the provided function or closure and resolve its arguments.

Type-based and name-based binding

PhpContainer supports typed-based and name-based bindings. The following example demonstrates these types of bindings.

Error handling

The ContainerException might be raised by the container for several reasons. It can arise when a ReflectionException occurs, indicating a missing concrete implementation for a provided abstraction. Additionally, this exception occures when the container cannot inject parameter values into concrete constructors or closures.

License

PhpContainer is created by Milad Rahimi and released under the MIT License.


All versions of phpcontainer with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
psr/container Version ^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 miladrahimi/phpcontainer contains the following files

Loading the files please wait ....