2024-01-03 10:31:21 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\extension;
|
|
|
|
|
|
|
|
|
|
use SPC\builder\Extension;
|
|
|
|
|
use SPC\exception\RuntimeException;
|
|
|
|
|
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:29:34 +07:00
|
|
|
putenv('EXTENSION_DIR=' . BUILD_MODULES_PATH);
|
|
|
|
|
[$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) {
|
|
|
|
|
throw new RuntimeException('extension ' . $this->getName() . ' failed compile check: php-cli returned ' . $ret);
|
|
|
|
|
}
|
|
|
|
|
if (!str_contains($out, 'mysqlnd')) {
|
|
|
|
|
throw new RuntimeException('swoole mysql hook is not enabled correctly.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|