Skip to content

Commit

Permalink
Add routes action (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Dec 4, 2022
1 parent d4423ba commit cf964f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/routes.php
Expand Up @@ -88,6 +88,9 @@ static function (ResponseFactoryInterface $responseFactory, ValidatorInterface $
Route::get('/files')
->action([InspectController::class, 'files'])
->name('files'),
Route::get('/routes')
->action([InspectController::class, 'routes'])
->name('routes'),
Route::get('/translations')
->action([InspectController::class, 'getTranslations'])
->name('getTranslations'),
Expand Down
20 changes: 20 additions & 0 deletions src/Controller/InspectController.php
Expand Up @@ -17,6 +17,7 @@
use Yiisoft\Aliases\Aliases;
use Yiisoft\Config\ConfigInterface;
use Yiisoft\DataResponse\DataResponseFactoryInterface;
use Yiisoft\Router\RouteCollectionInterface;
use Yiisoft\Translator\CategorySource;
use Yiisoft\VarDumper\VarDumper;
use Yiisoft\Yii\Debug\Api\Inspector\ApplicationState;
Expand Down Expand Up @@ -279,6 +280,25 @@ public function getCommands(ConfigInterface $config): ResponseInterface
return $this->responseFactory->createResponse($result);
}

public function routes(RouteCollectionInterface $routeCollection): ResponseInterface
{
$routes = [];
foreach ($routeCollection->getRoutes() as $route) {
$data = $route->__debugInfo();
$routes[] = [
'name' => $data['name'],
'hosts' => $data['hosts'],
'pattern' => $data['pattern'],
'methods' => $data['methods'],
'defaults' => $data['defaults'],
'override' => $data['override'],
'middlewares' => $data['middlewareDefinitions'],
];
}
$response = VarDumper::create($routes)->asJson(false, 5);
return $this->responseFactory->createResponse(json_decode($response, null, 512, JSON_THROW_ON_ERROR));
}

public function runCommand(
ServerRequestInterface $request,
ContainerInterface $container,
Expand Down

0 comments on commit cf964f4

Please sign in to comment.