|
| 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\Extension; |
| 10 | +use StaticPHP\Attribute\PatchDescription; |
| 11 | +use StaticPHP\Util\FileSystem; |
| 12 | + |
| 13 | +#[Extension('pdo_sqlsrv')] |
| 14 | +class pdo_sqlsrv |
| 15 | +{ |
| 16 | + #[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-pdo_sqlsrv')] |
| 17 | + #[PatchDescription('Remove /sdl flag from pdo_sqlsrv config.w32 to prevent strict SDL check compilation failures')] |
| 18 | + public function patchBeforeBuildconfForWindows(): void |
| 19 | + { |
| 20 | + // Fix the compilation issue of pdo_sqlsrv on Windows (/sdl check is too strict and will cause Zend compilation to fail) |
| 21 | + if (file_exists(SOURCE_PATH . '/php-src/ext/pdo_sqlsrv/config.w32')) { |
| 22 | + FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/pdo_sqlsrv/config.w32', '/sdl', ''); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + #[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-pdo_sqlsrv')] |
| 27 | + #[PatchDescription('Fix pdo_sqlsrv directory structure for PHP 8.5+ (source layout changed)')] |
| 28 | + public function patchDirectoryStructureForPhp85(): void |
| 29 | + { |
| 30 | + $source_dir = SOURCE_PATH . '/php-src/ext/pdo_sqlsrv'; |
| 31 | + if (!file_exists($source_dir . '/config.m4') && is_dir($source_dir . '/source/pdo_sqlsrv')) { |
| 32 | + FileSystem::moveFileOrDir($source_dir . '/LICENSE', $source_dir . '/source/pdo_sqlsrv/LICENSE'); |
| 33 | + FileSystem::moveFileOrDir($source_dir . '/source/shared', $source_dir . '/source/pdo_sqlsrv/shared'); |
| 34 | + FileSystem::moveFileOrDir($source_dir . '/source/pdo_sqlsrv', SOURCE_PATH . '/pdo_sqlsrv'); |
| 35 | + FileSystem::removeDir($source_dir); |
| 36 | + FileSystem::moveFileOrDir(SOURCE_PATH . '/pdo_sqlsrv', $source_dir); |
| 37 | + } |
| 38 | + } |
| 39 | +} |
0 commit comments