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\exception\WrongUsageException;
|
|
|
|
|
use SPC\util\CustomExt;
|
|
|
|
|
|
|
|
|
|
#[CustomExt('swoole-hook-pgsql')]
|
|
|
|
|
class swoole_hook_pgsql extends Extension
|
|
|
|
|
{
|
2024-02-04 16:18:20 +08:00
|
|
|
public function getDistName(): string
|
|
|
|
|
{
|
|
|
|
|
return 'swoole';
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 13:01:11 +08:00
|
|
|
public function validate(): void
|
2024-01-03 10:31:21 +08:00
|
|
|
{
|
|
|
|
|
// pdo_pgsql need to be disabled
|
|
|
|
|
if ($this->builder->getExt('pdo_pgsql') !== null) {
|
|
|
|
|
throw new WrongUsageException('swoole-hook-pgsql provides pdo_pgsql, if you enable pgsql hook for swoole, you must remove pdo_pgsql extension.');
|
|
|
|
|
}
|
2024-05-16 13:01:11 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-27 11:12:19 +07:00
|
|
|
public function getUnixConfigureArg(bool $shared = false): string
|
2024-05-16 13:01:11 +08:00
|
|
|
{
|
2024-01-03 10:31:21 +08:00
|
|
|
// enable swoole pgsql hook
|
|
|
|
|
return '--enable-swoole-pgsql';
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
$sharedExtensions = $this->getSharedExtensionLoadString();
|
|
|
|
|
[$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n' . $sharedExtensions . ' --ri "' . $this->getDistName() . '"');
|
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, 'coroutine_pgsql')) {
|
|
|
|
|
throw new RuntimeException('swoole pgsql hook is not enabled correctly.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|