240 发简信
IP属地:广东
  • class Di
    {
    protected $_service = [];
    protected $_sharedService = [];
    public function set($name, $definition, $shared = false)
    {
    if ($shared) {
    $this->_sharedService[$name] = $definition;
    } else {
    $this->_service[$name] = $definition;
    }
    }
    public function get($name) {
    if (isset($this->_service[$name])) {
    $definition = $this->service[$name];
    } else if ($this->_sharedService[$name]) {
    $definition = $this->_sharedService[$name];
    } else {
    throw new Exception("Service '" . name . "' wasn't found in the dependency injection container");
    }
    ...
    }

    如果某个服务在一次请求中要调用多次,你就可以将shared属性设置为true,以减少不必要的浪费。请问这段代码如何理解这句话的?

    依赖注入(DI)在PHP中的实现

    什么是依赖注入? IOC:英文全称:Inversion of Control,中文名称:控制反转,它还有个名字叫依赖注入(Dependency Injection,简称DI)...

  • 小美妞:smile:

    关于吃的

    时光漫漫,越来发现自己喜欢厨艺,喜欢捣鼓一些吃的。回想自己小学四年级时候很害怕听别人说起他家的孩子多能做饭啊什么的,一对比自己在爸爸妈妈的庇护下疼爱下都没有做过饭,一直觉得自...