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

View File

@@ -2,5 +2,6 @@
<ruleset>
<rule ref="PSR12"/>
<file>src/</file>
<file>console</file>
<arg name="colors"/>
</ruleset>

View File

@@ -10,7 +10,8 @@
"bramus/router": "~1.6",
"filp/whoops": "^2.15",
"symfony/var-dumper": "^6.3",
"eftec/bladeone": "^4.9"
"eftec/bladeone": "^4.9",
"symfony/console": "^6.3"
},
"repositories": [
{

964
composer.lock generated

File diff suppressed because it is too large Load Diff

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();

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class TestCommand extends Command
{
protected static $defaultName = 'app:test';
protected static $defaultDescription = 'Test.';
protected function configure(): void
{
$this->setHelp('Test');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln("test");
return Command::SUCCESS;
}
}