- Implement full suite of 'phred' CLI generators and utility commands (M9). - Refactor scaffolding logic to use external stubs in 'src/stubs'. - Add security hardening via SecureHeaders, Csrf, and CORS middleware (M10). - Implement JWT token issuance and validation service with lcobucci/jwt. - Integrate 'getphred/flagpole' for feature flag support. - Introduce abstract 'Middleware' base class for standardized PSR-15 implementation. - Add robust driver validation to OrmServiceProvider. - Fix JwtTokenService claims access and validation constraints. - Update MILESTONES.md status.
78 lines
2.6 KiB
PHP
78 lines
2.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use Phred\Console\Command;
|
|
use Symfony\Component\Console\Input\InputInterface as Input;
|
|
use Symfony\Component\Console\Output\OutputInterface as Output;
|
|
|
|
return new class extends Command {
|
|
protected string $command = 'create:migration';
|
|
protected string $description = 'Scaffold a new migration in a module.';
|
|
protected array $options = [
|
|
'name' => [
|
|
'mode' => 'argument',
|
|
'required' => true,
|
|
'description' => 'Migration name (e.g., CreatePostsTable)',
|
|
],
|
|
'module' => [
|
|
'mode' => 'argument',
|
|
'required' => false,
|
|
'description' => 'Target module name (e.g., Blog). Optional if using create:<module>:migration',
|
|
],
|
|
];
|
|
|
|
public function handle(Input $input, Output $output): int
|
|
{
|
|
$module = null;
|
|
if (preg_match('/^create:([^:]+):migration$/', $this->getName(), $matches)) {
|
|
$module = $matches[1];
|
|
}
|
|
|
|
if (!$module) {
|
|
$module = $input->hasArgument('module') ? $input->getArgument('module') : null;
|
|
}
|
|
|
|
$module = trim((string) $module);
|
|
$name = trim((string) $input->getArgument('name'));
|
|
|
|
if ($module === '' || $name === '') {
|
|
$output->writeln('<error>Module and Name are required.</error>');
|
|
return 1;
|
|
}
|
|
|
|
// Case-insensitive module directory lookup
|
|
$modulesDir = getcwd() . '/modules';
|
|
$moduleDir = null;
|
|
if (is_dir($modulesDir)) {
|
|
foreach (scandir($modulesDir) as $dir) {
|
|
if (strtolower($dir) === strtolower($module)) {
|
|
$moduleDir = $modulesDir . '/' . $dir;
|
|
$module = $dir; // Use actual casing
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$moduleDir || !is_dir($moduleDir)) {
|
|
$output->writeln("<error>Module '$module' does not exist.</error>");
|
|
return 1;
|
|
}
|
|
|
|
$migrationsDir = $moduleDir . '/Database/Migrations';
|
|
if (!is_dir($migrationsDir)) {
|
|
@mkdir($migrationsDir, 0777, true);
|
|
}
|
|
|
|
$timestamp = date('Y_m_d_His');
|
|
$filename = $timestamp . '_' . strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $name)) . '.php';
|
|
$path = $migrationsDir . '/' . $filename;
|
|
|
|
$template = file_get_contents(dirname(__DIR__) . '/stubs/migration.stub');
|
|
|
|
file_put_contents($path, $template);
|
|
$output->writeln("<info>Migration created</info> at modules/$module/Database/Migrations/$filename");
|
|
|
|
return 0;
|
|
}
|
|
};
|