Files
scoutiq/cli.php

71 lines
2.0 KiB
PHP

<?php
if (php_sapi_name() !== 'cli') {
die("This script can only be run from the command line.");
}
require __DIR__ . '/vendor/autoload.php';
// Bootstrap Environment configurations
$localEnv = __DIR__ . '/.env';
$parentEnv = __DIR__ . '/../..';
if (file_exists($localEnv)) {
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
} elseif (file_exists($parentEnv . '/.env')) {
$dotenv = Dotenv\Dotenv::createImmutable($parentEnv);
$dotenv->load();
}
require_once __DIR__ . '/database/seeds/DatabaseSeeder.php';
use App\Core\Container;
use App\Services\Database\Connection;
use App\Services\Database\MigrationRunner;
use Database\Seeds\DatabaseSeeder;
$container = new Container();
// Singletons configurations
$container->singleton(Connection::class, Connection::class);
$container->singleton(MigrationRunner::class, MigrationRunner::class);
$container->singleton(DatabaseSeeder::class, DatabaseSeeder::class);
$args = $argv;
$command = $args[1] ?? 'help';
switch ($command) {
case 'migrate':
echo "=== Running Migrations ===\n";
try {
$runner = $container->get(MigrationRunner::class);
$runner->migrate();
} catch (\Throwable $e) {
echo "Migration failed: " . $e->getMessage() . "\n";
exit(1);
}
break;
case 'seed':
echo "=== Running Database Seeder ===\n";
try {
$seeder = $container->get(DatabaseSeeder::class);
$seeder->seed();
} catch (\Throwable $e) {
echo "Seeding failed: " . $e->getMessage() . "\n";
exit(1);
}
break;
case 'help':
default:
echo "ScoutIQ CLI Utility\n";
echo "Usage: php cli.php [command]\n\n";
echo "Commands:\n";
echo " migrate Run SQL database migrations\n";
echo " seed Seed the database with default data\n";
echo " help Show this help menu\n";
break;
}