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\exception\WrongUsageException;
|
|
|
|
|
use SPC\util\CustomExt;
|
|
|
|
|
|
|
|
|
|
#[CustomExt('swoole-hook-sqlite')]
|
|
|
|
|
class swoole_hook_sqlite 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
|
2025-08-25 11:09:02 +07:00
|
|
|
if ($this->builder->getExt('pdo_sqlite')?->isBuildStatic()) {
|
2024-01-03 10:31:21 +08:00
|
|
|
throw new WrongUsageException('swoole-hook-sqlite provides pdo_sqlite, if you enable sqlite hook for swoole, you must remove pdo_sqlite extension.');
|
|
|
|
|
}
|
2024-05-16 13:01:11 +08:00
|
|
|
}
|
|
|
|
|
|
2024-02-04 11:25:35 +08:00
|
|
|
public function runCliCheckUnix(): void
|
2024-01-03 10:31:21 +08:00
|
|
|
{
|
2025-05-25 18:29:34 +07:00
|
|
|
$sharedExtensions = $this->getSharedExtensionLoadString();
|
2025-08-26 01:01:45 +07:00
|
|
|
[$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n' . $sharedExtensions . ' --ri "' . $this->getDistName() . '"', 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 {$this->getName()} sanity check");
|
2024-01-03 10:31:21 +08:00
|
|
|
}
|
|
|
|
|
if (!str_contains($out, 'coroutine_sqlite')) {
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException('swoole sqlite hook is not enabled correctly.', validation_module: 'Extension swoole sqlite hook availability check');
|
2024-01-03 10:31:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|