Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"source": "https://github.com/webman-php/console"
},
"require": {
"symfony/console": ">=5.0",
"php": ">=8.1",
"symfony/console": ">=6.0",
"doctrine/inflector": "^2.0"
},
"autoload": {
Expand All @@ -32,6 +33,6 @@
}
},
"require-dev": {
"workerman/webman": "^1.0"
"workerman/webman": "^2.1"
}
}
36 changes: 26 additions & 10 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use RuntimeException;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command as Commands;
use support\Container;

Expand All @@ -14,7 +15,7 @@ public function installInternalCommands()
$this->installCommands(__DIR__ . '/Commands', 'Webman\Console\Commands');
}

public function installCommands($path, $namspace = 'app\command')
public function installCommands($path, $namespace = 'app\command')
{
$dir_iterator = new \RecursiveDirectoryIterator($path);
$iterator = new \RecursiveIteratorIterator($dir_iterator);
Expand All @@ -29,26 +30,41 @@ public function installCommands($path, $namspace = 'app\command')
// abc\def.php
$relativePath = str_replace(str_replace('/', '\\', $path . '\\'), '', str_replace('/', '\\', $file->getRealPath()));
// app\command\abc
$realNamespace = trim($namspace . '\\' . trim(dirname(str_replace('\\', DIRECTORY_SEPARATOR, $relativePath)), '.'), '\\');
$realNamespace = trim($namespace . '\\' . trim(dirname(str_replace('\\', DIRECTORY_SEPARATOR, $relativePath)), '.'), '\\');
$realNamespace = str_replace('/', '\\', $realNamespace);
// app\command\doc\def
$class_name = trim($realNamespace . '\\' . $file->getBasename('.php'), '\\');
if (!class_exists($class_name) || !is_a($class_name, Commands::class, true)) {
continue;
}
$reflection = new \ReflectionClass($class_name);
if ($reflection->isAbstract()) {
continue;
}

$this->createCommandInstance($class_name);
}
}

public function createCommandInstance($class_name)
{
$reflection = new \ReflectionClass($class_name);
if ($reflection->isAbstract()) {
return null;
}

$attributes = $reflection->getAttributes(AsCommand::class);
if (!empty($attributes)) {
$properties = current($attributes)->newInstance();
$name = $properties->name;
$description = $properties->description;
} else {
$properties = $reflection->getStaticProperties();
$name = $properties['defaultName'] ?? null;
if (!$name) {
throw new RuntimeException("Command {$class_name} has no defaultName");
}
$description = $properties['defaultDescription'] ?? '';
$command = Container::get($class_name);
$command->setName($name)->setDescription($description);
$this->add($command);
}
$command = Container::get($class_name);
$command->setName($name)->setDescription($description);
$this->add($command);
return $command;
}
}
}
7 changes: 2 additions & 5 deletions src/Commands/AppPluginCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

namespace Webman\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Webman\Console\Util;

#[AsCommand('app-plugin:create', 'Create App Plugin')]
class AppPluginCreateCommand extends Command
{
protected static $defaultName = 'app-plugin:create';
protected static $defaultDescription = 'App Plugin Create';

/**
* @return void
*/
Expand Down
9 changes: 2 additions & 7 deletions src/Commands/AppPluginInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@

namespace Webman\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Webman\Console\Util;

#[AsCommand('app-plugin:install', 'Install App Plugin')]
class AppPluginInstallCommand extends Command
{

protected static $defaultName = 'app-plugin:install';
protected static $defaultDescription = 'App Plugin Install';

/**
* @return void
*/
protected function configure()
{
$this->setName(static::$defaultName)->setDescription(static::$defaultDescription);
$this->addArgument('name', InputArgument::REQUIRED, 'App plugin name');
}

Expand Down
7 changes: 2 additions & 5 deletions src/Commands/AppPluginUninstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

namespace Webman\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Webman\Console\Util;

#[AsCommand('app-plugin:uninstall', 'App Plugin Uninstall')]
class AppPluginUninstallCommand extends Command
{
protected static $defaultName = 'app-plugin:uninstall';
protected static $defaultDescription = 'App Plugin Uninstall';

/**
* @return void
*/
Expand Down
7 changes: 2 additions & 5 deletions src/Commands/AppPluginUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

namespace Webman\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Webman\Console\Util;

#[AsCommand('app-plugin:update', 'Update App Plugin')]
class AppPluginUpdateCommand extends Command
{
protected static $defaultName = 'app-plugin:update';
protected static $defaultDescription = 'App Plugin Update';

/**
* @return void
*/
Expand Down
8 changes: 2 additions & 6 deletions src/Commands/AppPluginZipCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@

namespace Webman\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Webman\Console\Util;
use ZipArchive;
use Exception;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;

#[AsCommand('app-plugin:zip', 'App Plugin Zip')]
class AppPluginZipCommand extends Command
{

protected static $defaultName = 'app-plugin:zip';
protected static $defaultDescription = 'App Plugin Zip';

/**
* @return void
*/
Expand Down
9 changes: 2 additions & 7 deletions src/Commands/BuildBinCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

namespace Webman\Console\Commands;

use Phar;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use ZipArchive;


#[AsCommand('build:bin', 'build bin')]
class BuildBinCommand extends BuildPharCommand
{
protected static $defaultName = 'build:bin';
protected static $defaultDescription = 'build bin';

/**
* @return void
*/
Expand Down
18 changes: 3 additions & 15 deletions src/Commands/BuildPharCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use Phar;
use RuntimeException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

//暂时保留 phar:pack 命令,下一个版本再取消
#[AsCommand('build:phar', 'Can be easily packaged a project into phar files. Easy to distribute and use.', ['phar:pack'])]
class BuildPharCommand extends Command
{
protected static $defaultName = 'build:phar';
protected static $defaultDescription = 'Can be easily packaged a project into phar files. Easy to distribute and use.';

protected $buildDir = '';

public function __construct(?string $name = null)
Expand All @@ -21,18 +21,6 @@ public function __construct(?string $name = null)
$this->buildDir = config('plugin.webman.console.app.build_dir', base_path() . '/build');
}

/**
* @return void
* @deprecated 暂时保留 phar:pack 命令,下一个版本再取消
*/
protected function configure()
{
$this->setAliases([
'phar:pack',
]);
parent::configure();
}

/**
* @param InputInterface $input
* @param OutputInterface $output
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/ConnectionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

namespace Webman\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Webman\Console\Application;

#[AsCommand('connections', 'Get worker connections.')]
class ConnectionsCommand extends Command
{
protected static $defaultName = 'connections';
protected static $defaultDescription = 'Get worker connections.';

/**
* @param InputInterface $input
* @param OutputInterface $output
Expand Down
14 changes: 2 additions & 12 deletions src/Commands/FixDisbaleFunctionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@

namespace Webman\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


#[AsCommand('fix-disable-functions', 'Fix disbale_functions in php.ini')]
class FixDisbaleFunctionsCommand extends Command
{
protected static $defaultName = 'fix-disable-functions';
protected static $defaultDescription = 'Fix disbale_functions in php.ini';

/**
* @return void
*/
protected function configure()
{

}

/**
* @param InputInterface $input
* @param OutputInterface $output
Expand Down
14 changes: 2 additions & 12 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@

namespace Webman\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


#[AsCommand('install', 'Execute webman installation script')]
class InstallCommand extends Command
{
protected static $defaultName = 'install';
protected static $defaultDescription = 'Execute webman installation script';

/**
* @return void
*/
protected function configure()
{

}

/**
* @param InputInterface $input
* @param OutputInterface $output
Expand Down
6 changes: 2 additions & 4 deletions src/Commands/MakeBootstrapCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

namespace Webman\Console\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Webman\Console\Util;


#[AsCommand('make:bootstrap', 'Make a bootstrap.')]
class MakeBootstrapCommand extends Command
{
protected static $defaultName = 'make:bootstrap';
protected static $defaultDescription = 'Make bootstrap';

/**
* @return void
*/
Expand Down
Loading