Download the PHP package luoluolzb/di without Composer

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

DI

一个简单而实用的psr-11依赖注入容器。 A simple dependency injection container for psr-11.

安装

使用 composer 安装:

使用

实例化

使用容器之前需要实例化:

注入实体

使用set($id, $entity)方法注入一个实体,实体可以是一个函数(注入服务),可以是一个类实例(不推荐直接注入类实例,应该使用在函数中注册),还可以是其他任何类型:

如果注入的实体为一个匿名函数,那么我们可以使用匿名函数的第一个参数访问容器实例:

还可以在实例化的时候一次注入多个实体:

工厂方式注入实体

使用 set 或者数组式注入实体时,每次取出的都为同一对象实例,想要每次取出时都重新创建实例使用 factory 方法:

如果是通过构造函数一次注入了多个实体,想要使用工厂方式需提供第二个参数指定实体:

这样就将 myClass 指定为工厂创建模式,其他的仍然为单一实例模式。

获取实体

使用get($id)方法从容器中获取一个实体:

注意:如果要取出的实体为一个匿名函数或者其他可调用的类型,那么该匿名函数每次取出时都会调用。如果需要使用单例模式应该这样注入:

如果要取出的实体为其他类型(非可调用类型),那么会直接返回原来注入的实体。

删除实体

从容器中删除一个实体使用delete($id)方法:

判断实体是否存在

判断容器中是否存在某个实体使用has($id)方法:

像数组一样访问容器

容器实现了ArrayAccess接口,因此可以像访问数组的方式来访问容器:

容器中实体数量

使用容器的count()方法获取容器中实体数量:

容器实现了Countable接口,还可以直接使用PHP的count()函数()获取实体数量:


All versions of di with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
psr/container Version ^1.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 luoluolzb/di contains the following files

Loading the files please wait ....