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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ updates:
directory: "/"
schedule:
interval: "daily"
target-branch: "develop"
target-branch: "master"
labels:
- "area/dependency"
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Test
on:
push:
branches:
- master
- main
- develop
- '*-dev*'
Expand Down
6 changes: 4 additions & 2 deletions choir-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
/** @noinspection PhpComposerExtensionStubsInspection */

declare(strict_types=1);
use Choir\Http\Server;
use Choir\Protocol\HttpConnection;

require_once 'vendor/autoload.php';

$server = new \Choir\Http\Server('0.0.0.0', 20001, false, [
$server = new Server('0.0.0.0', 20001, false, [
'worker-num' => 8,
// 'logger-level' => 'debug',
]);
Expand All @@ -22,7 +24,7 @@
// echo "http://127.0.0.1:8080/index.php?run={$id}&source=xhprof_testing\n";
});

$server->on('request', function (Choir\Protocol\HttpConnection $connection) {
$server->on('request', function (HttpConnection $connection) {
$connection->end('hello world');
});

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"wiki": "https://github.com/botuniverse/php-libonebot/wiki"
},
"require": {
"php": "^7.4 || ^8.0 || ^8.1 || ^8.2",
"php": "^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4",
"ext-json": "*",
"psr/cache": "^1.0 || ^3.0",
"psr/event-dispatcher": "^1.0",
Expand Down Expand Up @@ -85,7 +85,7 @@
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/cghooks add"
],
"analyse": "phpstan analyse --memory-limit 300M",
"cs-fix": "php-cs-fixer fix",
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix",
"test": "phpunit --no-coverage"
}
}
9 changes: 6 additions & 3 deletions demo/repl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
declare(strict_types=1);

use OneBot\Driver\Event\DriverInitEvent;
use OneBot\Driver\Swoole\SwooleDriver;
use OneBot\Util\Utils;
use OneBot\V12\EventBuilder;
use OneBot\V12\Object\Action;
use OneBot\V12\Object\ActionResponse;
use OneBot\V12\OneBot;
use OneBot\V12\OneBotBuilder;
use OneBot\V12\Validator;
use ZM\Logger\ConsoleLogger;

require_once __DIR__ . '/../vendor/autoload.php';

Expand All @@ -23,11 +26,11 @@ function message_id(): string
'self_id' => 'REPL-1',
'db' => true,
'logger' => [
'class' => \ZM\Logger\ConsoleLogger::class,
'class' => ConsoleLogger::class,
'level' => 'info',
],
'driver' => [
'class' => \OneBot\Driver\Swoole\SwooleDriver::class,
'class' => SwooleDriver::class,
'config' => [
'init_in_user_process_block' => true,
],
Expand Down Expand Up @@ -81,7 +84,7 @@ function message_id(): string
$event->getDriver()->getEventLoop()->delReadEvent($x);
return;
}
$event = (new \OneBot\V12\EventBuilder('message', 'private'))
$event = (new EventBuilder('message', 'private'))
->feed('message', trim($s))
->feed('alt_message', trim($s))
->feed('message_id', message_id())
Expand Down
5 changes: 3 additions & 2 deletions demo/weixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OneBot\V12\RetCode;
use OneBot\V12\Validator;
use Swoole\Coroutine\Channel;
use ZM\Logger\ConsoleLogger;

require_once __DIR__ . '/../vendor/autoload.php';

Expand All @@ -24,7 +25,7 @@
'self_id' => '', // 后续会自动获取
'db' => true,
'logger' => [
'class' => \ZM\Logger\ConsoleLogger::class,
'class' => ConsoleLogger::class,
'level' => 'info',
],
'driver' => [
Expand Down Expand Up @@ -118,7 +119,7 @@ function wx_make_xml_reply(Action $action, string $self_id): string
return str_replace('{content}', '<![CDATA[' . $content . ']]>', $xml_template);
}

function swoole_channel(string $name, int $size = 1): Swoole\Coroutine\Channel
function swoole_channel(string $name, int $size = 1): Channel
{
global $channel;
if (!isset($channel[$name])) {
Expand Down
2 changes: 1 addition & 1 deletion src/OneBot/Config/Loader/DelegateLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DelegateLoader implements LoaderInterface
/**
* @param null|array{string: LoaderInterface} $loaders 加载器列表,null则使用默认列表
*/
public function __construct(array $loaders = null)
public function __construct(?array $loaders = null)
{
foreach ((array) $loaders as $key => $loader) {
if (!$loader instanceof LoaderInterface) {
Expand Down
4 changes: 1 addition & 3 deletions src/OneBot/Config/Loader/LoadException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace OneBot\Config\Loader;

class LoadException extends \RuntimeException
{
}
class LoadException extends \RuntimeException {}
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace OneBot\Driver\Event;

interface Event
{
}
interface Event {}
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Event/Process/ManagerStartEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use OneBot\Driver\Event\DriverEvent;

class ManagerStartEvent extends DriverEvent
{
}
class ManagerStartEvent extends DriverEvent {}
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Event/Process/ManagerStopEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use OneBot\Driver\Event\DriverEvent;

class ManagerStopEvent extends DriverEvent
{
}
class ManagerStopEvent extends DriverEvent {}
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Event/Process/WorkerExitEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use OneBot\Driver\Event\DriverEvent;

class WorkerExitEvent extends DriverEvent
{
}
class WorkerExitEvent extends DriverEvent {}
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Event/Process/WorkerStartEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use OneBot\Driver\Event\DriverEvent;

class WorkerStartEvent extends DriverEvent
{
}
class WorkerStartEvent extends DriverEvent {}
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Event/Process/WorkerStopEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use OneBot\Driver\Event\DriverEvent;

class WorkerStopEvent extends DriverEvent
{
}
class WorkerStopEvent extends DriverEvent {}
2 changes: 1 addition & 1 deletion src/OneBot/Driver/Event/StopException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class StopException extends \Exception
{
private DriverEvent $event;

public function __construct(DriverEvent $event, $message = '', $code = 0, \Throwable $previous = null)
public function __construct(DriverEvent $event, $message = '', $code = 0, ?\Throwable $previous = null)
{
$this->event = $event;
parent::__construct($message, $code, $previous);
Expand Down
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Swoole/Socket/HttpClientSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use OneBot\Driver\Socket\HttpClientSocketBase;

class HttpClientSocket extends HttpClientSocketBase
{
}
class HttpClientSocket extends HttpClientSocketBase {}
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Swoole/Socket/WSClientSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use OneBot\Driver\Socket\WSClientSocketBase;

class WSClientSocket extends WSClientSocketBase
{
}
class WSClientSocket extends WSClientSocketBase {}
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Workerman/Socket/HttpClientSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use OneBot\Driver\Socket\HttpClientSocketBase;

class HttpClientSocket extends HttpClientSocketBase
{
}
class HttpClientSocket extends HttpClientSocketBase {}
4 changes: 1 addition & 3 deletions src/OneBot/Driver/Workerman/Socket/WSClientSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use OneBot\Driver\Socket\WSClientSocketBase;

class WSClientSocket extends WSClientSocketBase
{
}
class WSClientSocket extends WSClientSocketBase {}
2 changes: 1 addition & 1 deletion src/OneBot/Driver/Workerman/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static function stopAll($code = 0, $log = '')
Timer::add(static::$stopTimeout, '\posix_kill', [$worker_pid, \SIGKILL], false);
}
}
Timer::add(1, '\\Workerman\\Worker::checkIfChildRunning');
Timer::add(1, '\Workerman\Worker::checkIfChildRunning');
// Remove statistics file.
if (\is_file(static::$_statisticsFile)) {
@\unlink(static::$_statisticsFile);
Expand Down
4 changes: 1 addition & 3 deletions src/OneBot/V12/Action/DefaultActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
/**
* 当未设置 Action 基础处理类时,将默认使用 ActionBase 级别的所有 Not Implemented Action
*/
class DefaultActionHandler extends ActionHandlerBase
{
}
class DefaultActionHandler extends ActionHandlerBase {}
4 changes: 1 addition & 3 deletions src/OneBot/V12/Exception/OneBotException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace OneBot\V12\Exception;

class OneBotException extends \Exception
{
}
class OneBotException extends \Exception {}
2 changes: 1 addition & 1 deletion src/OneBot/V12/Exception/OneBotFailureException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
$retcode = RetCode::INTERNAL_HANDLER_ERROR,
?Action $action_object = null,
$message = null,
\Exception $previous = null
?\Exception $previous = null
) {
$this->retcode = $retcode;
$this->action_object = $action_object;
Expand Down
3 changes: 1 addition & 2 deletions src/OneBot/V12/OneBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ public function dispatchEvent(OneBotEvent $event): void
}
$socket->post(json_encode($event->jsonSerialize()), $this->getRequestHeaders(), function (ResponseInterface $response) {
// TODO:编写 HTTP Webhook 响应的处理逻辑
}, function (RequestInterface $request) {
});
}, function (RequestInterface $request) {});
}
$frame_str = FrameFactory::createTextFrame(json_encode($event->jsonSerialize())); // 创建文本帧
foreach ($this->driver->getWSServerSockets() as $socket) {
Expand Down
3 changes: 2 additions & 1 deletion src/OneBot/V12/OneBotBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OneBot\V12;

use OneBot\Config\Config;
use OneBot\Config\Repository;
use OneBot\Config\RepositoryInterface;
use OneBot\Driver\Driver;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -136,7 +137,7 @@ public function build(): OneBot
*/
public static function buildFromArray(array $array): OneBot
{
$config = new \OneBot\Config\Repository($array);
$config = new Repository($array);
return self::buildFromConfig($config);
}

Expand Down
15 changes: 8 additions & 7 deletions src/OneBot/global_defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
use OneBot\V12\Object\MessageSegment;
use OneBot\V12\OneBot;
use Psr\Log\LoggerInterface;
use Symfony\Component\VarDumper\VarDumper;
use ZM\Logger\ConsoleLogger;

const ONEBOT_VERSION = '12';
const ONEBOT_LIBOB_VERSION = '0.6.8';
const ONEBOT_LIBOB_VERSION = '0.6.9';

const ONEBOT_JSON = 1;
const ONEBOT_MSGPACK = 2;
Expand All @@ -38,7 +39,7 @@
class_alias(MessageSegment::class, 'MessageSegment');

if (DIRECTORY_SEPARATOR === '\\') {
define('ONEBOT_TMP_DIR', 'C:\\Windows\\Temp');
define('ONEBOT_TMP_DIR', 'C:\Windows\Temp');
} elseif (!empty(getenv('TMPDIR'))) {
define('ONEBOT_TMP_DIR', getenv('TMPDIR'));
} elseif (is_writable('/tmp')) {
Expand All @@ -56,9 +57,9 @@ class_alias(MessageSegment::class, 'MessageSegment');
function ob_dump($var, ...$moreVars)
{
if (class_exists('\Symfony\Component\VarDumper\VarDumper')) {
Symfony\Component\VarDumper\VarDumper::dump($var);
VarDumper::dump($var);
foreach ($moreVars as $v) {
Symfony\Component\VarDumper\VarDumper::dump($v);
VarDumper::dump($v);
}
} elseif (PHP_VERSION >= 8.0) {
var_dump($var, ...$moreVars);
Expand Down Expand Up @@ -121,7 +122,7 @@ function ob_logger_register(LoggerInterface $logger): void
* @param null|mixed $default
* @return mixed
*/
function ob_config(string $key = null, $default = null)
function ob_config(?string $key = null, $default = null)
{
$config = OneBot::getInstance()->getConfig();
if (!is_null($key)) {
Expand All @@ -144,8 +145,8 @@ function ob_uuidgen(bool $uppercase = false): string
}
$data[6] = chr(ord($data[6]) & 0x0F | 0x40);
$data[8] = chr(ord($data[8]) & 0x3F | 0x80);
return $uppercase ? strtoupper(vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4))) :
vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
return $uppercase ? strtoupper(vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)))
: vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}

function ob_event_dispatcher(): HandledDispatcherInterface
Expand Down
12 changes: 6 additions & 6 deletions tests/OneBot/Config/Loader/AbstractFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public function providerTestGetAbsolutePath(): array
'Linux',
],
'windows absolute path' => [
'C:\\Windows\\System32\\drivers\\etc\\hosts',
'C:\\Windows\\System32',
'C:\\Windows\\System32\\drivers\\etc\\hosts',
'C:\Windows\System32\drivers\etc\hosts',
'C:\Windows\System32',
'C:\Windows\System32\drivers\etc\hosts',
'Windows',
],
'windows relative path' => [
'drivers\\etc\\hosts',
'C:\\Windows\\System32',
'C:\\Windows\\System32\\drivers\\etc\\hosts',
'drivers\etc\hosts',
'C:\Windows\System32',
'C:\Windows\System32\drivers\etc\hosts',
'Windows',
],
];
Expand Down
20 changes: 10 additions & 10 deletions tests/OneBot/Config/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ public function testDeleteValue(string $key): void
$this->assertNull($this->repository->get($key));
}

public function providerTestDeleteValue(): array
{
return [
'shallow' => ['foo'],
'deep' => ['associate.x'],
'not exists' => ['not_exists'],
'not exists deep' => ['deep.not_exists'],
];
}

public function testHas(): void
{
$this->assertTrue($this->repository->has('foo'));
Expand All @@ -119,14 +129,4 @@ public function testAll(): void
{
$this->assertSame($this->config, $this->repository->all());
}

public function providerTestDeleteValue(): array
{
return [
'shallow' => ['foo'],
'deep' => ['associate.x'],
'not exists' => ['not_exists'],
'not exists deep' => ['deep.not_exists'],
];
}
}
Loading
Loading