Download the PHP package kocuj/di without Composer

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

Kocuj DI

Container for design pattern Dependency Injection in PHP 7

Author Latest Version Github Issues Pending Pull-Requests Software License Build Status Coverage Status Quality Score Total Downloads

SensioLabsInsight

This package is compliant with PSR-1, PSR-2, PSR-4 and PSR-11. If you notice compliance oversights, please send a patch via pull request.

Download 1.4.1

Install

Via Composer:

Requirements

The following versions of PHP are supported by this version:

Documentation

In this documentation it is assumed that you will import namespaces for the Kocuj DI library by using the following code:

To use the Kocuj DI library you must first initialize it:

It will create a Kocuj DI library object. You can create more Di objects, but it is not recommended. The better solution is to create more DI containers, which will be explained in the next part of this documentation.

After the construction, the $di variable will have one container for Dependency Injection, which you can get by using the following code:

You can also create more containers:

You can also create new container based on already existing container by using the following code:

From now on you can use new container by using methods on $myContainer variable. However, the following documentation will use default container for explanations about using the Kocuj DI library.

After creating the container (default or other), you can add services into it. There are two types of services:

To create service you can use the following method: add(ServiceType $serviceType, string $id, string $source, array $arguments = []): ContainerInterface

The $serviceType argument can be one of the following:

If you want to ommit a $serviceType argument, you can use one of the following methods:

Argument $id is an identifier of created service. All identifiers will be automatically converted to camelCase format. Remember, that inside one container there can be only one service with the selected identifier.

Argument $source is a fully qualified class name for service. It is a good practice to use "::class" notation in this place.

For example, to add shared service from class \Services\Service with "someService" identifier, use the following code:

However, the best feature of the Kocuj DI library is to automatically resolving dependencies between services. To use this feature, there should be at least one argument sent to a service constructor. The place to do so is in $arguments argument.

Each argument in $arguments contains an array with one element with index "type" and second with index "value" which value depends on value set in index "type". Element with index "type" contains a name of argument type.

There are two types of arguments selected by element with index "type":

For example, to add shared service from class \Services\OtherService with "otherService" identifier, which has constructor __construct(\Services\Service $service, bool $status) and require $status to set to true, use the following code:

The order of adding services to container is not important, because during construction of service all dependencies will be automatically resolved.

To get service object you can use the following code:

or:

Additionally you can check type of service by using the following method: checkType(string $id, ServiceType $serviceType): bool. You can also check if service exists in container by using the following method: has($id): bool.

To control any wrong situations, there are the following exceptions available:

Example of using the library:

For more information you can see examples included in this project or by looking on project website.

Testing

Creating programming documentation

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please contact me by using contact form on project website instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.


All versions of di with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
psr/container Version ~1.0
danielstjules/stringy Version ~3.1
esky/enum 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 kocuj/di contains the following files

Loading the files please wait ....