|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Package\Extension; |
| 6 | + |
| 7 | +use Package\Target\php; |
| 8 | +use StaticPHP\Attribute\Package\BeforeStage; |
| 9 | +use StaticPHP\Attribute\Package\CustomPhpConfigureArg; |
| 10 | +use StaticPHP\Attribute\Package\Extension; |
| 11 | +use StaticPHP\Attribute\PatchDescription; |
| 12 | +use StaticPHP\Package\PackageInstaller; |
| 13 | +use StaticPHP\Package\PhpExtensionPackage; |
| 14 | +use StaticPHP\Util\FileSystem; |
| 15 | + |
| 16 | +#[Extension('clickhouse')] |
| 17 | +class clickhouse extends PhpExtensionPackage |
| 18 | +{ |
| 19 | + #[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-clickhouse')] |
| 20 | + #[PatchDescription('Replace THIS_DIR=`dirname $0` with PHP_EXT_SRCDIR() in config.m4 so include paths resolve to the ext source dir during PHP main configure (dirname $0 returns "." when run from php-src root).')] |
| 21 | + public function patchBeforeBuildconfUnix(): void |
| 22 | + { |
| 23 | + FileSystem::replaceFileRegex( |
| 24 | + "{$this->getSourceDir()}/config.m4", |
| 25 | + '/^(\s*)THIS_DIR=.*/m', |
| 26 | + '$1THIS_DIR=PHP_EXT_SRCDIR()', |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + #[CustomPhpConfigureArg('Darwin')] |
| 31 | + #[CustomPhpConfigureArg('Linux')] |
| 32 | + public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string |
| 33 | + { |
| 34 | + $arg = '--enable-clickhouse' . ($shared ? '=shared' : ''); |
| 35 | + if ($installer->getLibraryPackage('openssl')) { |
| 36 | + $arg .= ' --enable-clickhouse-openssl'; |
| 37 | + } |
| 38 | + return $arg; |
| 39 | + } |
| 40 | +} |
0 commit comments