2025-12-14 23:10:01 +00:00
|
|
|
#!/usr/bin/env php
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
// Ensure composer autoload is available whether this is run from repo or installed project
|
|
|
|
|
$autoloadPaths = [
|
|
|
|
|
__DIR__ . '/../vendor/autoload.php', // project root vendor
|
|
|
|
|
__DIR__ . '/../../autoload.php', // vendor/bin scenario
|
|
|
|
|
];
|
|
|
|
|
$autoloaded = false;
|
|
|
|
|
foreach ($autoloadPaths as $path) {
|
|
|
|
|
if (is_file($path)) {
|
|
|
|
|
require $path;
|
|
|
|
|
$autoloaded = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!$autoloaded) {
|
|
|
|
|
fwrite(STDERR, "Unable to locate Composer autoload.\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$app = new \Symfony\Component\Console\Application('Phred', '0.1');
|
|
|
|
|
|
|
|
|
|
// Discover core commands bundled with Phred (moved under src/commands)
|
|
|
|
|
$coreDir = dirname(__DIR__) . '/src/commands';
|
2025-12-22 21:52:41 +00:00
|
|
|
$generators = [
|
|
|
|
|
'create:controller',
|
|
|
|
|
'create:view',
|
|
|
|
|
'create:model',
|
|
|
|
|
'create:migration',
|
|
|
|
|
'create:seed',
|
|
|
|
|
'create:test'
|
|
|
|
|
];
|
|
|
|
|
|
2025-12-14 23:10:01 +00:00
|
|
|
if (is_dir($coreDir)) {
|
|
|
|
|
foreach (glob($coreDir . '/*.php') as $file) {
|
2025-12-22 21:52:41 +00:00
|
|
|
/** @var \Phred\Console\Command $cmd */
|
2025-12-14 23:10:01 +00:00
|
|
|
$cmd = require $file;
|
|
|
|
|
if ($cmd instanceof \Phred\Console\Command) {
|
|
|
|
|
$app->add($cmd->toSymfony());
|
2025-12-22 21:52:41 +00:00
|
|
|
|
|
|
|
|
// If it's a generator, also register module-specific versions
|
|
|
|
|
if (in_array($cmd->getName(), $generators, true)) {
|
|
|
|
|
$modulesDir = getcwd() . '/modules';
|
|
|
|
|
if (is_dir($modulesDir)) {
|
|
|
|
|
foreach (scandir($modulesDir) as $module) {
|
|
|
|
|
if ($module === '.' || $module === '..' || !is_dir($modulesDir . '/' . $module)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// Create a module-specific command name: create:blog:controller
|
|
|
|
|
$moduleCmdName = str_replace('create:', 'create:' . strtolower($module) . ':', $cmd->getName());
|
|
|
|
|
|
|
|
|
|
// We need a fresh instance for each command name to avoid overwriting Symfony's command registry
|
|
|
|
|
$moduleCmd = require $file;
|
|
|
|
|
$moduleCmd->setName($moduleCmdName);
|
|
|
|
|
$app->add($moduleCmd->toSymfony());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-14 23:10:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Discover user commands in console/commands
|
|
|
|
|
$userDir = getcwd() . '/console/commands';
|
|
|
|
|
if (is_dir($userDir)) {
|
|
|
|
|
foreach (glob($userDir . '/*.php') as $file) {
|
|
|
|
|
$cmd = require $file;
|
|
|
|
|
if ($cmd instanceof \Phred\Console\Command) {
|
|
|
|
|
$app->add($cmd->toSymfony());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run
|
|
|
|
|
$app->run();
|
|
|
|
|
}
|