public function getAllByMiddleware($mw) { $routeList = array(); $routes = $this->route->getRoutes()->getRoutes(); foreach ($routes as $route) { $uri = $route->getUri(); $action = $route->getAction(); $method = $this->getMethod($route); $id = $this->getRouteHashId($route); if (in_array($mw, $action)) { if (!$action['uses'] instanceof \Closure) { $arr = ['id' => $id, 'uri' => $uri, 'method' => $method, 'action' => $action['uses'], 'status' => 'VALID']; } else { $dump = closure_dump($action['uses']); $func = $dump['file'] . '[' . $dump['line'] . ']'; $arr = ['id' => $id, 'uri' => $uri, 'method' => $method, 'action' => $func, 'status' => 'VALID']; } array_push($routeList, $arr); } } return $routeList; }
/** * 将变量转为输出到字符串 * @param mixed $expression * @param boolen $escape * @return string */ function custom_var_export($expression, $escape = true) { $str = ''; if (is_array($expression)) { $str .= 'array('; foreach ($expression as $key => $val) { $str .= "'" . $key . "' => " . custom_var_export($val) . ','; } $str .= ')'; } else { if ($expression instanceof \Closure) { $str .= closure_dump($expression); } else { $str .= var_export($expression, true); } } return $str; }