diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98f5e411e3..2545a4dcce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -529,7 +529,7 @@ jobs: composer update --prefer-dist --no-progress Write-Output "::endgroup::" Write-Output "::group::Table Init" - php src\Cli\bin\imi-cli generate/table --app-namespace "Imi\Test\Component" + php src\Cli\bin\imi-cli generate/table --app-namespace "Imi\Model\Test" Write-Output "::endgroup::" - name: Install RoadRunner diff --git a/phpstan-components.neon b/phpstan-components.neon index e0ec71fb21..ea693efe9c 100644 --- a/phpstan-components.neon +++ b/phpstan-components.neon @@ -35,6 +35,9 @@ parameters: - message: '#^Call to an undefined method Swoole\\Coroutine\\#' reportUnmatched: false + - + message: '#should return .*static\(.+\).+but returns .+#' + reportUnmatched: false services: includes: diff --git a/src/Cli/Tools/Imi/Imi.php b/src/Cli/Tools/Imi/Imi.php index 8317e71e3e..33c24fb3a3 100644 --- a/src/Cli/Tools/Imi/Imi.php +++ b/src/Cli/Tools/Imi/Imi.php @@ -11,7 +11,6 @@ use Imi\Cli\Contract\BaseCommand; use Imi\Core\Runtime\Runtime; use Imi\Log\Log; -use Imi\Pool\Annotation\PoolClean; use Imi\Util\File; use Imi\Util\Imi as ImiUtil; use Imi\Util\Text; @@ -56,7 +55,6 @@ public function clearImiRuntime(?string $runtimeMode = null): void /** * 构建项目预加载缓存. */ - #[PoolClean] #[CommandAction(name: 'buildRuntime', description: '构建项目预加载缓存')] #[Option(name: 'changedFilesFile', type: \Imi\Cli\ArgType::STRING, comments: '保存改变的文件列表的文件,一行一个')] #[Option(name: 'confirm', type: \Imi\Cli\ArgType::BOOLEAN, default: false, comments: '是否等待输入y后再构建')] diff --git a/src/Components/database/src/Db.php b/src/Components/database/src/Db.php index c204d4aeb9..4affad3ce7 100644 --- a/src/Components/database/src/Db.php +++ b/src/Components/database/src/Db.php @@ -18,11 +18,6 @@ class Db { use \Imi\Util\Traits\TStaticClass; - /** - * 连接配置. - */ - private static ?array $connections = null; - /** * 获取新的数据库连接实例. * diff --git a/src/Components/database/src/Listener/WorkerStart.php b/src/Components/database/src/Listener/WorkerStart.php index 99eb30d9f3..91e0bd0c3c 100644 --- a/src/Components/database/src/Listener/WorkerStart.php +++ b/src/Components/database/src/Listener/WorkerStart.php @@ -7,9 +7,7 @@ use Imi\App; use Imi\Bean\Annotation\Listener; use Imi\Core\CoreEvents; -use Imi\Event\Event; use Imi\Event\IEventListener; -use Imi\Util\ImiPriority; #[Listener(eventName: CoreEvents::APP_RUN, priority: \Imi\Util\ImiPriority::IMI_MAX, one: true)] class WorkerStart implements IEventListener diff --git a/src/Components/model/src/Cli/Model/Event/Param/TGenerateModel.php b/src/Components/model/src/Cli/Model/Event/Param/TGenerateModel.php index c1ab6da0de..d639af176f 100644 --- a/src/Components/model/src/Cli/Model/Event/Param/TGenerateModel.php +++ b/src/Components/model/src/Cli/Model/Event/Param/TGenerateModel.php @@ -132,6 +132,13 @@ public function __construct( * 是否检查字段长度. */ public bool $lengthCheck = false, + + /** + * 类注解代码 + * + * @var string + */ + public string $classAttributeCode = '', ) { parent::__construct(static::class); } diff --git a/src/Components/model/src/Cli/Model/ModelGenerate.php b/src/Components/model/src/Cli/Model/ModelGenerate.php index d724230d6c..632fd611d7 100644 --- a/src/Components/model/src/Cli/Model/ModelGenerate.php +++ b/src/Components/model/src/Cli/Model/ModelGenerate.php @@ -53,7 +53,7 @@ public function generate(string $namespace, string $baseClass, ?string $database { Event::dispatch(eventName: BeforeGenerateModels::class); $db = Db::getInstance($poolName); - $tablePrefix = $db->getOption()['prefix'] ?? ''; + $tablePrefix = $db->getConfig()->prefix; if ('' !== $tablePrefix && !\in_array($tablePrefix, $prefix)) { $prefix[] = $tablePrefix; diff --git a/src/Components/model/src/Cli/Table/TableGenerate.php b/src/Components/model/src/Cli/Table/TableGenerate.php index 68cf0024ee..db1dc83b8e 100644 --- a/src/Components/model/src/Cli/Table/TableGenerate.php +++ b/src/Components/model/src/Cli/Table/TableGenerate.php @@ -56,7 +56,7 @@ public function generate(?string $namespace, ?string $database, ?string $poolNam $query = Db::query($poolName ?? $meta->getDbPoolName()); if ($meta->isUsePrefix()) { - $table = ($query->getDb()->getOption()['prefix'] ?? '') . $table; + $table = $query->getDb()->getConfig()->prefix . $table; } if (\in_array($table, $tables)) { diff --git a/src/Components/model/tests/config/config.php b/src/Components/model/tests/config/config.php index 990c9b91a8..6b4eadd20e 100644 --- a/src/Components/model/tests/config/config.php +++ b/src/Components/model/tests/config/config.php @@ -5,6 +5,11 @@ use function Imi\env; return [ + // 组件命名空间 + 'components' => [ + 'model' => 'Imi\Model', + ], + // 日志配置 'logger' => [ 'channels' => [ diff --git a/src/Components/phar/tests/project/config/config.php b/src/Components/phar/tests/project/config/config.php index 9f7424d2d5..796bcd9c5a 100644 --- a/src/Components/phar/tests/project/config/config.php +++ b/src/Components/phar/tests/project/config/config.php @@ -77,120 +77,6 @@ ], ], - // 连接池配置 - 'pools' => 'swoole' === $mode ? [ - // 主数据库 - 'maindb' => [ - 'pool' => [ - 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class, - 'config' => [ - 'maxResources' => 10, - 'minResources' => 0, - ], - ], - 'resource' => [ - 'host' => '127.0.0.1', - 'port' => 3306, - 'username' => 'root', - 'password' => 'root', - 'database' => 'mysql', - 'charset' => 'utf8mb4', - ], - ], - 'redis' => [ - 'pool' => [ - 'class' => \Imi\Swoole\Redis\Pool\CoroutineRedisPool::class, - 'config' => [ - 'maxResources' => 10, - 'minResources' => 0, - ], - ], - 'resource' => [ - 'host' => '127.0.0.1', - 'port' => 6379, - 'password' => null, - ], - ], - ] : [], - - // 数据库配置 - 'db' => [ - // 数默认连接池名 - 'defaultPool' => 'maindb', - // FPM、Workerman 下用 - 'connections' => [ - 'maindb' => [ - 'host' => '127.0.0.1', - 'port' => 3306, - 'username' => 'root', - 'password' => 'root', - 'database' => 'mysql', - 'charset' => 'utf8mb4', - // 'port' => '3306', - // 'timeout' => '建立连接超时时间', - // 'charset' => '', - // 使用 hook pdo 驱动(缺省默认) - // 'dbClass' => \Imi\Db\Drivers\PdoMysql\Driver::class, - // 使用 hook mysqli 驱动 - // 'dbClass' => \Imi\Db\Drivers\Mysqli\Driver::class, - // 使用 Swoole MySQL 驱动 - // 'dbClass' => \Imi\Swoole\Db\Drivers\Swoole\Driver::class, - // 数据库连接后,执行初始化的 SQL - // 'sqls' => [ - // 'select 1', - // 'select 2', - // ], - ], - ], - ], - - // redis 配置 - 'redis' => [ - // 数默认连接池名 - 'defaultPool' => 'redis', - // FPM、Workerman 下用 - 'connections' => [ - 'redis' => [ - 'host' => '127.0.0.1', - 'port' => 6379, - // 是否自动序列化变量 - 'serialize' => true, - // 密码 - 'password' => null, - // 第几个库 - 'db' => 0, - ], - ], - ], - - // 内存表配置 - 'memoryTable' => [ - // 't1' => [ - // 'columns' => [ - // ['name' => 'name', 'type' => \Swoole\Table::TYPE_STRING, 'size' => 16], - // ['name' => 'quantity', 'type' => \Swoole\Table::TYPE_INT], - // ], - // 'lockId' => 'atomic', - // ], - ], - - // 锁 - 'lock' => [ - // 'list' => [ - // 'atomic' => [ - // 'class' => 'AtomicLock', - // 'options' => [ - // 'atomicName' => 'atomicLock', - // ], - // ], - // ], - ], - - // atmoic 配置 - 'atomics' => [ - // 'atomicLock' => 1, - ], - // 日志配置 'logger' => [ 'channels' => [ diff --git a/src/Components/snowflake/composer.json b/src/Components/snowflake/composer.json index 3fb050766a..ee1d2912db 100644 --- a/src/Components/snowflake/composer.json +++ b/src/Components/snowflake/composer.json @@ -17,7 +17,8 @@ "Imi\\Snowflake\\Test\\": "tests/" }, "files": [ - "../../../vendor/autoload.php" + "../../../vendor/autoload.php", + "../database/vendor/autoload.php" ] }, "scripts": {}, diff --git a/src/Components/snowflake/tests/config/config.php b/src/Components/snowflake/tests/config/config.php index a5cf2c3a94..ec21f04598 100644 --- a/src/Components/snowflake/tests/config/config.php +++ b/src/Components/snowflake/tests/config/config.php @@ -13,33 +13,27 @@ ], 'ignoreNamespace' => [ ], - // 连接池配置 - 'pools' => [ + 'connectionCenter' => [ // 主数据库 - 'maindb' => [ - 'pool' => [ - // 协程池类名 - 'class' => \Imi\Db\Pool\SyncDbPool::class, - // 连接池配置 - 'config' => [ - 'maxResources' => 10, - 'minResources' => 1, - 'checkStateWhenGetResource' => false, - ], - ], - // 连接池资源配置 - 'resource' => [ - 'host' => env('MYSQL_SERVER_HOST', '127.0.0.1'), - 'port' => env('MYSQL_SERVER_PORT', 3306), - 'username' => env('MYSQL_SERVER_USERNAME', 'root'), - 'password' => env('MYSQL_SERVER_PASSWORD', 'root'), - 'database' => 'db_imi_test', - 'charset' => 'utf8mb4', - 'initSqls' => [ - 'SET @__pool_name="maindb"', + 'maindb' => [ + 'manager' => \Imi\ConnectionCenter\Handler\RequestContextSingleton\RequestContextSingletonConnectionManager::class, + 'config' => [ + 'driver' => \Imi\Db\ConnectionCenter\DatabaseDriver::class, + 'dbDriver' => \Imi\Db\Mysql\Drivers\PdoMysql\Driver::class, + 'resources' => [ + [ + 'host' => env('MYSQL_SERVER_HOST', '127.0.0.1'), + 'port' => env('MYSQL_SERVER_PORT', 3306), + 'username' => env('MYSQL_SERVER_USERNAME', 'root'), + 'password' => env('MYSQL_SERVER_PASSWORD', 'root'), + 'database' => 'db_imi_test', + ], ], ], ], + ], + // 连接池配置 + 'pools' => [ 'redis_test' => [ 'pool' => [ 'class' => \Imi\Redis\SyncRedisPool::class, diff --git a/src/Components/swoole-tracker/example/TCPServer/config/config.php b/src/Components/swoole-tracker/example/TCPServer/config/config.php index ff909790fd..aabcf760b3 100644 --- a/src/Components/swoole-tracker/example/TCPServer/config/config.php +++ b/src/Components/swoole-tracker/example/TCPServer/config/config.php @@ -65,45 +65,6 @@ // 连接池配置 'pools' => [ - // 主数据库 - // 'maindb' => [ - // // 同步池子 - // 'sync' => [ - // 'pool' => [ - // 'class' => \Imi\Db\Pool\SyncDbPool::class, - // 'config' => [ - // 'maxResources' => 10, - // 'minResources' => 0, - // ], - // ], - // 'resource' => [ - // 'host' => '127.0.0.1', - // 'port' => 3306, - // 'username' => 'root', - // 'password' => 'root', - // 'database' => 'database_name', - // 'charset' => 'utf8mb4', - // ], - // ], - // // 异步池子,worker进程使用 - // 'async' => [ - // 'pool' => [ - // 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class, - // 'config' => [ - // 'maxResources' => 10, - // 'minResources' => 0, - // ], - // ], - // 'resource' => [ - // 'host' => '127.0.0.1', - // 'port' => 3306, - // 'username' => 'root', - // 'password' => 'root', - // 'database' => 'database_name', - // 'charset' => 'utf8mb4', - // ], - // ] - // ], 'redis' => [ 'sync' => [ 'pool' => [ diff --git a/src/Components/swoole-tracker/example/UDPServer/config/config.php b/src/Components/swoole-tracker/example/UDPServer/config/config.php index 8d82a6a538..2caabb18d9 100644 --- a/src/Components/swoole-tracker/example/UDPServer/config/config.php +++ b/src/Components/swoole-tracker/example/UDPServer/config/config.php @@ -46,75 +46,6 @@ // 连接池配置 'pools' => [ - // 主数据库 - // 'maindb' => [ - // // 同步池子 - // 'sync' => [ - // 'pool' => [ - // 'class' => \Imi\Db\Pool\SyncDbPool::class, - // 'config' => [ - // 'maxResources' => 10, - // 'minResources' => 0, - // ], - // ], - // 'resource' => [ - // 'host' => '127.0.0.1', - // 'port' => 3306, - // 'username' => 'root', - // 'password' => 'root', - // 'database' => 'database_name', - // 'charset' => 'utf8mb4', - // ], - // ], - // // 异步池子,worker进程使用 - // 'async' => [ - // 'pool' => [ - // 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class, - // 'config' => [ - // 'maxResources' => 10, - // 'minResources' => 0, - // ], - // ], - // 'resource' => [ - // 'host' => '127.0.0.1', - // 'port' => 3306, - // 'username' => 'root', - // 'password' => 'root', - // 'database' => 'database_name', - // 'charset' => 'utf8mb4', - // ], - // ] - // ], - // 'redis' => [ - // 'sync' => [ - // 'pool' => [ - // 'class' => \Imi\Redis\SyncRedisPool::class, - // 'config' => [ - // 'maxResources' => 10, - // 'minResources' => 0, - // ], - // ], - // 'resource' => [ - // 'host' => '127.0.0.1', - // 'port' => 6379, - // 'password' => null, - // ] - // ], - // 'async' => [ - // 'pool' => [ - // 'class' => \Imi\Swoole\Redis\Pool\CoroutineRedisPool::class, - // 'config' => [ - // 'maxResources' => 10, - // 'minResources' => 0, - // ], - // ], - // 'resource' => [ - // 'host' => '127.0.0.1', - // 'port' => 6379, - // 'password' => null, - // ] - // ], - // ], ], // 数据库配置 diff --git a/src/Components/swoole/src/Db/Pool/CoroutineDbPool.php b/src/Components/swoole/src/Db/Pool/CoroutineDbPool.php deleted file mode 100644 index 191b0f61d8..0000000000 --- a/src/Components/swoole/src/Db/Pool/CoroutineDbPool.php +++ /dev/null @@ -1,35 +0,0 @@ -initUriResourceConfig(); - } - - /** - * {@inheritDoc} - */ - public function createNewResource(): IPoolResource - { - $config = $this->getNextResourceConfig(); - - return new DbResource($this, App::newInstance($config['dbClass'] ?? 'PdoMysqlDriver', $config)); - } -} diff --git a/src/Components/swoole/src/HotUpdate/HotUpdateProcess.php b/src/Components/swoole/src/HotUpdate/HotUpdateProcess.php index 63157585e9..5882e4b271 100644 --- a/src/Components/swoole/src/HotUpdate/HotUpdateProcess.php +++ b/src/Components/swoole/src/HotUpdate/HotUpdateProcess.php @@ -9,7 +9,6 @@ use Imi\Event\Event; use Imi\HotUpdate\Event\HotUpdateBeginBuildEvent; use Imi\Log\Log; -use Imi\Pool\Annotation\PoolClean; use Imi\Process\Event\ProcessEvents; use Imi\Swoole\Event\SwooleEvents; use Imi\Swoole\Process\Annotation\Process; @@ -103,7 +102,6 @@ class HotUpdateProcess extends BaseProcess private bool $running = false; - #[PoolClean] public function run(\Swoole\Process $process): void { if (!$this->status) diff --git a/src/Components/swoole/tests/unit/Component/PHPUnitHook.php b/src/Components/swoole/tests/unit/Component/PHPUnitHook.php index ac495662f2..3112f6487d 100644 --- a/src/Components/swoole/tests/unit/Component/PHPUnitHook.php +++ b/src/Components/swoole/tests/unit/Component/PHPUnitHook.php @@ -5,9 +5,6 @@ namespace Imi\Swoole\Test\Component; use Imi\App; -use Imi\Db\Interfaces\IDb; -use Imi\Pool\Interfaces\IPoolResource; -use Imi\Pool\PoolManager; use Imi\Swoole\SwooleApp; use PHPUnit\Event\TestRunner\ExecutionFinished; use PHPUnit\Event\TestRunner\ExecutionFinishedSubscriber; @@ -52,18 +49,6 @@ public function executeBeforeFirstTest(): void { $this->channel = $channel = new Channel(1); Coroutine::create(static fn () => App::run('Imi\Swoole\Test\Component', SwooleApp::class, static function () use ($channel): void { - PoolManager::use('maindb', static function (IPoolResource $resource, IDb $db): void { - $truncateList = [ - 'tb_article', - 'tb_member', - 'tb_update_time', - 'tb_performance', - ]; - foreach ($truncateList as $table) - { - $db->exec('TRUNCATE ' . $table); - } - }); $channel->push(1); $channel->pop(); })); diff --git a/src/Components/swoole/tests/unit/Component/Pool/PoolTestClass.php b/src/Components/swoole/tests/unit/Component/Pool/PoolTestClass.php deleted file mode 100644 index 5ab0528569..0000000000 --- a/src/Components/swoole/tests/unit/Component/Pool/PoolTestClass.php +++ /dev/null @@ -1,14 +0,0 @@ -\'$.uid\' = :p1'; -} diff --git a/src/Components/swoole/tests/unit/Component/Tests/PoolTest.php b/src/Components/swoole/tests/unit/Component/Tests/PoolTest.php deleted file mode 100644 index eaa13e809b..0000000000 --- a/src/Components/swoole/tests/unit/Component/Tests/PoolTest.php +++ /dev/null @@ -1,21 +0,0 @@ -go(function (): void { - $object = RequestContext::getBean(PoolTestClass::class); - $this->assertInstanceOf(DbResource::class, $object->db); - }); - } -} diff --git a/src/Components/swoole/tests/unit/Component/config/config.php b/src/Components/swoole/tests/unit/Component/config/config.php index 7bd4d1e05d..7e2aaabfc1 100644 --- a/src/Components/swoole/tests/unit/Component/config/config.php +++ b/src/Components/swoole/tests/unit/Component/config/config.php @@ -72,79 +72,6 @@ // 连接池配置 'pools' => [ - // 主数据库 - 'maindb' => [ - 'pool' => [ - // 协程池类名 - 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class, - // 连接池配置 - 'config' => [ - 'maxResources' => 10, - 'minResources' => 1, - 'checkStateWhenGetResource' => false, - ], - ], - // 连接池资源配置 - 'resource' => [ - 'host' => env('MYSQL_SERVER_HOST', '127.0.0.1'), - 'port' => env('MYSQL_SERVER_PORT', 3306), - 'username' => env('MYSQL_SERVER_USERNAME', 'root'), - 'password' => env('MYSQL_SERVER_PASSWORD', 'root'), - 'database' => 'db_imi_test', - 'charset' => 'utf8mb4', - 'initSqls' => [ - 'SET @__pool_name="maindb"', - ], - ], - ], - // 主数据库 - 'maindb.slave' => [ - 'pool' => [ - // 协程池类名 - 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class, - // 连接池配置 - 'config' => [ - 'maxResources' => 10, - 'minResources' => 1, - 'checkStateWhenGetResource' => false, - ], - ], - // 连接池资源配置 - 'resource' => [ - 'host' => env('MYSQL_SERVER_HOST', '127.0.0.1'), - 'port' => env('MYSQL_SERVER_PORT', 3306), - 'username' => env('MYSQL_SERVER_USERNAME', 'root'), - 'password' => env('MYSQL_SERVER_PASSWORD', 'root'), - 'database' => 'db_imi_test', - 'charset' => 'utf8mb4', - 'initSqls' => [ - 'SET @__pool_name="maindb.slave"', - ], - ], - ], - // mysqli - 'mysqli' => [ - 'pool' => [ - // 协程池类名 - 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class, - // 连接池配置 - 'config' => [ - 'maxResources' => 10, - 'minResources' => 1, - 'checkStateWhenGetResource' => false, - ], - ], - // 连接池资源配置 - 'resource' => [ - 'host' => env('MYSQL_SERVER_HOST', '127.0.0.1'), - 'port' => env('MYSQL_SERVER_PORT', 3306), - 'username' => env('MYSQL_SERVER_USERNAME', 'root'), - 'password' => env('MYSQL_SERVER_PASSWORD', 'root'), - 'database' => 'db_imi_test', - 'charset' => 'utf8mb4', - 'dbClass' => 'MysqliDriver', - ], - ], 'redis_test' => [ 'pool' => [ 'class' => \Imi\Swoole\Redis\Pool\CoroutineRedisPool::class, diff --git a/src/Components/swoole/tests/unit/Component/test.php b/src/Components/swoole/tests/unit/Component/test.php index 690b6e7aa3..2522d52a5a 100644 --- a/src/Components/swoole/tests/unit/Component/test.php +++ b/src/Components/swoole/tests/unit/Component/test.php @@ -3,7 +3,6 @@ declare(strict_types=1); use Imi\App; -use Imi\Db\Db; use Imi\Swoole\SwooleApp; use function Swoole\Coroutine\run; @@ -12,7 +11,6 @@ run(static function (): void { App::runApp(__DIR__, SwooleApp::class, static function (): void { - Db::getInstance(); // 必须,获取连接后,连接池就被启动了 echo 'Test swoole quick start', \PHP_EOL; }); }); diff --git a/src/Components/swoole/tests/unit/HttpServer/Process/PoolTest1Process.php b/src/Components/swoole/tests/unit/HttpServer/Process/PoolTest1Process.php deleted file mode 100644 index 230656f46d..0000000000 --- a/src/Components/swoole/tests/unit/HttpServer/Process/PoolTest1Process.php +++ /dev/null @@ -1,27 +0,0 @@ -getCount(); - } - echo json_encode($result), \PHP_EOL; - $process->exit(); - } -} diff --git a/src/Components/swoole/tests/unit/HttpServer/Process/PoolTest2Process.php b/src/Components/swoole/tests/unit/HttpServer/Process/PoolTest2Process.php deleted file mode 100644 index 3d1e65f990..0000000000 --- a/src/Components/swoole/tests/unit/HttpServer/Process/PoolTest2Process.php +++ /dev/null @@ -1,26 +0,0 @@ -getCount(); - } - echo json_encode($result), \PHP_EOL; - } -} diff --git a/src/Components/swoole/tests/unit/HttpServer/Tests/ProcessTest.php b/src/Components/swoole/tests/unit/HttpServer/Tests/ProcessTest.php index 346a02f3d9..4743de3079 100644 --- a/src/Components/swoole/tests/unit/HttpServer/Tests/ProcessTest.php +++ b/src/Components/swoole/tests/unit/HttpServer/Tests/ProcessTest.php @@ -11,34 +11,6 @@ */ class ProcessTest extends BaseTestCase { - /** - * 测试 PoolClean 注解,mode=allow. - */ - public function testPoolCleanAllow(): void - { - $file = \dirname(__DIR__) . '/bin/imi'; - $cmd = \Imi\cmd('"' . $file . '" process/start PoolTest1'); - $result = shell_exec("{$cmd}"); - $this->assertStringContainsString(json_encode([ - 'maindb' => 0, - 'redis' => 0, - ]), $result); - } - - /** - * 测试 PoolClean 注解,mode=deny. - */ - public function testPoolCleanDeny(): void - { - $file = \dirname(__DIR__) . '/bin/imi'; - $cmd = \Imi\cmd('"' . $file . '" process/run PoolTest2'); - $result = shell_exec("{$cmd}"); - $this->assertStringContainsString(json_encode([ - 'maindb' => 0, - 'redis' => 1, - ]), $result); - } - /** * getProcessWithManager. */ diff --git a/src/Components/swoole/tests/unit/HttpServer/config/config.php b/src/Components/swoole/tests/unit/HttpServer/config/config.php index 56e5164081..0fbfcda760 100644 --- a/src/Components/swoole/tests/unit/HttpServer/config/config.php +++ b/src/Components/swoole/tests/unit/HttpServer/config/config.php @@ -118,24 +118,6 @@ // 连接池配置 'pools' => [ - // 主数据库 - 'maindb' => [ - 'pool' => [ - 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class, - 'config' => [ - 'maxResources' => 10, - 'minResources' => 1, - ], - ], - 'resource' => [ - 'host' => env('MYSQL_SERVER_HOST', '127.0.0.1'), - 'port' => env('MYSQL_SERVER_PORT', 3306), - 'username' => env('MYSQL_SERVER_USERNAME', 'root'), - 'password' => env('MYSQL_SERVER_PASSWORD', 'root'), - 'database' => 'mysql', - 'charset' => 'utf8mb4', - ], - ], 'redis' => [ 'pool' => [ 'class' => \Imi\Swoole\Redis\Pool\CoroutineRedisPool::class, diff --git a/src/Components/swoole/tests/unit/RedisSessionServer/config/config.php b/src/Components/swoole/tests/unit/RedisSessionServer/config/config.php index 87b621a08e..5d4266f055 100644 --- a/src/Components/swoole/tests/unit/RedisSessionServer/config/config.php +++ b/src/Components/swoole/tests/unit/RedisSessionServer/config/config.php @@ -75,24 +75,6 @@ // 连接池配置 'pools' => [ - // 主数据库 - 'maindb' => [ - 'pool' => [ - 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class, - 'config' => [ - 'maxResources' => 10, - 'minResources' => 0, - ], - ], - 'resource' => [ - 'host' => env('MYSQL_SERVER_HOST', '127.0.0.1'), - 'port' => env('MYSQL_SERVER_PORT', 3306), - 'username' => env('MYSQL_SERVER_USERNAME', 'root'), - 'password' => env('MYSQL_SERVER_PASSWORD', 'root'), - 'database' => 'mysql', - 'charset' => 'utf8mb4', - ], - ], 'redis' => [ 'pool' => [ 'class' => \Imi\Swoole\Redis\Pool\CoroutineRedisPool::class, diff --git a/src/Components/workerman-gateway/composer.json b/src/Components/workerman-gateway/composer.json index 389447f4b7..82dbf82f98 100644 --- a/src/Components/workerman-gateway/composer.json +++ b/src/Components/workerman-gateway/composer.json @@ -4,6 +4,7 @@ "license": "MulanPSL-2.0", "description": "imi workerman gateway component", "require": { + "workerman/workerman": "^4.0", "workerman/gateway-worker": "^3.0", "yurunsoft/workerman-gateway-sdk": "^1.0" }, diff --git a/src/Components/workerman/src/Server/WorkermanServerWorker.php b/src/Components/workerman/src/Server/WorkermanServerWorker.php index 3e09fd47f0..9979d7b052 100644 --- a/src/Components/workerman/src/Server/WorkermanServerWorker.php +++ b/src/Components/workerman/src/Server/WorkermanServerWorker.php @@ -17,6 +17,7 @@ public function __construct(string $socket_name = '', array $context_option = [] { parent::__construct($socket_name, $context_option); + // @phpstan-ignore-next-line if (OS_TYPE_LINUX === static::$_OS // if linux && version_compare(\PHP_VERSION, '7.0.0', 'ge') // if php >= 7.0.0 && version_compare(php_uname('r'), '3.9', 'ge') // if kernel >=3.9 diff --git a/src/Pool/Annotation/PoolClean.php b/src/Pool/Annotation/PoolClean.php deleted file mode 100644 index dd018b638e..0000000000 --- a/src/Pool/Annotation/PoolClean.php +++ /dev/null @@ -1,26 +0,0 @@ -getTarget()), $joinPoint->getMethod(), PoolClean::class, true, true); - switch ($poolClean->mode) - { - case 'allow': - PoolManager::cleanAllow($poolClean->list); - break; - case 'deny': - PoolManager::cleanDeny($poolClean->list); - break; - } - } -} diff --git a/tests/db/generate-model.sh b/tests/db/generate-model.sh index 1d75149b57..77e5de553a 100644 --- a/tests/db/generate-model.sh +++ b/tests/db/generate-model.sh @@ -2,7 +2,7 @@ __DIR__=$(cd `dirname $0`; pwd)/../../ -$__DIR__/src/Cli/bin/imi-cli generate/model "Imi\Test\Component\Model" --app-namespace "Imi\Test\Component" --prefix=tb_ --override=base --lengthCheck --sqlSingleLine --exclude tb_prefix +$__DIR__/src/Cli/bin/imi-cli generate/model "Imi\Model\Test\Model" --app-namespace "Imi\Model\Test" --prefix=tb_ --override=base --lengthCheck --sqlSingleLine --exclude tb_prefix $__DIR__/src/Cli/bin/imi-cli generate/model "Imi\Test\Component\Model" --app-namespace "Imi\Test\Component" --poolName=dbPrefix --override=base --lengthCheck --sqlSingleLine --include tb_prefix diff --git a/tests/db/install-db.sh b/tests/db/install-db.sh index 562e4422e7..9a33df3c59 100755 --- a/tests/db/install-db.sh +++ b/tests/db/install-db.sh @@ -3,4 +3,4 @@ __DIR__=$(cd `dirname $0`; pwd) # MySQL -$__DIR__/../../src/Cli/bin/imi-cli generate/table --app-namespace "Imi\Test\Component" +$__DIR__/../../src/Cli/bin/imi-cli generate/table --app-namespace "Imi\Model\Test"