Phred/bin/phred
Funky Waddle 54303282d7
Some checks failed
CI / PHP ${{ matrix.php }} (8.1) (push) Has been cancelled
CI / PHP ${{ matrix.php }} (8.2) (push) Has been cancelled
CI / PHP ${{ matrix.php }} (8.3) (push) Has been cancelled
Too many things
2026-01-06 11:02:05 -06:00

81 lines
2.7 KiB
PHP

#!/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';
$generators = [
'create:controller',
'create:view',
'create:model',
'create:migration',
'create:seed',
'create:test'
];
if (is_dir($coreDir)) {
foreach (glob($coreDir . '/*.php') as $file) {
/** @var \Phred\Console\Command $cmd */
$cmd = require $file;
if ($cmd instanceof \Phred\Console\Command) {
$app->add($cmd->toSymfony());
// 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:shop: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());
}
}
}
}
}
}
// 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();
}