Download the PHP package jitesoft/container without Composer

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

pipeline status coverage report Back project Maintainability

Container

IoC container with constructor dependency injection.

Bindings

The container binds a key to a value where the value can be any type or a class name.

If it is a object, primitive or any type of instance, it will store the instance as a static object, that is: the same object will be returned at each get call. While if a class name is passed the container will try to create an instance of the class on each get call. If it can not create an instance, a NotFoundException or ContainerException will be thrown.

The binding can be done at creation by passing an associative array into the constructor, or by using the set method. To re-bind, the rebind method - accepting a key and a value - can be used.

The container implements the PSR-11 Container interface. Further, the container implements the ArrayAccess interface, enabling fetching by using the array index syntax as: $container[Interface::class].

Usage

The container implements the following interfaces:

The ArrayAccess interface allows for getting, setting and un-setting bindings through the array index syntax:

Furthermore, the class implements the following public methods:

The constructor of the class takes an optional bindings array. The array expected to be an associative array containing the abstract as key and concrete as value. If wanted, the concrete could be another associative array with a class or func key containing the class or callable to resolve to/with and a singleton key with a boolean value.
If the singleton key is true, the container will only ever create a single instance of the resolved value or only run the resolve function once.

Example:

Alternatively to the array type singleton binding, the interface will create a singleton binding with the singleton method.

Rebinding can be done in runtime with the $container->rebind($a, $c, $singleton); method.
This will unset the earlier binding and create a new.

To remove all the current bindings, the $container->clear(); method can be used, which will empty the inner list of entries. Observe that this will not clear up the currently resolved instances of objects stored in your classes, but rather just remove all the entries from the container.

All the methods implemented in the class (with an exception in the has and clear methods) will throw exceptions on errors.
The following two exceptions are used:

So when checking for exceptions, one could use either the underlying JitesoftException class, the specific classes or the interfaces.
Observe though that the NotFoundException inherits from the ContainerException so in the cases where both can be returned and you want to catch the specific exceptions, catch the NotFoundException before the ContainerException.

Dependency injection

The container will, in the cases where it is able to, inject dependencies into the constructor when resolving the object.
There are some requirements before it will be able to do this though:

  1. The parameter need to be typehinted.
  2. The parameter need to be possible to resolve in the container or be possible to creat without constructor.

If the container can not resolve the parameter, it will throw an exception, but following the above two requirements, this should not happen.

Not only classes

The container does not only resolve bindings, but can be used to store other values too.
If the passed concrete is not a class name, it will use it as a single value and not resolve. So passing a string or number as the concrete will make the get method return the value.

License

MIT


All versions of container with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
psr/container Version ^2
jitesoft/exceptions Version ^2.4
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 jitesoft/container contains the following files

Loading the files please wait ....