Home  >  Article  >  php教程  >  LotusPhp笔记之:基于ObjectUtil组件的使用分析

LotusPhp笔记之:基于ObjectUtil组件的使用分析

WBOY
WBOYOriginal
2016-06-13 11:52:52792browse

ObjectUtil组件其实就是单例模式的最好范例,声明调用各个组件的时候,用ObjectUtil调用,可以有效的防止调用过多的类而导致错误或者资源浪费。

比如调用Db组件,这样声明就可以了

$db = LtObjectUtil::singleton('LtDb');

singleton方法是LtObjectUtil类中唯一的方法,目的就是声明类库,如果该类库存在init()方法,然后调用该类库的init()的方法。

ObjectUtil 还有一个快速调用的函数,可以在框架里或者模板里进行快速调用

格式如下:

C('LtDb');

其实就是函数内部调用的LtObjectUtil::singleton('LtDb');

LotusPhp 是不太主张过多的使用静态类的,这个是框架中唯一的静态类。

对于静态类的优劣,不是今天说的主题,不过大家可以看看这篇基于PHP静态类的原罪详解>的文章,就是说静态类的,可以作为参考。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn