123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- class Container {
- /**
- * 容器对象实例
- * @var Container
- */
- static $instance;
- /**
- * 容器中的对象实例
- * @var array
- */
- instances = {};
- static getInstance() {
- if (Container.$instance == null) {
- Container.$instance = new Container();
- }
- return Container.$instance;
- }
- /**
- * 获取容器中的对象实例
- * @access public
- * @param string name 类名或者标识
- * @return object
- */
- static get(name) {
- return Container.getInstance().instances[name];
- }
- /**
- * 移除容器中的对象实例
- * @access public
- * @param string name 类标识、接口
- * @return void
- */
- static remove(name) {
- return Container.getInstance().del(name);
- }
- /**
- * 创建类的实例
- * @access public
- * @param string vImport 导入improt
- * @param {} vars 变量
- * @return object
- */
- make(vImport, alias, vars = "default") {
- this.instances[alias] = vars == "" ? vImport : vImport[vars];
- return this.instances[alias];
- }
-
- /**
- * 获取容器中的对象实例
- * @access public
- * @param string name 类名或者标识
- * @return object
- */
- get(name) {
- return this.instances[name];
- }
-
- /**
- * 删除实例对象
- * @param {Object} name
- */
- del(name) {
- delete this.instances[name];
- }
-
- }
- export default Container;
|