/** * @param Route[] $routes */ protected function displayRoutes(array $routes) { $routeFilters = []; foreach ($routes as $route) { $before = array_keys($route->beforeFilters()); $before = array_unique(array_merge($before, $this->getPatternFilters($route))); $after = array_keys($route->afterFilters()); $routeFilters = array_unique(array_merge($routeFilters, $before, $after)); } natsort($routeFilters); foreach ($routeFilters as &$routeFilter) { $listenerClosure = Event::getListeners('router.filter: ' . $routeFilter)[0]; $reflectionFunction = new \ReflectionFunction($listenerClosure); $closureParser = new ClosureParser($reflectionFunction); $listenerName = $closureParser->getUsedVariables()['listener']; if (str_contains($listenerName, '@')) { $className = explode('@', $listenerName)[0]; $reflectionClass = new \ReflectionClass($className); $description = substr(explode("\n", $reflectionClass->getDocComment())[1], 3); } else { $description = 'UNKNOWN'; } $routeFilter = [$routeFilter, $listenerName, $description]; } $this->table(['Filter Name', 'Callback', 'Description'], $routeFilters); }
/** * @covers \Jeremeamia\SuperClosure\ClosureParser::getClosureAbstractSyntaxTree * @covers \Jeremeamia\SuperClosure\ClosureParser::getFileAbstractSyntaxTree */ public function testCanGetClosureAst() { $closure = function () { }; $parser = new ClosureParser(new \ReflectionFunction($closure)); $ast = $parser->getClosureAbstractSyntaxTree(); $this->assertInstanceOf('PHPParser_Node_Expr_Closure', $ast); }
public function getCode($name) { $parser = ClosureParser::fromClosure($this->funcs[$name]); return $parser->getCode(); }