Slim 框架學習,第二天
阿新 • • 發佈:2019-01-22
緊接著第一天的內容
今天主要說下,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的實現原理。