mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?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-sqlite')]
|
|
class swoole_hook_sqlite extends Extension
|
|
{
|
|
public function getUnixConfigureArg(): string
|
|
{
|
|
// pdo_pgsql need to be disabled
|
|
if ($this->builder->getExt('pdo_sqlite') !== null) {
|
|
throw new WrongUsageException('swoole-hook-sqlite provides pdo_sqlite, if you enable sqlite hook for swoole, you must remove pdo_sqlite extension.');
|
|
}
|
|
// enable swoole pgsql hook
|
|
return '--enable-swoole-sqlite';
|
|
}
|
|
|
|
public function runCliCheckUnix(): void
|
|
{
|
|
// skip if not enable swoole
|
|
if ($this->builder->getExt('swoole') === null) {
|
|
return;
|
|
}
|
|
[$ret, $out] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php --ri "swoole"', false);
|
|
$out = implode('', $out);
|
|
if ($ret !== 0) {
|
|
throw new RuntimeException('extension ' . $this->getName() . ' failed compile check: php-cli returned ' . $ret);
|
|
}
|
|
if (!str_contains($out, 'coroutine_sqlite')) {
|
|
throw new RuntimeException('swoole sqlite hook is not enabled correctly.');
|
|
}
|
|
}
|
|
}
|