2024-01-03 10:31:21 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\extension;
|
|
|
|
|
|
|
|
|
|
use SPC\builder\Extension;
|
2025-08-06 20:43:23 +08:00
|
|
|
use SPC\exception\ValidationException;
|
2024-01-03 10:31:21 +08:00
|
|
|
use SPC\util\CustomExt;
|
|
|
|
|
|
|
|
|
|
#[CustomExt('swoole-hook-mysql')]
|
|
|
|
|
class swoole_hook_mysql extends Extension
|
|
|
|
|
{
|
2024-02-04 16:18:20 +08:00
|
|
|
public function getDistName(): string
|
|
|
|
|
{
|
|
|
|
|
return 'swoole';
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-27 11:12:19 +07:00
|
|
|
public function getUnixConfigureArg(bool $shared = false): string
|
2024-01-03 10:31:21 +08:00
|
|
|
{
|
|
|
|
|
// pdo_mysql doesn't need to be disabled
|
|
|
|
|
// enable swoole-hook-mysql will enable mysqli, pdo, pdo_mysql, we don't need to add any additional options
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 11:25:35 +08:00
|
|
|
public function runCliCheckUnix(): void
|
2024-01-03 10:31:21 +08:00
|
|
|
{
|
|
|
|
|
// skip if not enable swoole
|
|
|
|
|
if ($this->builder->getExt('swoole') === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-25 18:39:11 +07:00
|
|
|
[$ret, $out] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -n' . $this->getSharedExtensionLoadString() . ' --ri "swoole"', false);
|
2024-01-03 10:31:21 +08:00
|
|
|
$out = implode('', $out);
|
|
|
|
|
if ($ret !== 0) {
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException("extension {$this->getName()} failed compile check: php-cli returned {$ret}", validation_module: 'extension swoole_hook_mysql sanity check');
|
2024-01-03 10:31:21 +08:00
|
|
|
}
|
|
|
|
|
if (!str_contains($out, 'mysqlnd')) {
|
2025-08-25 11:09:02 +07:00
|
|
|
throw new ValidationException('swoole mysql hook is not enabled correctly.', validation_module: 'Extension swoole mysql hook availability check');
|
2024-01-03 10:31:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-08-25 12:08:53 +07:00
|
|
|
|
|
|
|
|
public function getSharedExtensionLoadString(): string
|
|
|
|
|
{
|
|
|
|
|
$ret = parent::getSharedExtensionLoadString();
|
|
|
|
|
return str_replace(' -d "extension=' . $this->name . '"', '', $ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buildShared(): void
|
|
|
|
|
{
|
|
|
|
|
// nothing to do, it's built into swoole
|
|
|
|
|
}
|
2024-01-03 10:31:21 +08:00
|
|
|
}
|