Atlas/atlas

48 lines
1.4 KiB
Plaintext
Raw Normal View History

<?php
require_once __DIR__ . '/vendor/autoload.php';
use Atlas\Router\Router;
use Atlas\Config\Config;
use Atlas\Commands\ListRoutesCommand;
use Atlas\Commands\TestRouteCommand;
$command = $argv[1] ?? 'help';
$config = new Config([
'modules_path' => __DIR__ . '/src/Modules',
'routes_file' => 'routes.php'
]);
$router = new Router($config);
// Load routes from a central routes file if it exists, or provide a way to load them
// For this CLI tool, we might need a way to bootstrap the application's router.
// Usually, this would be part of a framework. For Atlas as a library, we provide
// the tool that can be integrated.
// In a real scenario, the user would point this tool to their router bootstrap file.
// For demonstration, let's assume we have a `bootstrap/router.php` that returns the Router.
$bootstrapFile = getcwd() . '/bootstrap/router.php';
if (file_exists($bootstrapFile)) {
$router = require $bootstrapFile;
}
switch ($command) {
case 'route:list':
(new ListRoutesCommand())->execute($router, $argv);
break;
case 'route:test':
(new TestRouteCommand())->execute($router, $argv);
break;
default:
echo "Atlas Routing CLI" . PHP_EOL;
echo "Usage:" . PHP_EOL;
echo " php atlas route:list [--json]" . PHP_EOL;
echo " php atlas route:test <METHOD> <PATH> [--verbose]" . PHP_EOL;
break;
}