您的位置:首页 > 其它

Slim 框架学习,第二天

2017-11-29 21:18 239 查看

紧接着第一天的内容

今天主要说下,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.php

public 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的实现原理。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  框架