From 57c17e33494ee747f6d6a4c887cb6659e7190980 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 12 Feb 2021 18:34:27 +0530 Subject: [PATCH] Add support for pecl_http on Windows for PHP 7.1 to 8.0 --- __tests__/extensions.test.ts | 3 +- dist/index.js | 4 ++- src/extensions.ts | 2 ++ src/scripts/ext/http.ps1 | 55 ++++++++++++++++++++++++++++++++++++ src/utils.ts | 2 +- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/scripts/ext/http.ps1 diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 8c0e5c85..664c1469 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -3,7 +3,7 @@ import * as extensions from '../src/extensions'; describe('Extension tests', () => { it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( - 'Xdebug, pcov, sqlite, :intl, phalcon4, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2, sqlsrv-1.2.3preview1', + 'Xdebug, pcov, sqlite, :intl, phalcon4, pecl_http, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2, sqlsrv-1.2.3preview1', '7.4', 'win32' ); @@ -12,6 +12,7 @@ describe('Extension tests', () => { expect(win32).toContain('Add-Extension sqlite3'); expect(win32).toContain('Remove-Extension intl'); expect(win32).toContain('Add-Phalcon phalcon4'); + expect(win32).toContain('Add-Http'); expect(win32).toContain('Add-Ioncube'); expect(win32).toContain('Add-Oci oci8'); expect(win32).toContain('Add-Oci pdo_oci'); diff --git a/dist/index.js b/dist/index.js index 63a3975b..bda97ecf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1405,7 +1405,7 @@ exports.scriptTool = scriptTool; * @param os_version */ async function customPackage(pkg, type, version, os_version) { - const pkg_name = pkg.replace(/\d+|pdo[_-]/, ''); + const pkg_name = pkg.replace(/\d+|(pdo|pecl)[_-]/, ''); const script_extension = await scriptExtension(os_version); const script = path.join(__dirname, '../src/scripts/' + type + '/' + pkg_name + script_extension); const command = await getCommand(os_version, pkg_name); @@ -2986,10 +2986,12 @@ async function addExtensionWindows(extension_csv, version) { // match pdo_oci and oci8 // match 5.3ioncube...7.4ioncube // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + // match 7.1pecl_http...8.0pecl_http and 7.1http...8.0http case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension): case /^pdo_oci$|^oci8$/.test(extension): case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): + case /^(7\.[1-4]|8\.0)(http|pecl_http)$/.test(version_extension): add_script += await utils.customPackage(ext_name, 'ext', extension, 'win32'); return; // match pre-release versions. For example - xdebug-beta diff --git a/src/extensions.ts b/src/extensions.ts index 1b476eae..d44ff166 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -136,12 +136,14 @@ export async function addExtensionWindows( // match pdo_oci and oci8 // match 5.3ioncube...7.4ioncube // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + // match 7.1pecl_http...8.0pecl_http and 7.1http...8.0http case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test( version_extension ): case /^pdo_oci$|^oci8$/.test(extension): case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): + case /^(7\.[1-4]|8\.0)(http|pecl_http)$/.test(version_extension): add_script += await utils.customPackage( ext_name, 'ext', diff --git a/src/scripts/ext/http.ps1 b/src/scripts/ext/http.ps1 new file mode 100644 index 00000000..7b67d279 --- /dev/null +++ b/src/scripts/ext/http.ps1 @@ -0,0 +1,55 @@ +Function Get-ICUUrl() { + Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + $icu_version, + [Parameter(Position = 1, Mandatory = $true)] + [ValidateNotNull()] + $arch, + [Parameter(Position = 2, Mandatory = $true)] + [ValidateNotNull()] + $vs_version + ) + $trunk = "https://windows.php.net" + $urls=@("${trunk}/downloads/php-sdk/deps/${vs_version}/${arch}", "${trunk}/downloads/php-sdk/deps/archives/${vs_version}/${arch}") + foreach ($url in $urls) { + $web_content = Invoke-WebRequest -Uri $url + foreach ($link in $web_content.Links) { + if ($link -match "/.*ICU-${icu_version}.*/") { + return $trunk + $link.HREF + } + } + } +} + +Function Repair-ICU() { + $icu = deplister $ext_dir\php_http.dll | Select-String "icu[a-z]+(\d+).dll,([A-Z]+)" | Foreach-Object { $_.Matches } + if($icu -and $icu.Groups[2].Value -ne 'OK') { + $vs = "vs" + $installed.VCVersion + if ($installed.VCVersion -lt 16) { + $vs = "vc" + $installed.VCVersion + } + $zip_url = Get-ICUUrl $icu.Groups[1].Value $installed.Architecture $vs + if ($zip_url -ne '') { + New-Item -Path "$php_dir" -Name "icu" -ItemType "directory" | Out-Null + Invoke-WebRequest -Uri $zip_url -OutFile "$php_dir\icu\icu.zip" + Expand-Archive -Path $php_dir\icu\icu.zip -DestinationPath $php_dir\icu -Force + Get-ChildItem $php_dir\icu\bin -Filter *.dll | Copy-Item -Destination $php_dir -Force + } + } +} + +Function Add-Http() { + Add-Extension raphf >$null 2>&1 + if($version -lt '8.0') { + Add-Extension propro >$null 2>&1 + } + Add-Extension pecl_http >$null 2>&1 + Repair-ICU + try { + php --ri "http" 2> $null | Out-Null + Add-Log $tick "http" "Installed and enabled" + } catch { + Add-Log $cross "http" "Could not install http on PHP $( $installed.FullVersion )" + } +} \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 4e42f4a8..5ab025bb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -428,7 +428,7 @@ export async function customPackage( version: string, os_version: string ): Promise { - const pkg_name: string = pkg.replace(/\d+|pdo[_-]/, ''); + const pkg_name: string = pkg.replace(/\d+|(pdo|pecl)[_-]/, ''); const script_extension: string = await scriptExtension(os_version); const script: string = path.join( __dirname,