Download the PHP package fanqingxuan/container without Composer

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

起因

Laravel是一个很优雅的框架,这一点不容置疑,laravel实现的很松耦合,有些组件库可以在自己的非laravel项目里用(只要你的项目使用composer),比如illuminate/database这个orm,就是一个独立的repository,我们composer执行下面的命令就可以将laravel的数据库orm安装到自己的项目了

个人对Laravel的服务容器很感兴趣,想单独拿出来用,高兴的是官方也将Container容器单独抽离出一个仓库illuminate/container,我看了下这个仓库下的composer.json文件,依赖illuminate/contracts仓库,通过阅读Container类我发现其实只依赖illuminate/contracts下的container约定,其它的约定完全不需要,也就是说illuminate/contracts仓库下面的其它契约成了多余的代码,这对我来说完全受不了,容忍不了多余没有用的代码。

因此我就单独拉了一个仓库,代码完全来自illuminate/container仓库以及illuminate/contracts仓库下Illuminate/Contracts/Container命名空间下的代码,当然为了使用composer,所以我需要改下仓库,因此命名空间变更成了自己的命名空间,其它Laravel服务容器原有相关的方法100%可用;另外有些原有的功能在手册或者教程上并没有,通过阅读代码发现了已有的功能,也罗列出了用法

安装

demo

看下面的例子

有没有发现,每一个类不再依赖具体的实现类,通过依赖注入容器实现控制反转

使用

意思是当一个类需要实现 Cache 时,应该注入 RedisCache,注入依赖项时,我们就可以使用注入Cache接口,而不需要注入具体实现,就像上面demo中的注入依赖项UserService接口,而不是具体实现

根据输出可以反省,UserService注入的是Memcache,而OrderService注入的是Redis

解析服务

使用 make 方法从容器中解析出类实例。 make 方法接收你想要解析的类或接口的名字

如果类依赖不能通过容器解析,你可以通过将它们作为关联数组作为 makeWith 、make 方法的参数注入:

容器事件

服务容器每次解析对象会触发一个事件,你可以使用 resolving 方法监听这个事件 :

PSR-11

Laravel服务容器实现了PSR-11接口,所以可以使用PSR-11接口提供的方法来获取服务

ArrayAccess

Laravel服务容器实现了ArrayAccess接口,因此可以像数组一样为容器注入服务,获取服务等操作

魔术方法

Laravel服务容器还实现了get,set魔术方法,因此我们可以用属性的方式进行服务注入和访问

Laravel服务容器的其它方法


All versions of container with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3
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 fanqingxuan/container contains the following files

Loading the files please wait ....