This commit is contained in:
crazywhalecc
2024-10-02 20:31:16 +08:00
committed by Jerry Ma
parent 2d9f879994
commit ef1a9646e4
72 changed files with 107 additions and 234 deletions

View File

@@ -66,6 +66,8 @@ return (new PhpCsFixer\Config())
'multiline_comment_opening_closing' => true, 'multiline_comment_opening_closing' => true,
'phpdoc_summary' => false, 'phpdoc_summary' => false,
'php_unit_test_class_requires_covers' => false, 'php_unit_test_class_requires_covers' => false,
'fully_qualified_strict_types' => false,
'new_with_parentheses' => false,
]) ])
->setFinder( ->setFinder(
PhpCsFixer\Finder::create() PhpCsFixer\Finder::create()

View File

@@ -65,7 +65,7 @@ define('WORKING_DIR', getcwd());
define('SOURCE_ROOT_DIR', Phar::running() !== '' ? Phar::running() : WORKING_DIR); define('SOURCE_ROOT_DIR', Phar::running() !== '' ? Phar::running() : WORKING_DIR);
if (DIRECTORY_SEPARATOR === '\\') { if (DIRECTORY_SEPARATOR === '\\') {
define('TMP_DIR', 'C:\\Windows\\Temp'); define('TMP_DIR', 'C:\Windows\Temp');
} elseif (!empty(getenv('TMPDIR'))) { } elseif (!empty(getenv('TMPDIR'))) {
define('TMP_DIR', getenv('TMPDIR')); define('TMP_DIR', getenv('TMPDIR'));
} elseif (is_writable('/tmp')) { } elseif (is_writable('/tmp')) {

View File

@@ -13,7 +13,6 @@ use OneBot\Driver\Workerman\WebSocketClient;
use OneBot\V12\Object\MessageSegment; use OneBot\V12\Object\MessageSegment;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Psr\SimpleCache\CacheInterface;
use ZM\Config\Environment; use ZM\Config\Environment;
use ZM\Config\ZMConfig; use ZM\Config\ZMConfig;
use ZM\Container\ContainerHolder; use ZM\Container\ContainerHolder;
@@ -148,7 +147,7 @@ function is_assoc_array(array $array): bool
*/ */
function match_pattern(string $pattern, string $subject): bool function match_pattern(string $pattern, string $subject): bool
{ {
$pattern = str_replace(['\*', '\\\\.*'], ['.*', '\*'], preg_quote($pattern, '/')); $pattern = str_replace(['\*', '\\\.*'], ['.*', '\*'], preg_quote($pattern, '/'));
$pattern = '/^' . $pattern . '$/i'; $pattern = '/^' . $pattern . '$/i';
return preg_match($pattern, $subject) === 1; return preg_match($pattern, $subject) === 1;
} }
@@ -302,7 +301,7 @@ function redis(string $name = 'default'): RedisWrapper
* @param null|mixed $default 默认值 * @param null|mixed $default 默认值
* @return mixed|void|ZMConfig * @return mixed|void|ZMConfig
*/ */
function config(array|string $key = null, mixed $default = null) function config(null|array|string $key = null, mixed $default = null)
{ {
$config = ZMConfig::getInstance(); $config = ZMConfig::getInstance();
if (is_null($key)) { if (is_null($key)) {
@@ -328,8 +327,7 @@ function bot_connect(int $flag, int $fd)
/** /**
* 获取一个 KV 库实例 * 获取一个 KV 库实例
* *
* @param string $name KV 库名称 * @param string $name KV 库名称
* @return CacheInterface
*/ */
function kv(string $name = ''): Psr\SimpleCache\CacheInterface function kv(string $name = ''): Psr\SimpleCache\CacheInterface
{ {

View File

@@ -49,6 +49,6 @@ function _zm_setup_loader()
// 在*nix等支持多进程环境的情况可直接运行此文件那么就执行 // 在*nix等支持多进程环境的情况可直接运行此文件那么就执行
if (debug_backtrace() === []) { if (debug_backtrace() === []) {
require((!is_dir(__DIR__ . '/../../vendor')) ? getcwd() : (__DIR__ . '/../..')) . '/vendor/autoload.php'; require ((!is_dir(__DIR__ . '/../../vendor')) ? getcwd() : (__DIR__ . '/../..')) . '/vendor/autoload.php';
echo _zm_setup_loader(); echo _zm_setup_loader();
} }

View File

@@ -7,7 +7,7 @@ namespace ZM\Annotation;
abstract class AnnotationBase implements \IteratorAggregate, \Stringable abstract class AnnotationBase implements \IteratorAggregate, \Stringable
{ {
/** @var array|\Closure|string 方法名或闭包 */ /** @var array|\Closure|string 方法名或闭包 */
public \Closure|string|array $method = ''; public array|\Closure|string $method = '';
public $class = ''; public $class = '';
@@ -40,7 +40,7 @@ abstract class AnnotationBase implements \IteratorAggregate, \Stringable
/** /**
* InstantPlugin 下调用,设置回调或匿名函数 * InstantPlugin 下调用,设置回调或匿名函数
*/ */
public function on(\Closure|callable|string $method): AnnotationBase public function on(callable|\Closure|string $method): AnnotationBase
{ {
$this->method = $method; $this->method = $method;
return $this; return $this;

View File

@@ -21,7 +21,7 @@ class AnnotationHandler
public const STATUS_RULE_FAILED = 4; // 判断事件执行的规则函数判定为false所以不执行此方法 public const STATUS_RULE_FAILED = 4; // 判断事件执行的规则函数判定为false所以不执行此方法
private string|AnnotationBase $annotation_class; private AnnotationBase|string $annotation_class;
/** @var callable */ /** @var callable */
private $rule_callback; private $rule_callback;

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation; namespace ZM\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target; use Doctrine\Common\Annotations\Annotation\Target;
@@ -15,6 +14,4 @@ use Doctrine\Common\Annotations\Annotation\Target;
* @Target("ALL") * @Target("ALL")
*/ */
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_ALL)] #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_ALL)]
class Closed extends AnnotationBase class Closed extends AnnotationBase {}
{
}

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation\Framework; namespace ZM\Annotation\Framework;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target; use Doctrine\Common\Annotations\Annotation\Target;
@@ -32,8 +31,7 @@ class BindEvent extends AnnotationBase implements Level
*/ */
public string $event_class, public string $event_class,
public int $level = 800 public int $level = 800
) { ) {}
}
public function getLevel(): int public function getLevel(): int
{ {

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation\Framework; namespace ZM\Annotation\Framework;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target; use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase; use ZM\Annotation\AnnotationBase;
@@ -20,9 +19,7 @@ use ZM\Annotation\Interfaces\Level;
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Init extends AnnotationBase implements Level class Init extends AnnotationBase implements Level
{ {
public function __construct(public int $worker = 0, public int $level = 20) public function __construct(public int $worker = 0, public int $level = 20) {}
{
}
public function getLevel() public function getLevel()
{ {

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation\Framework; namespace ZM\Annotation\Framework;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target; use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase; use ZM\Annotation\AnnotationBase;
@@ -17,6 +16,4 @@ use ZM\Annotation\AnnotationBase;
* @since 3.0.0 * @since 3.0.0
*/ */
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Setup extends AnnotationBase class Setup extends AnnotationBase {}
{
}

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation\Http; namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target; use Doctrine\Common\Annotations\Annotation\Target;
@@ -25,6 +24,5 @@ class Controller extends AnnotationBase implements ErgodicAnnotation
* @Required() * @Required()
*/ */
public string $prefix public string $prefix
) { ) {}
}
} }

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation\Http; namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target; use Doctrine\Common\Annotations\Annotation\Target;
@@ -30,8 +29,7 @@ class Route extends AnnotationBase
* Routing path params binding. eg. {"id"="\d+"} * Routing path params binding. eg. {"id"="\d+"}
*/ */
public $params = [] public $params = []
) { ) {}
}
public static function make($route, $name = '', $request_method = ['GET', 'POST'], $params = []): static public static function make($route, $name = '', $request_method = ['GET', 'POST'], $params = []): static
{ {

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace ZM\Annotation\Interfaces; namespace ZM\Annotation\Interfaces;
interface CustomAnnotation interface CustomAnnotation {}
{
}

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace ZM\Annotation\Interfaces; namespace ZM\Annotation\Interfaces;
interface ErgodicAnnotation interface ErgodicAnnotation {}
{
}

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation\Middleware; namespace ZM\Annotation\Middleware;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target; use Doctrine\Common\Annotations\Annotation\Target;
@@ -22,6 +21,7 @@ class Middleware extends AnnotationBase implements ErgodicAnnotation
{ {
/** /**
* @param string[] $args * @param string[] $args
* @param mixed $name
*/ */
public function __construct( public function __construct(
/** /**
@@ -29,6 +29,5 @@ class Middleware extends AnnotationBase implements ErgodicAnnotation
*/ */
public $name, public $name,
public array $args = [] public array $args = []
) { ) {}
}
} }

View File

@@ -17,9 +17,7 @@ use ZM\Annotation\Interfaces\Level;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class BotAction extends AnnotationBase implements Level class BotAction extends AnnotationBase implements Level
{ {
public function __construct(public string $action = '', public bool $need_response = false, public int $level = 20) public function __construct(public string $action = '', public bool $need_response = false, public int $level = 20) {}
{
}
public static function make(callable $callback, string $action, bool $need_response = false, int $level = 20): BotAction public static function make(callable $callback, string $action, bool $need_response = false, int $level = 20): BotAction
{ {

View File

@@ -20,9 +20,7 @@ use ZM\Annotation\Interfaces\Level;
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class BotActionResponse extends AnnotationBase implements Level class BotActionResponse extends AnnotationBase implements Level
{ {
public function __construct(public ?string $status = null, public ?int $retcode = null, public int $level = 20) public function __construct(public ?string $status = null, public ?int $retcode = null, public int $level = 20) {}
{
}
public function getLevel() public function getLevel()
{ {

View File

@@ -39,8 +39,7 @@ class BotCommand extends AnnotationBase implements Level
public string $detail_type = '', public string $detail_type = '',
public string $prefix = '', public string $prefix = '',
public int $level = 20 public int $level = 20
) { ) {}
}
public static function make( public static function make(
string $name = '', string $name = '',

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation\OneBot; namespace ZM\Annotation\OneBot;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target; use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase; use ZM\Annotation\AnnotationBase;
@@ -20,9 +19,7 @@ use ZM\Annotation\Interfaces\Level;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class BotEvent extends AnnotationBase implements Level class BotEvent extends AnnotationBase implements Level
{ {
public function __construct(public ?string $type = null, public ?string $detail_type = null, public ?string $sub_type = null, public int $level = 20) public function __construct(public ?string $type = null, public ?string $detail_type = null, public ?string $sub_type = null, public int $level = 20) {}
{
}
public static function make( public static function make(
?string $type = null, ?string $type = null,

View File

@@ -41,7 +41,7 @@ class CommandArgument extends AnnotationBase implements ErgodicAnnotation
string $type = 'string', string $type = 'string',
public bool $required = false, public bool $required = false,
public string $prompt = '', public string $prompt = '',
public string|\Closure|array|int|float|null $default = '', public null|array|\Closure|float|int|string $default = '',
public int $timeout = 60, public int $timeout = 60,
public int $error_prompt_policy = 1 public int $error_prompt_policy = 1
) { ) {

View File

@@ -22,8 +22,7 @@ class CommandHelp extends AnnotationBase
public string $description, public string $description,
public string $usage, public string $usage,
public string $example, public string $example,
) { ) {}
}
public static function make( public static function make(
string $description, string $description,

View File

@@ -83,7 +83,7 @@ class BuildCommand extends Command
$separator = '\\' . DIRECTORY_SEPARATOR; $separator = '\\' . DIRECTORY_SEPARATOR;
// 只打包 bin / config / resources / src / vendor 目录以及 composer.json / composer.lock / entry.php // 只打包 bin / config / resources / src / vendor 目录以及 composer.json / composer.lock / entry.php
$files = array_filter($files, function ($file) use ($separator) { $files = array_filter($files, function ($file) use ($separator) {
return preg_match('/^(bin|config|resources|src|vendor)' . $separator . '|^(composer\\.json|README\\.md)$/', $file); return preg_match('/^(bin|config|resources|src|vendor)' . $separator . '|^(composer\.json|README\.md)$/', $file);
}); });
sort($files); sort($files);

View File

@@ -26,7 +26,6 @@ abstract class Command extends \Symfony\Component\Console\Command\Command implem
protected OutputInterface $output; protected OutputInterface $output;
/** /**
* {@inheritdoc}
* @internal 不建议覆写此方法,建议使用 {@see handle()} 方法 * @internal 不建议覆写此方法,建议使用 {@see handle()} 方法
*/ */
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int

View File

@@ -18,9 +18,6 @@ class TextGenerateCommand extends Command
$this->setDescription('生成一些框架本身的文本(内部' . PHP_EOL . '当前包含class-alias-mdupdate-log-md'); $this->setDescription('生成一些框架本身的文本(内部' . PHP_EOL . '当前包含class-alias-mdupdate-log-md');
} }
/**
* {@inheritDoc}
*/
protected function handle(): int protected function handle(): int
{ {
return match ($this->input->getArgument('name')) { return match ($this->input->getArgument('name')) {

View File

@@ -20,9 +20,6 @@ class PluginInstallCommand extends PluginCommand
$this->addOption('github-token', null, InputOption::VALUE_REQUIRED, '提供的 GitHub Token'); $this->addOption('github-token', null, InputOption::VALUE_REQUIRED, '提供的 GitHub Token');
} }
/**
* {@inheritDoc}
*/
protected function handle(): int protected function handle(): int
{ {
$addr = $this->input->getArgument('address'); $addr = $this->input->getArgument('address');

View File

@@ -27,7 +27,6 @@ class PluginMakeCommand extends PluginCommand
} }
/** /**
* {@inheritDoc}
* @throws FileSystemException * @throws FileSystemException
*/ */
protected function handle(): int protected function handle(): int

View File

@@ -19,9 +19,6 @@ class PluginPackCommand extends PluginCommand
$this->addOption('build-dir', 'D', InputOption::VALUE_REQUIRED, '指定输出文件位置', WORKING_DIR . '/build'); $this->addOption('build-dir', 'D', InputOption::VALUE_REQUIRED, '指定输出文件位置', WORKING_DIR . '/build');
} }
/**
* {@inheritDoc}
*/
protected function handle(): int protected function handle(): int
{ {
try { try {

View File

@@ -17,9 +17,6 @@ class PluginRemoveCommand extends PluginCommand
$this->addArgument('name', InputArgument::REQUIRED, '插件名称'); $this->addArgument('name', InputArgument::REQUIRED, '插件名称');
} }
/**
* {@inheritDoc}
*/
protected function handle(): int protected function handle(): int
{ {
$plugin_name = $this->input->getArgument('name'); $plugin_name = $this->input->getArgument('name');

View File

@@ -29,9 +29,6 @@ class Environment implements EnvironmentInterface
$this->values = $values + $_ENV + $_SERVER; $this->values = $values + $_ENV + $_SERVER;
} }
/**
* {@inheritdoc}
*/
public function set(string $name, mixed $value): self public function set(string $name, mixed $value): self
{ {
if (array_key_exists($name, $this->values) && !$this->overwrite) { if (array_key_exists($name, $this->values) && !$this->overwrite) {
@@ -45,9 +42,6 @@ class Environment implements EnvironmentInterface
return $this; return $this;
} }
/**
* {@inheritdoc}
*/
public function get(string $name, mixed $default = null): mixed public function get(string $name, mixed $default = null): mixed
{ {
if (isset($this->values[$name])) { if (isset($this->values[$name])) {
@@ -57,9 +51,6 @@ class Environment implements EnvironmentInterface
return $default; return $default;
} }
/**
* {@inheritdoc}
*/
public function getAll(): array public function getAll(): array
{ {
$result = []; $result = [];

View File

@@ -14,7 +14,7 @@ class RuntimePreferences
protected string $config_dir = SOURCE_ROOT_DIR . '/config'; protected string $config_dir = SOURCE_ROOT_DIR . '/config';
public function environment(...$environments): string|bool public function environment(...$environments): bool|string
{ {
if (empty($environments)) { if (empty($environments)) {
return $this->environment; return $this->environment;

View File

@@ -64,7 +64,7 @@ class ZMConfig
* *
* @throws ConfigException 配置文件加载出错 * @throws ConfigException 配置文件加载出错
*/ */
public function __construct(array $init_config = null) public function __construct(?array $init_config = null)
{ {
// 合并初始化配置,构造传入优先 // 合并初始化配置,构造传入优先
$conf = array_merge_recursive($this->loadInitConfig(), $init_config ?? []); $conf = array_merge_recursive($this->loadInitConfig(), $init_config ?? []);
@@ -332,7 +332,7 @@ class ZMConfig
// 读取并解析配置 // 读取并解析配置
$content = file_get_contents($path); $content = file_get_contents($path);
// TODO: 使用 Loader 替代 // TODO: 使用 Loader 替代
// $config = $this->loader->load($path); // $config = $this->loader->load($path);
$config = []; $config = [];
switch ($ext) { switch ($ext) {
case 'php': case 'php':

View File

@@ -46,9 +46,6 @@ final class ConsoleApplication extends Application
self::$obj = $this; self::$obj = $this;
} }
/**
* {@inheritdoc}
*/
public function doRun(InputInterface $input, OutputInterface $output): int public function doRun(InputInterface $input, OutputInterface $output): int
{ {
try { try {
@@ -73,9 +70,6 @@ final class ConsoleApplication extends Application
]); ]);
} }
/**
* {@inheritdoc}
*/
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int
{ {
// 初始化内核 // 初始化内核
@@ -99,7 +93,7 @@ final class ConsoleApplication extends Application
// 先加载框架内置命令 // 先加载框架内置命令
$command_classes = array_merge( $command_classes = array_merge(
$command_classes, $command_classes,
FileSystem::getClassesPsr4(FRAMEWORK_ROOT_DIR . '/src/ZM/Command', 'ZM\\Command') FileSystem::getClassesPsr4(FRAMEWORK_ROOT_DIR . '/src/ZM/Command', 'ZM\Command')
); );
// 再加载用户自定义命令(如存在) // 再加载用户自定义命令(如存在)
if (is_dir(SOURCE_ROOT_DIR . '/src/Command')) { if (is_dir(SOURCE_ROOT_DIR . '/src/Command')) {

View File

@@ -28,9 +28,7 @@ class ContainerBindingListener
} }
} }
public static function callback(): void public static function callback(): void {}
{
}
public static function cleanCallback(): void public static function cleanCallback(): void
{ {

View File

@@ -15,9 +15,7 @@ class BotConnectContext
protected ?array $self = null; protected ?array $self = null;
public function __construct(private int $flag, private int $fd) public function __construct(private int $flag, private int $fd) {}
{
}
public function getFd(): int public function getFd(): int
{ {

View File

@@ -54,7 +54,7 @@ class BotContext implements ContextInterface
* @noinspection PhpDocMissingThrowsInspection * @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection * @noinspection PhpUnhandledExceptionInspection
*/ */
public function reply(\Stringable|MessageSegment|array|string $message, int $reply_mode = ZM_REPLY_NONE): ActionResponse|bool public function reply(array|MessageSegment|string|\Stringable $message, int $reply_mode = ZM_REPLY_NONE): ActionResponse|bool
{ {
if (container()->has('bot.event')) { if (container()->has('bot.event')) {
// 这里直接使用当前上下文的事件里面的参数,不再重新挨个获取怎么发消息的参数 // 这里直接使用当前上下文的事件里面的参数,不再重新挨个获取怎么发消息的参数
@@ -87,7 +87,7 @@ class BotContext implements ContextInterface
* @noinspection PhpDocMissingThrowsInspection * @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection * @noinspection PhpUnhandledExceptionInspection
*/ */
public function prompt(string|\Stringable|MessageSegment|array $prompt = '', int $timeout = 600, string|\Stringable|MessageSegment|array $timeout_prompt = '', int $option = ZM_PROMPT_NONE): null|OneBotEvent|array|string public function prompt(array|MessageSegment|string|\Stringable $prompt = '', int $timeout = 600, array|MessageSegment|string|\Stringable $timeout_prompt = '', int $option = ZM_PROMPT_NONE): null|array|OneBotEvent|string
{ {
if (!container()->has('bot.event')) { if (!container()->has('bot.event')) {
throw new OneBot12Exception('bot()->prompt() can only be used in message event'); throw new OneBot12Exception('bot()->prompt() can only be used in message event');
@@ -135,7 +135,7 @@ class BotContext implements ContextInterface
* 如果是多级群组,则等待最小级下当前消息人的消息 * 如果是多级群组,则等待最小级下当前消息人的消息
* @noinspection PhpUnhandledExceptionInspection * @noinspection PhpUnhandledExceptionInspection
*/ */
public function promptString(string|\Stringable|MessageSegment|array $prompt = '', int $timeout = 600, string|\Stringable|MessageSegment|array $timeout_prompt = '', int $option = ZM_PROMPT_NONE): string public function promptString(array|MessageSegment|string|\Stringable $prompt = '', int $timeout = 600, array|MessageSegment|string|\Stringable $timeout_prompt = '', int $option = ZM_PROMPT_NONE): string
{ {
return $this->prompt($prompt, $timeout, $timeout_prompt, $option | ZM_PROMPT_RETURN_STRING); return $this->prompt($prompt, $timeout, $timeout_prompt, $option | ZM_PROMPT_RETURN_STRING);
} }
@@ -194,12 +194,12 @@ class BotContext implements ContextInterface
* *
* @param int|string $name 参数名称或索引 * @param int|string $name 参数名称或索引
*/ */
public function getParam(string|int $name): mixed public function getParam(int|string $name): mixed
{ {
return $this->params[$name] ?? null; return $this->params[$name] ?? null;
} }
public function getParamString(string|int $name): ?string public function getParamString(int|string $name): ?string
{ {
return MessageUtil::getAltMessage($this->params[$name] ?? null); return MessageUtil::getAltMessage($this->params[$name] ?? null);
} }
@@ -242,7 +242,7 @@ class BotContext implements ContextInterface
* @param OneBotEvent $event 事件对象 * @param OneBotEvent $event 事件对象
* @return array 消息段 * @return array 消息段
*/ */
private function applyPromptMode(int $option, array|string|\Stringable|MessageSegment $prompt, OneBotEvent $event): array private function applyPromptMode(int $option, array|MessageSegment|string|\Stringable $prompt, OneBotEvent $event): array
{ {
// 先格式化消息 // 先格式化消息
if ($prompt instanceof MessageSegment) { if ($prompt instanceof MessageSegment) {
@@ -268,7 +268,7 @@ class BotContext implements ContextInterface
* @return null|array|OneBotEvent|string 根据不同匹配类型返回不同的东西 * @return null|array|OneBotEvent|string 根据不同匹配类型返回不同的东西
* @throws OneBot12Exception * @throws OneBot12Exception
*/ */
private function applyPromptReturn(mixed $result, int $option): null|OneBotEvent|array|string private function applyPromptReturn(mixed $result, int $option): null|array|OneBotEvent|string
{ {
// 必须是 OneBotEvent 且是消息类型 // 必须是 OneBotEvent 且是消息类型
if (!$result instanceof OneBotEvent || $result->type !== 'message') { if (!$result instanceof OneBotEvent || $result->type !== 'message') {

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace ZM\Context; namespace ZM\Context;
interface ContextInterface interface ContextInterface {}
{
}

View File

@@ -35,7 +35,7 @@ trait BotActionTrait
* @param array|MessageSegment|string|\Stringable $message 消息内容,可以是消息段、字符串 * @param array|MessageSegment|string|\Stringable $message 消息内容,可以是消息段、字符串
* @throws \Throwable * @throws \Throwable
*/ */
public function sendMessage(\Stringable|array|MessageSegment|string $message, string $detail_type, array $params = []): ActionResponse|bool public function sendMessage(array|MessageSegment|string|\Stringable $message, string $detail_type, array $params = []): ActionResponse|bool
{ {
$message = MessageUtil::convertToArr($message); $message = MessageUtil::convertToArr($message);
$params['message'] = $message; $params['message'] = $message;
@@ -48,7 +48,7 @@ trait BotActionTrait
* *
* @throws \Throwable * @throws \Throwable
*/ */
public function sendAction(string $action, array $params = [], ?array $self = null): bool|ActionResponse public function sendAction(string $action, array $params = [], ?array $self = null): ActionResponse|bool
{ {
if ($self === null && $this->self !== null) { if ($self === null && $this->self !== null) {
$self = $this->self; $self = $this->self;

View File

@@ -110,8 +110,7 @@ class WorkerEventListener
} }
// Windows 系统的 CtrlC 由于和 Select 有一定的冲突,如果没事件解析的话 CtrlC 会阻塞,所以必须添加一个空的计时器 // Windows 系统的 CtrlC 由于和 Select 有一定的冲突,如果没事件解析的话 CtrlC 会阻塞,所以必须添加一个空的计时器
if (PHP_OS_FAMILY === 'Windows') { if (PHP_OS_FAMILY === 'Windows') {
Framework::getInstance()->getDriver()->getEventLoop()->addTimer(1000, function () { Framework::getInstance()->getDriver()->getEventLoop()->addTimer(1000, function () {}, 0);
}, 0);
} }
// 回显 debug 日志:进程占用的内存 // 回显 debug 日志:进程占用的内存
$memory_total = memory_get_usage() / 1024 / 1024; $memory_total = memory_get_usage() / 1024 / 1024;

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace ZM\Exception; namespace ZM\Exception;
class DriverException extends ZMException class DriverException extends ZMException {}
{
}

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace ZM\Exception; namespace ZM\Exception;
class FileSystemException extends ZMException class FileSystemException extends ZMException {}
{
}

View File

@@ -7,6 +7,4 @@ namespace ZM\Exception;
/** /**
* 初始化命令(./zhamao init出现的错误 * 初始化命令(./zhamao init出现的错误
*/ */
class InitException extends ZMException class InitException extends ZMException {}
{
}

View File

@@ -6,7 +6,7 @@ namespace ZM\Exception;
class InterruptException extends ZMException class InterruptException extends ZMException
{ {
public function __construct(public $return_var = null, $message = '', $code = 0, \Throwable $previous = null) public function __construct(public $return_var = null, $message = '', $code = 0, ?\Throwable $previous = null)
{ {
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
} }

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace ZM\Exception; namespace ZM\Exception;
class InvalidArgumentException extends ZMException class InvalidArgumentException extends ZMException {}
{
}

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace ZM\Exception; namespace ZM\Exception;
class OneBot12Exception extends PluginException class OneBot12Exception extends PluginException {}
{
}

View File

@@ -7,6 +7,4 @@ namespace ZM\Exception;
/** /**
* 插件加载器出现的错误 * 插件加载器出现的错误
*/ */
class PluginException extends ZMException class PluginException extends ZMException {}
{
}

View File

@@ -10,8 +10,7 @@ class Solution
private string $title, private string $title,
private string $description, private string $description,
private array $links, private array $links,
) { ) {}
}
public function getSolutionTitle(): string public function getSolutionTitle(): string
{ {

View File

@@ -14,11 +14,11 @@ class WaitTimeoutException extends ZMException
public function __construct( public function __construct(
public mixed $module, public mixed $module,
string|\MessageSegment|array|\Stringable $timeout_prompt = '', array|\MessageSegment|string|\Stringable $timeout_prompt = '',
private ?ActionResponse $prompt_response = null, private ?ActionResponse $prompt_response = null,
private ?OneBotEvent $user_event = null, private ?OneBotEvent $user_event = null,
private int $prompt_option = ZM_PROMPT_NONE, private int $prompt_option = ZM_PROMPT_NONE,
\Throwable $previous = null ?\Throwable $previous = null
) { ) {
parent::__construct('wait timeout!', 0, $previous); parent::__construct('wait timeout!', 0, $previous);
if ($timeout_prompt === '') { if ($timeout_prompt === '') {

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace ZM\Exception; namespace ZM\Exception;
abstract class ZMException extends \Exception abstract class ZMException extends \Exception {}
{
}

View File

@@ -9,7 +9,7 @@ use JetBrains\PhpStorm\Deprecated;
#[Deprecated(reason: '建议使用具体的异常类')] #[Deprecated(reason: '建议使用具体的异常类')]
class ZMKnownException extends ZMException class ZMKnownException extends ZMException
{ {
public function __construct($err_code, $message = '', $code = 0, \Throwable $previous = null) public function __construct($err_code, $message = '', $code = 0, ?\Throwable $previous = null)
{ {
parent::__construct(zm_internal_errcode($err_code) . $message, $code, $previous); parent::__construct(zm_internal_errcode($err_code) . $message, $code, $previous);
if ($err_code === 'E99999') { if ($err_code === 'E99999') {

View File

@@ -61,7 +61,7 @@ class Framework
protected array $argv; protected array $argv;
/** @var null|Driver|SwooleDriver|WorkermanDriver OneBot驱动 */ /** @var null|Driver|SwooleDriver|WorkermanDriver OneBot驱动 */
protected SwooleDriver|Driver|WorkermanDriver|null $driver = null; protected null|Driver|SwooleDriver|WorkermanDriver $driver = null;
/** @var array<array<string, string>> 启动注解列表 */ /** @var array<array<string, string>> 启动注解列表 */
protected array $setup_annotations = []; protected array $setup_annotations = [];

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace ZM\Middleware; namespace ZM\Middleware;
interface MiddlewareInterface interface MiddlewareInterface {}
{
}

View File

@@ -41,7 +41,7 @@ class WebSocketFilter implements MiddlewareInterface, PipelineInterface
return true; return true;
} }
private function filterMessageAndClose(WebSocketMessageEvent|WebSocketCloseEvent $event): bool private function filterMessageAndClose(WebSocketCloseEvent|WebSocketMessageEvent $event): bool
{ {
// 过滤存在 flag 设置的情况 // 过滤存在 flag 设置的情况
if (($this->args['flag'] ?? null) !== null && $this->args['flag'] !== $event->getSocketFlag()) { if (($this->args['flag'] ?? null) !== null && $this->args['flag'] !== $event->getSocketFlag()) {

View File

@@ -10,9 +10,7 @@ use ZM\Annotation\OneBot\CommandHelp;
class StaticManualFactory class StaticManualFactory
{ {
public function __construct() public function __construct() {}
{
}
public function __invoke(BotCommand $command, array $template, array $adjacent_annotations): string public function __invoke(BotCommand $command, array $template, array $adjacent_annotations): string
{ {

View File

@@ -69,7 +69,7 @@ class BotMap
* @param int $fd 绑定的反向 ws 连接的客户端对应 fd * @param int $fd 绑定的反向 ws 连接的客户端对应 fd
* @param int $flag fd 所在 server 监听端口 * @param int $flag fd 所在 server 监听端口
*/ */
public static function registerBotWithFd(string|int $bot_id, string $platform, bool $status, int $fd, int $flag): bool public static function registerBotWithFd(int|string $bot_id, string $platform, bool $status, int $fd, int $flag): bool
{ {
logger()->debug('正在注册机器人:' . "{$platform}:{$bot_id}, fd:{$fd}, flag:{$flag}"); logger()->debug('正在注册机器人:' . "{$platform}:{$bot_id}, fd:{$fd}, flag:{$flag}");
self::$bot_fds[$platform][strval($bot_id)] = [$flag, $fd]; self::$bot_fds[$platform][strval($bot_id)] = [$flag, $fd];
@@ -87,12 +87,12 @@ class BotMap
return self::$bot_fds; return self::$bot_fds;
} }
public static function getBotFd(string|int $bot_id, string $platform): ?array public static function getBotFd(int|string $bot_id, string $platform): ?array
{ {
return self::$bot_fds[$platform][$bot_id] ?? null; return self::$bot_fds[$platform][$bot_id] ?? null;
} }
public static function unregisterBot(string|int $bot_id, string $platform): void public static function unregisterBot(int|string $bot_id, string $platform): void
{ {
logger()->debug('取消注册 bot: ' . $bot_id); logger()->debug('取消注册 bot: ' . $bot_id);
unset(self::$bot_fds[$platform][$bot_id], self::$bot_status[$platform][$bot_id], self::$bot_ctx_cache[$platform][$bot_id]); unset(self::$bot_fds[$platform][$bot_id], self::$bot_status[$platform][$bot_id], self::$bot_ctx_cache[$platform][$bot_id]);
@@ -117,7 +117,7 @@ class BotMap
} }
} }
public static function getBotContext(string|int $bot_id = '', string $platform = ''): BotContext public static function getBotContext(int|string $bot_id = '', string $platform = ''): BotContext
{ {
if (isset(self::$bot_ctx_cache[$platform][$bot_id])) { if (isset(self::$bot_ctx_cache[$platform][$bot_id])) {
return self::$bot_ctx_cache[$platform][$bot_id]; return self::$bot_ctx_cache[$platform][$bot_id];
@@ -152,7 +152,7 @@ class BotMap
return self::$bot_ctx_cache[$platform][$bot_id] = new (self::$custom_contexts[$platform][$bot_id] ?? BotContext::class)($bot_id, $platform); return self::$bot_ctx_cache[$platform][$bot_id] = new (self::$custom_contexts[$platform][$bot_id] ?? BotContext::class)($bot_id, $platform);
} }
public static function setCustomContext(string|int $bot_id, string $platform, string $context_class = BotContext::class): void public static function setCustomContext(int|string $bot_id, string $platform, string $context_class = BotContext::class): void
{ {
self::$custom_contexts[$platform][$bot_id] = $context_class; self::$custom_contexts[$platform][$bot_id] = $context_class;
} }

View File

@@ -31,7 +31,7 @@ class ProcessStateManager
* @throws ZMKnownException * @throws ZMKnownException
* @internal * @internal
*/ */
public static function removeProcessState(int $type, int|string $id_or_name = null): void public static function removeProcessState(int $type, null|int|string $id_or_name = null): void
{ {
switch ($type) { switch ($type) {
case ZM_PROCESS_MASTER: case ZM_PROCESS_MASTER:

View File

@@ -13,9 +13,7 @@ use Doctrine\DBAL\ParameterType;
class DBStatement implements \IteratorAggregate, Statement class DBStatement implements \IteratorAggregate, Statement
{ {
public function __construct(private \PDOStatement $statement) public function __construct(private \PDOStatement $statement) {}
{
}
public function closeCursor() public function closeCursor()
{ {

View File

@@ -14,9 +14,7 @@ use Doctrine\DBAL\ForwardCompatibility\Result;
class DBStatementWrapper class DBStatementWrapper
{ {
public function __construct(public ?Result $stmt) public function __construct(public ?Result $stmt) {}
{
}
/** /**
* 获取结果的迭代器 * 获取结果的迭代器
@@ -41,7 +39,7 @@ class DBStatementWrapper
/** /**
* wrapper method * wrapper method
* @return array|false|mixed * @return array|false|mixed
*@throws DBException * @throws DBException
*/ */
public function fetchNumeric() public function fetchNumeric()
{ {
@@ -55,7 +53,7 @@ class DBStatementWrapper
/** /**
* wrapper method * wrapper method
* @return array|false|mixed * @return array|false|mixed
*@throws DBException * @throws DBException
*/ */
public function fetchAssociative() public function fetchAssociative()
{ {
@@ -69,7 +67,7 @@ class DBStatementWrapper
/** /**
* wrapper method * wrapper method
* @return false|mixed * @return false|mixed
*@throws DBException * @throws DBException
*/ */
public function fetchOne() public function fetchOne()
{ {

View File

@@ -104,7 +104,7 @@ class LightCache implements KVInterface
/** /**
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool public function set(string $key, mixed $value, null|\DateInterval|int $ttl = null): bool
{ {
$this->validateKey($key); $this->validateKey($key);
self::$caches[$this->name][$key] = $value; self::$caches[$this->name][$key] = $value;
@@ -139,7 +139,7 @@ class LightCache implements KVInterface
} }
} }
public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool public function setMultiple(iterable $values, null|\DateInterval|int $ttl = null): bool
{ {
foreach ($values as $k => $v) { foreach ($values as $k => $v) {
if (!$this->set($k, $v, $ttl)) { if (!$this->set($k, $v, $ttl)) {

View File

@@ -21,9 +21,6 @@ class KVRedis implements KVInterface
return new KVRedis($name); return new KVRedis($name);
} }
/**
* {@inheritDoc}
*/
public function get(string $key, mixed $default = null): mixed public function get(string $key, mixed $default = null): mixed
{ {
/** @var ZMRedis $redis */ /** @var ZMRedis $redis */
@@ -38,10 +35,7 @@ class KVRedis implements KVInterface
return $ret; return $ret;
} }
/** public function set(string $key, mixed $value, null|\DateInterval|int $ttl = null): bool
* {@inheritDoc}
*/
public function set(string $key, mixed $value, \DateInterval|int|null $ttl = null): bool
{ {
/** @var ZMRedis $redis */ /** @var ZMRedis $redis */
$redis = RedisPool::pool($this->pool_name)->get(); $redis = RedisPool::pool($this->pool_name)->get();
@@ -50,9 +44,6 @@ class KVRedis implements KVInterface
return (bool) $ret; return (bool) $ret;
} }
/**
* {@inheritDoc}
*/
public function delete(string $key): bool public function delete(string $key): bool
{ {
/** @var ZMRedis $redis */ /** @var ZMRedis $redis */
@@ -62,9 +53,6 @@ class KVRedis implements KVInterface
return (bool) $ret; return (bool) $ret;
} }
/**
* {@inheritDoc}
*/
public function clear(): bool public function clear(): bool
{ {
/** @var ZMRedis $redis */ /** @var ZMRedis $redis */
@@ -74,9 +62,6 @@ class KVRedis implements KVInterface
return (bool) $ret; return (bool) $ret;
} }
/**
* {@inheritDoc}
*/
public function getMultiple(iterable $keys, mixed $default = null): iterable public function getMultiple(iterable $keys, mixed $default = null): iterable
{ {
/** @var ZMRedis $redis */ /** @var ZMRedis $redis */
@@ -93,10 +78,7 @@ class KVRedis implements KVInterface
RedisPool::pool($this->pool_name)->put($redis); RedisPool::pool($this->pool_name)->put($redis);
} }
/** public function setMultiple(iterable $values, null|\DateInterval|int $ttl = null): bool
* {@inheritDoc}
*/
public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool
{ {
/** @var ZMRedis $redis */ /** @var ZMRedis $redis */
$redis = RedisPool::pool($this->pool_name)->get(); $redis = RedisPool::pool($this->pool_name)->get();
@@ -108,9 +90,6 @@ class KVRedis implements KVInterface
return $ret; return $ret;
} }
/**
* {@inheritDoc}
*/
public function deleteMultiple(iterable $keys): bool public function deleteMultiple(iterable $keys): bool
{ {
/** @var ZMRedis $redis */ /** @var ZMRedis $redis */
@@ -123,9 +102,6 @@ class KVRedis implements KVInterface
return $ret; return $ret;
} }
/**
* {@inheritDoc}
*/
public function has(string $key): bool public function has(string $key): bool
{ {
/** @var ZMRedis $redis */ /** @var ZMRedis $redis */

View File

@@ -6,6 +6,4 @@ namespace ZM\Store\KV\Redis;
use ZM\Exception\ZMException; use ZM\Exception\ZMException;
class RedisException extends ZMException class RedisException extends ZMException {}
{
}

View File

@@ -241,9 +241,7 @@ namespace ZM\Store\KV\Redis;
*/ */
class RedisWrapper class RedisWrapper
{ {
public function __construct(private string $pool = 'default') public function __construct(private string $pool = 'default') {}
{
}
public function __call(string $name, array $arguments) public function __call(string $name, array $arguments)
{ {

View File

@@ -14,7 +14,7 @@ class CatCode
* @param array|MessageSegment|string $message_segment MessageSegment 对象或数组 * @param array|MessageSegment|string $message_segment MessageSegment 对象或数组
* @param bool $encode_text 是否对文本进行 CatCode 编码(默认为否) * @param bool $encode_text 是否对文本进行 CatCode 编码(默认为否)
*/ */
public static function fromSegment(string|array|MessageSegment $message_segment, bool $encode_text = false): string public static function fromSegment(array|MessageSegment|string $message_segment, bool $encode_text = false): string
{ {
// 传入的必须是段数组或段对象 // 传入的必须是段数组或段对象
if (is_array($message_segment)) { if (is_array($message_segment)) {
@@ -40,7 +40,7 @@ class CatCode
* @param bool $is_param 如果是转义CatCode本体内容则为false默认如果是参数内的字符串则为true * @param bool $is_param 如果是转义CatCode本体内容则为false默认如果是参数内的字符串则为true
* @return string 转义后的CatCode * @return string 转义后的CatCode
*/ */
public static function encode(\Stringable|int|string $msg, bool $is_param = false): string public static function encode(int|string|\Stringable $msg, bool $is_param = false): string
{ {
$msg = str_replace(['&', '[', ']'], ['&amp;', '&#91;', '&#93;'], (string) $msg); $msg = str_replace(['&', '[', ']'], ['&amp;', '&#91;', '&#93;'], (string) $msg);
if ($is_param) { if ($is_param) {
@@ -56,7 +56,7 @@ class CatCode
* @param bool $is_param 如果是解码CatCode本体内容则为false默认如果是参数内的字符串则为true * @param bool $is_param 如果是解码CatCode本体内容则为false默认如果是参数内的字符串则为true
* @return string 转义后的CatCode * @return string 转义后的CatCode
*/ */
public static function decode(\Stringable|int|string $msg, bool $is_param = false): string public static function decode(int|string|\Stringable $msg, bool $is_param = false): string
{ {
$msg = str_replace(['&amp;', '&#91;', '&#93;'], ['&', '[', ']'], (string) $msg); $msg = str_replace(['&amp;', '&#91;', '&#93;'], ['&', '[', ']'], (string) $msg);
if ($is_param) { if ($is_param) {

View File

@@ -14,9 +14,7 @@ use ZM\Utils\ZMUtil;
*/ */
class PluginGenerator class PluginGenerator
{ {
public function __construct(private string $name, private string $plugin_dir) public function __construct(private string $name, private string $plugin_dir) {}
{
}
/** /**
* 开始生成 * 开始生成

View File

@@ -61,7 +61,7 @@ class MessageUtil
return $arr; return $arr;
} }
public static function convertToArr(MessageSegment|\Stringable|array|string $message): array public static function convertToArr(array|MessageSegment|string|\Stringable $message): array
{ {
if (is_array($message)) { if (is_array($message)) {
foreach ($message as $k => $v) { foreach ($message as $k => $v) {
@@ -99,7 +99,7 @@ class MessageUtil
return $ls; return $ls;
} }
public static function getAltMessage(null|array|string|MessageSegment $message): string public static function getAltMessage(null|array|MessageSegment|string $message): string
{ {
if ($message === null) { if ($message === null) {
return ''; return '';

View File

@@ -59,10 +59,10 @@ class OneBot12FileDownloader
$name = $obj->data['name']; $name = $obj->data['name'];
$data = base64_decode($obj->data['data']); $data = base64_decode($obj->data['data']);
// TODO: Walle-Q 返回的 sha256 是空的 // TODO: Walle-Q 返回的 sha256 是空的
/* if ($obj->data['sha256'] !== hash('sha256', $data)) { /* if ($obj->data['sha256'] !== hash('sha256', $data)) {
$this->err = 'sha256 mismatch between ' . $obj->data['sha256'] . ' and ' . hash('sha256', $data) . "\n" . json_encode($obj); $this->err = 'sha256 mismatch between ' . $obj->data['sha256'] . ' and ' . hash('sha256', $data) . "\n" . json_encode($obj);
return false; return false;
}*/ }*/
} else { } else {
$obj = $this->ctx->sendAction('get_file_fragmented', [ $obj = $this->ctx->sendAction('get_file_fragmented', [
'stage' => 'prepare', 'stage' => 'prepare',

View File

@@ -20,9 +20,7 @@ class OneBot12FileUploader
* @param BotContext $ctx 机器人上下文,用于调用发送动作 * @param BotContext $ctx 机器人上下文,用于调用发送动作
* @param int $buffer_size 分片传输的大小,默认为 65536 字节,建议调整小于 2MB * @param int $buffer_size 分片传输的大小,默认为 65536 字节,建议调整小于 2MB
*/ */
public function __construct(private BotContext $ctx, private int $buffer_size = 131072) public function __construct(private BotContext $ctx, private int $buffer_size = 131072) {}
{
}
/** /**
* 通过文件内容上传一个文件 * 通过文件内容上传一个文件

View File

@@ -81,7 +81,7 @@ class ReflectionUtil
* @param callable|string $callback 回调 * @param callable|string $callback 回调
* @throws \ReflectionException * @throws \ReflectionException
*/ */
public static function isNonStaticMethod(callable|array|string $callback): bool public static function isNonStaticMethod(array|callable|string $callback): bool
{ {
if (is_array($callback) && is_string($callback[0])) { if (is_array($callback) && is_string($callback[0])) {
$reflection = new \ReflectionMethod($callback[0], $callback[1]); $reflection = new \ReflectionMethod($callback[0], $callback[1]);

View File

@@ -22,7 +22,7 @@ class ZMRequest
* @param bool $only_body 是否只返回 Response body 部分,默认为 True * @param bool $only_body 是否只返回 Response body 部分,默认为 True
* @return bool|ResponseInterface|string 返回 False 代表请求失败,返回 string 为仅 Body 的内容,返回 Response 接口对象表明是回包 * @return bool|ResponseInterface|string 返回 False 代表请求失败,返回 string 为仅 Body 的内容,返回 Response 接口对象表明是回包
*/ */
public static function get(string|UriInterface|\Stringable $url, array $headers = [], array $config = [], bool $only_body = true): bool|ResponseInterface|string public static function get(string|\Stringable|UriInterface $url, array $headers = [], array $config = [], bool $only_body = true): bool|ResponseInterface|string
{ {
$socket = Framework::getInstance()->getDriver()->createHttpClientSocket(array_merge_recursive([ $socket = Framework::getInstance()->getDriver()->createHttpClientSocket(array_merge_recursive([
'url' => ($url instanceof UriInterface ? $url->__toString() : $url), 'url' => ($url instanceof UriInterface ? $url->__toString() : $url),
@@ -51,7 +51,7 @@ class ZMRequest
* @param bool $only_body 是否只返回 Response body 部分,默认为 True * @param bool $only_body 是否只返回 Response body 部分,默认为 True
* @return bool|ResponseInterface|string 返回 False 代表请求失败,返回 string 为仅 Body 的内容,返回 Response 接口对象表明是回包 * @return bool|ResponseInterface|string 返回 False 代表请求失败,返回 string 为仅 Body 的内容,返回 Response 接口对象表明是回包
*/ */
public static function post(string|UriInterface|\Stringable $url, array $header, mixed $data, array $config = [], bool $only_body = true): bool|ResponseInterface|string public static function post(string|\Stringable|UriInterface $url, array $header, mixed $data, array $config = [], bool $only_body = true): bool|ResponseInterface|string
{ {
$socket = Framework::getInstance()->getDriver()->createHttpClientSocket(array_merge_recursive([ $socket = Framework::getInstance()->getDriver()->createHttpClientSocket(array_merge_recursive([
'url' => ($url instanceof UriInterface ? $url->__toString() : $url), 'url' => ($url instanceof UriInterface ? $url->__toString() : $url),

View File

@@ -68,8 +68,8 @@ class ZMConfigTest extends TestCase
public function testGetValueWhenKeyContainsDot(): void public function testGetValueWhenKeyContainsDot(): void
{ {
$this->markTestSkipped('should it be supported?'); $this->markTestSkipped('should it be supported?');
// $this->assertEquals('c', $this->config->get('test.a.b')); // $this->assertEquals('c', $this->config->get('test.a.b'));
// $this->assertEquals('d', $this->config->get('test.a.b.c')); // $this->assertEquals('d', $this->config->get('test.a.b.c'));
} }
public function testGetBooleanValue(): void public function testGetBooleanValue(): void

View File

@@ -95,7 +95,7 @@ class HttpEventListenerTest extends TestCase
return $event->reveal(); return $event->reveal();
} }
private function mockHandler(bool $should_be_called, callable $callback = null): self private function mockHandler(bool $should_be_called, ?callable $callback = null): self
{ {
$handler = $this->prophesize(self::class); $handler = $this->prophesize(self::class);
if ($should_be_called) { if ($should_be_called) {

View File

@@ -68,8 +68,7 @@ class ReflectionUtilTest extends TestCase
public function provideTestGetCallReflector(): array public function provideTestGetCallReflector(): array
{ {
$closure = function () { $closure = function () {};
};
return [ return [
'callable' => [[new ReflectionUtilTestClass(), 'method'], new \ReflectionMethod(ReflectionUtilTestClass::class, 'method')], 'callable' => [[new ReflectionUtilTestClass(), 'method'], new \ReflectionMethod(ReflectionUtilTestClass::class, 'method')],
@@ -83,18 +82,12 @@ class ReflectionUtilTest extends TestCase
class ReflectionUtilTestClass class ReflectionUtilTestClass
{ {
public function method(string $string, ReflectionUtilTestClass $class): void public function method(string $string, ReflectionUtilTestClass $class): void {}
{
}
public static function staticMethod(string $string, ReflectionUtilTestClass $class): void public static function staticMethod(string $string, ReflectionUtilTestClass $class): void {}
{
}
} }
class InvokableClass class InvokableClass
{ {
public function __invoke(): void public function __invoke(): void {}
{
}
} }

View File

@@ -16,19 +16,19 @@ class ZMRequestTest extends TestCase
public function testPost() public function testPost()
{ {
$this->markTestIncomplete('Potential dead on Windows'); $this->markTestIncomplete('Potential dead on Windows');
// $r = ZMRequest::post('http://httpbin.org/post', [], 'niubi=123'); // $r = ZMRequest::post('http://httpbin.org/post', [], 'niubi=123');
// $this->assertStringContainsString('123', $r); // $this->assertStringContainsString('123', $r);
// $r2 = ZMRequest::post('http://httpbin.org/post', ['User-Agent' => 'test'], 'oijoij=ooo', [], false); // $r2 = ZMRequest::post('http://httpbin.org/post', ['User-Agent' => 'test'], 'oijoij=ooo', [], false);
// $this->assertInstanceOf(ResponseInterface::class, $r2); // $this->assertInstanceOf(ResponseInterface::class, $r2);
// $this->assertStringContainsString('ooo', $r2->getBody()->getContents()); // $this->assertStringContainsString('ooo', $r2->getBody()->getContents());
} }
public function testGet() public function testGet()
{ {
$this->markTestIncomplete('Potential dead on Windows'); $this->markTestIncomplete('Potential dead on Windows');
// $r = ZMRequest::get('http://httpbin.org/get', [ // $r = ZMRequest::get('http://httpbin.org/get', [
// 'X-Test' => '123', // 'X-Test' => '123',
// ]); // ]);
// $this->assertStringContainsString('123', $r); // $this->assertStringContainsString('123', $r);
} }
} }