紧接着第二天的内容
先上一段代码
public function offsetGet($id)
{
echo $id."<br/>";
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);
}
echo $id.'1'."<br/>";
$raw = $this->values[$id];
echo $id.'2'."<br/>";
$val = $this->values[$id] = $raw($this);
// die();
// echo $id.'3'.'___';
$this->raw[$id] = $raw;
$this->frozen[$id] = true;
echo "<pre>";
echo $id.'___';
//var_dump($this->values);
echo "</pre>";
die();
return $val;
}
返回结果让我很想不通
router
router1
router2
settings
settings1
settings2
settings___
为何传进去的是router,却执行了settings 。经过调试发现
val= this->values[ id]= raw($this);这一句,导致的原因,
但是为什么会出现这种情况,现在还没搞明白。
回到第一天的index.php 文件
require 'vendor/autoload.php';
$app = new Slim\App();
$app->get('/hello/{name}', function ($request, $response, $args) {
return $response->write("Hello, " . $args['name']);
});
echo "<pre>";
var_dump($app);
echo "</pre>";die();
$app->run();
返回结果如下
object(Slim\App)#2 (3) {
[“container”:”Slim\App”:private]=>
object(Slim\Container)#3 (7) {
[“defaultSettings”:”Slim\Container”:private]=>
array(7) {
[“httpVersion”]=>
string(3) “1.1”
[“responseChunkSize”]=>
int(4096)
[“outputBuffering”]=>
string(6) “append”
[“determineRouteBeforeAppMiddleware”]=>
bool(false)
[“displayErrorDetails”]=>
bool(false)
[“addContentLengthHeader”]=>
bool(true)
[“routerCacheFile”]=>
bool(false)
}
….. // 主要设置了路由信息
[“router”]=>
object(Slim\Router)#21 (8) {
[“container”:protected]=>
RECURSION
[“routeParser”:protected]=>
object(FastRoute\RouteParser\Std)#22 (0) {
}
[“basePath”:protected]=>
string(0) “”
[“cacheFile”:protected]=>
bool(false)
[“routes”:protected]=>
array(1) {
[“route0”]=>
object(Slim\Route)#23 (13) {
[“methods”:protected]=>
array(1) {
[0]=>
string(3) “GET”
}
[“identifier”:protected]=>
string(6) “route0”
[“name”:protected]=>
NULL
[“groups”:protected]=>
array(0) {
}
[“finalized”:”Slim\Route”:private]=>
bool(false)
[“outputBuffering”:protected]=>
string(6) “append”
[“arguments”:protected]=>
array(0) {
}
[“callable”:protected]=>
object(Closure)#19 (2) {
[“this”]=>
RECURSION
[“parameter”]=>
array(3) {
[“ request”]=>string(10)“”[“ response”]=>
string(10) “”
[“$args”]=>
string(10) “”
}
}
[“container”:protected]=>
RECURSION
[“middleware”:protected]=>
array(0) {
}
[“pattern”:protected]=>
string(13) “/hello/{name}”
[“tip”:protected]=>
NULL
[“middlewareLock”:protected]=>
bool(false)
}
}
index.php 中的最后一行 $app->run(); 明天在进行探讨。