Download the PHP package wazsmwazsm/ioc-container without Composer

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

Container

Build Status

安装

介绍

一个简单好用的 IOC 容器。

IOC 容器是一个特殊的工厂类,它可以帮助你获取你需要的对象,并自动帮你注入需要的依赖 (包括依赖的依赖注入,一直到没有依赖为止)。

IOC 容器提供了单例操作、获取实例、执行实例方法 (给方法注入依赖) 等功能,你可以使用 IOC 容器解决多重依赖的问题,提高开发的效率。

获取实例

Container 提供了 getInstance 方法来获取一个实例,由 getInstance 方法获取的实例会自动进行依赖注入。

如果注入的实例也有依赖的话,IOC 容器会继续向下查找依赖进行依赖注入,直到所有的依赖注入完成。

例如:

如果要获取实例的构造方法有其他参数,可以通过 getInstance 方法的第二个参数传入:

Container 还提供了获取实例单例的版本 getInstanceWithSingleton,如果要获取的实例没有设置单例,getInstanceWithSingleton 方法会将该实例设置为单例并返回该实例。

运行方法

Container 的 run 方法用来运行一个实例的方法,并且如果该方法有依赖则进行依赖注入。

例子:

你还可以使用 run 方法的第三个参数给要运行的方法传入额外参数:

如果要运行的实例的构造方法有其他参数,可以通过 run 方法的第四个参数传入:

单例

设置单例: singleton 方法

获取单例: getSingleton 方法

设置单例时还可以指定名称:

销毁单例:unsetSingleton 方法

单例注册

Container 提供了一个 register 方法用来注册单例。和 singleton 方法不同的是,register 方法可以实现自定义类替换抽象类的功能。这个功能可以让你更改实例时不用重写获取实例的代码。

如下所示,注册一个 Exceptions\ExceptionHandler 单例,实际注册的实例是 App\Exceptions\Handler,获取该实例时可以通过 Exceptions\ExceptionHandler::class 来获取。

当 register 方法的第二个参数不传时,默认使用抽象类的实例。

License

The IOCContainer is open-sourced software licensed under the MIT license.


All versions of ioc-container with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
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 wazsmwazsm/ioc-container contains the following files

Loading the files please wait ....