Slim 框架学习,第二天

来源:互联网 发布:nginx rtmp hls 配置 编辑:程序博客网 时间:2024/06/14 01:56

紧接着第一天的内容

今天主要说下,App类中的map 方法 中的
route=this->container->get(‘router’)->map(methods,pattern, $callable);
该方法。

跳转过程

Container 类public function get($id)    {        if (!$this->offsetExists($id)) {            throw new ContainerValueNotFoundException(sprintf('Identifier "%s" is not defined.', $id));        }        try {            return $this->offsetGet($id);        } catch (\InvalidArgumentException $exception) {            if ($this->exceptionThrownByContainer($exception)) {                throw new SlimContainerException(                    sprintf('Container error while retrieving "%s"', $id),                    null,                    $exception                );            } else {                throw $exception;            }        }    }
路径 vendor/pimple/pimple/src/Pimple/Container.phppublic function offsetGet($id)    {        if (!isset($this->keys[$id])) {            throw new UnknownIdentifierException($id);        }        if (            isset($this->raw[$id])            || !is_object($this->values[$id])            || isset($this->protected[$this->values[$id]])            || !method_exists($this->values[$id], '__invoke')        ) {            return $this->values[$id];        }        if (isset($this->factories[$this->values[$id]])) {            return $this->values[$id]($this);        }        $raw = $this->values[$id];        $val = $this->values[$id] = $raw($this);        $this->raw[$id] = $raw;        $this->frozen[$id] = true;        return $val;    }
  • 在这里返回了router 对象,其中 val=this->values[id]=raw($this); 没有看太明白。
  • 这里牵扯到了一个类,就是 DefaultServicesProvider,这里是他的服务提供者类。需要重点理解下。
  • 明天重点工作,研究DefaultServicesProvider的实现原理。