update class-alias update command

This commit is contained in:
crazywhalecc 2023-02-18 14:38:48 +08:00
parent de88c26427
commit 65c609754a
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680

View File

@ -45,11 +45,29 @@ class TextGenerateCommand extends Command
$full_maxlen = max($full_maxlen, strlen('`' . $full_class . '`'));
$short_maxlen = max($short_maxlen, strlen('`' . $short_class . '`'));
}
$this->write('| ' . str_pad('全类名', $full_maxlen) . ' | ' . str_pad('别名', $short_maxlen) . ' |');
$this->write('| ' . str_pad('', $full_maxlen, '-') . ' | ' . str_pad('', $short_maxlen, '-') . ' |');
foreach ($line as $v) {
$this->write('| ' . str_pad('`' . $v[0] . '`', $full_maxlen) . ' | ' . str_pad('`' . $v[1] . '`', $short_maxlen) . ' |');
}
$obj = <<<'LINE'
# 类全局别名
在框架 1.x 2.x 老版本中,我们发现许多开发者在使用框架时,往往不会使用 PhpStorm 这类大型 IDE而即使使用 VSCode 这类编辑器的时候也不一定会安装补全插件,
这样在编写机器人模块或插件时会因寻找每个对象的完整命名空间而烦恼。
3.0 版本起,框架对常用的注解事件和对象均使用了类别名功能,方便非 IDE 开发者编写插件。
## 别名使用
框架对别名的定义比较简单,由于内部暂时没有不同命名空间下重复类名的情况,所以我们目前只对需要别名类名的命名空间移除,例如:
`\ZM\Annotation\OneBot\BotCommand` 注解事件类,在经过全局别名后,你也可以使用 `\BotCommand` 作为注解事件,效果相同。
## 别名列表
LINE;
file_put_contents(
SOURCE_ROOT_DIR . '/docs/components/common/class-alias.md',
$obj . "\n" . '| ' . str_pad('全类名', $full_maxlen) . ' | ' . str_pad('别名', $short_maxlen) . ' |' .
"\n" . '| ' . str_pad('', $full_maxlen, '-') . ' | ' . str_pad('', $short_maxlen, '-') . ' |' .
"\n" . implode("\n", array_map(fn ($v) => '| ' . str_pad('`' . $v[0] . '`', $full_maxlen) . ' | ' . str_pad('`' . $v[1] . '`', $short_maxlen) . ' |', $line)) . "\n"
);
$this->write('成功');
return static::SUCCESS;
}