Add new console system
This commit is contained in:
@@ -2,5 +2,6 @@
|
||||
<ruleset>
|
||||
<rule ref="PSR12"/>
|
||||
<file>src/</file>
|
||||
<file>console</file>
|
||||
<arg name="colors"/>
|
||||
</ruleset>
|
||||
@@ -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
964
composer.lock
generated
File diff suppressed because it is too large
Load Diff
38
console
Normal file
38
console
Normal 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();
|
||||
24
src/Commands/TestCommand.php
Normal file
24
src/Commands/TestCommand.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user