Add new console system

This commit is contained in:
Gregory Letellier
2023-11-13 11:41:47 +01:00
parent 610ed871bb
commit 9eeb3d353d
5 changed files with 545 additions and 487 deletions

38
console Normal file
View File

@@ -0,0 +1,38 @@
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Application;
set_time_limit(0);
/**
* Loading path constant
*/
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
function findCommandClasses($directory)
{
$commandClasses = [];
$files = glob($directory . '/*.php');
foreach ($files as $file) {
$commandClasses[] = basename($file, '.php');
}
return $commandClasses;
}
/**
* Enable autoload
*/
require_once ROOT . DS . 'vendor'. DS . 'autoload.php';
$application = new Application();
// Load all commands in Commands folder
$command_directory = ROOT . DS . 'src' . DS . "Commands";
$commandClasses = findCommandClasses($command_directory);
foreach ($commandClasses as $commandClass) {
$clsname = "App\\Commands\\$commandClass";
$application->add(new $clsname());
}
$application->run();