导读,今天我们紧接着前几天的内容,学习 Slim/Route.php 类的功能
先看一下该类被调用的地方
在 Slim/Router.php 类中的 createRoute 方法中
protected function createRoute($methods, $pattern, $callable)
{
$route = new Route($methods, $pattern, $callable, $this->routeGroups, $this->routeCounter);
if (!empty($this->container)) {
$route->setContainer($this->container);
}
return $route;
}
首先我们看下Slim/Route.php 类的构造函数
public function __construct($methods, $pattern, $callable, $groups = [], $identifier = 0)
{
$this->methods = is_string($methods) ? [$methods] : $methods;
$this->pattern = $pattern;
$this->callable = $callable;
$this->groups = $groups;
$this->identifier = 'route' . $identifier;
}
下面我们分别看一下,每个传入参数的值这里以http://localhost:8080/hello/world 为例子
$method
array(1) {
[0]=>
string(3) "GET"
}
$pattern
string(13) "/hello/{name}"
$callable
object(Closure)#19 (2) {
["this"]=>
object(Slim\Container)#3 (7) {
["defaultSettings":"Slim\Container":private]=>
array(7) {
["httpVersion"]=>
string(3) "1.1"
["responseChunkSize"]=>
int(