|
57 | 57 | if (-Not(Test-Path -LiteralPath $phpVersion.ExtensionsPath -PathType Container)) { |
58 | 58 | throw "The PHP extension directory ""$($phpVersion.ExtensionsPath)"" configured in your php.ini does not exist. You may need to create it, or fix the extension_dir setting in the php.ini file." |
59 | 59 | } |
| 60 | + if ($null -eq $Version) { |
| 61 | + $Version = '' |
| 62 | + } |
60 | 63 | $tempFolder = $null |
61 | 64 | try { |
62 | 65 | if (Test-Path -Path $Extension -PathType Leaf) { |
63 | | - if ($null -ne $Version -and $Version -ne '') { |
| 66 | + if ($Version -ne '') { |
64 | 67 | throw 'You can''t specify the -Version argument if you specify an existing file with the -Extension argument' |
65 | 68 | } |
66 | 69 | if ($null -ne $MinimumStability -and $MinimumStability -ne '') { |
|
85 | 88 | } |
86 | 89 | $peclPackageHandle = $foundPeclPackages[0] |
87 | 90 | $peclPackageVersions = @(Get-PeclPackageVersion -Handle $peclPackageHandle -Version $Version -MinimumStability $MinimumStability) |
88 | | - if ($peclPackageVersions.Count -eq 0) { |
89 | | - if ($null -eq $Version -or $Version -eq '') { |
90 | | - throw "The PECL package $peclPackageHandle does not have any version with a $MinimumStability minimum stability" |
91 | | - } |
92 | | - throw "The PECL package $peclPackageHandle does not have any $Version version with a $MinimumStability minimum stability" |
93 | | - } |
94 | 91 | $availablePackageVersion = $null |
95 | | - foreach ($peclPackageVersion in $peclPackageVersions) { |
96 | | - $archiveUrl = Get-PeclArchiveUrl -PackageHandle $peclPackageHandle -PackageVersion $peclPackageVersion -PhpVersion $phpVersion -MinimumStability $MinimumStability |
97 | | - if ($archiveUrl -eq '') { |
98 | | - Write-Verbose ("No Windows DLLs found for PECL package {0} {1} compatible with {2}" -f $peclPackageHandle, $peclPackageVersion, $phpVersion.DisplayName) |
| 92 | + $remoteFileIsZip = $true |
| 93 | + if ($peclPackageVersions.Count -eq 0) { |
| 94 | + if ($peclPackageHandle -eq 'xdebug' -and $MinimumStability -ne 'stable') { |
| 95 | + Write-Verbose 'Analyzing xdebug download page' |
| 96 | + $xdebugDownloadPageUrl = 'https://xdebug.org/download' |
| 97 | + $xdebugDownloadLinkRx = '^.*/php_xdebug-({0}(?:\.\d+)*){1}\d*-{2}-vc{3}{4}{5}\.dll$' -f @( |
| 98 | + @('\d+', [System.Text.RegularExpressions.Regex]::Escape($Version))[$Version -ne ''], |
| 99 | + @('(?:RC|alpha|beta)', '(?:RC|beta)')[$MinimumStability -eq 'beta'], |
| 100 | + [System.Text.RegularExpressions.Regex]::Escape($phpVersion.MajorMinorVersion), |
| 101 | + $phpVersion.VCVersion, |
| 102 | + @('-nts', '')[$phpVersion.ThreadSafe] |
| 103 | + @('', '-x86_64')[$phpVersion.Architecture -eq 'x64'] |
| 104 | + ) |
| 105 | + $webResponse = Invoke-WebRequest -UseBasicParsing -Uri $xdebugDownloadPageUrl |
| 106 | + foreach ($link in $webResponse.Links) { |
| 107 | + if ('Href' -in $link.PSobject.Properties.Name) { |
| 108 | + $linkUrl = [Uri]::new([Uri]$xdebugDownloadPageUrl, $link.Href).AbsoluteUri |
| 109 | + $linkUrlMatch = $linkUrl | Select-String -Pattern $xdebugDownloadLinkRx |
| 110 | + if ($null -ne $linkUrlMatch) { |
| 111 | + $availablePackageVersion = @{PackageVersion = $linkUrlMatch.Matches[0].Groups[1].Value; PackageArchiveUrl = $linkUrl } |
| 112 | + $remoteFileIsZip = $false |
| 113 | + break |
| 114 | + } |
| 115 | + } |
| 116 | + } |
99 | 117 | } |
100 | | - else { |
101 | | - $availablePackageVersion = @{PackageVersion = $peclPackageVersion; PackageArchiveUrl = $archiveUrl } |
102 | | - break |
| 118 | + if ($null -eq $availablePackageVersion) { |
| 119 | + if ($Version -eq '') { |
| 120 | + throw "The PECL package $peclPackageHandle does not have any version with a $MinimumStability minimum stability" |
| 121 | + } |
| 122 | + throw "The PECL package $peclPackageHandle does not have any $Version version with a $MinimumStability minimum stability" |
103 | 123 | } |
104 | 124 | } |
105 | 125 | if ($null -eq $availablePackageVersion) { |
106 | | - throw "No compatible Windows DLL found for PECL package $peclPackageHandle with a $MinimumStability minimum stability" |
| 126 | + foreach ($peclPackageVersion in $peclPackageVersions) { |
| 127 | + $archiveUrl = Get-PeclArchiveUrl -PackageHandle $peclPackageHandle -PackageVersion $peclPackageVersion -PhpVersion $phpVersion -MinimumStability $MinimumStability |
| 128 | + if ($archiveUrl -eq '') { |
| 129 | + Write-Verbose ("No Windows DLLs found for PECL package {0} {1} compatible with {2}" -f $peclPackageHandle, $peclPackageVersion, $phpVersion.DisplayName) |
| 130 | + } |
| 131 | + else { |
| 132 | + $availablePackageVersion = @{PackageVersion = $peclPackageVersion; PackageArchiveUrl = $archiveUrl } |
| 133 | + break |
| 134 | + } |
| 135 | + } |
| 136 | + if ($null -eq $availablePackageVersion) { |
| 137 | + throw "No compatible Windows DLL found for PECL package $peclPackageHandle with a $MinimumStability minimum stability" |
| 138 | + } |
107 | 139 | } |
108 | 140 | Write-Verbose ("Downloading PECL package {0} {1} from {2}" -f $peclPackageHandle, $availablePackageVersion.PackageVersion, $availablePackageVersion.PackageArchiveUrl) |
109 | | - $zip, $keepZip = Get-FileFromUrlOrCache -Url $availablePackageVersion.PackageArchiveUrl |
| 141 | + $downloadedFile, $keepDownloadedFile = Get-FileFromUrlOrCache -Url $availablePackageVersion.PackageArchiveUrl |
110 | 142 | try { |
111 | | - $tempFolder = New-TempDirectory |
112 | | - Expand-ArchiveWith7Zip -ArchivePath $zip -DestinationPath $tempFolder |
113 | | - $phpDlls = @(Get-ChildItem -Path $tempFolder\php_*.dll -File -Depth 0) |
114 | | - if ($phpDlls.Count -eq 0) { |
115 | | - $phpDlls = @(Get-ChildItem -Path $tempFolder\php_*.dll -File -Depth 1) |
116 | | - } |
117 | | - if ($phpDlls.Count -eq 0) { |
118 | | - throw ("No PHP DLL found in archive downloaded from {0}" -f $availablePackageVersion.PackageArchiveUrl) |
119 | | - } |
120 | | - if ($phpDlls.Count -ne 1) { |
121 | | - throw ("Multiple PHP DLL found in archive downloaded from {0}" -f $availablePackageVersion.PackageArchiveUrl) |
| 143 | + if ($remoteFileIsZip) { |
| 144 | + $tempFolder = New-TempDirectory |
| 145 | + Expand-ArchiveWith7Zip -ArchivePath $downloadedFile -DestinationPath $tempFolder |
| 146 | + $phpDlls = @(Get-ChildItem -Path $tempFolder\php_*.dll -File -Depth 0) |
| 147 | + if ($phpDlls.Count -eq 0) { |
| 148 | + $phpDlls = @(Get-ChildItem -Path $tempFolder\php_*.dll -File -Depth 1) |
| 149 | + } |
| 150 | + if ($phpDlls.Count -eq 0) { |
| 151 | + throw ("No PHP DLL found in archive downloaded from {0}" -f $availablePackageVersion.PackageArchiveUrl) |
| 152 | + } |
| 153 | + if ($phpDlls.Count -ne 1) { |
| 154 | + throw ("Multiple PHP DLL found in archive downloaded from {0}" -f $availablePackageVersion.PackageArchiveUrl) |
| 155 | + } |
| 156 | + $dllPath = $phpDlls[0].FullName |
| 157 | + } else { |
| 158 | + $keepDownloadedFile = $true |
| 159 | + $dllPath = $downloadedFile |
122 | 160 | } |
123 | | - $dllPath = $phpDlls[0].FullName |
| 161 | + $newExtension = Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath |
124 | 162 | } |
125 | 163 | catch { |
126 | | - $keepZip = $false |
| 164 | + $keepDownloadedFile = $false |
127 | 165 | throw |
128 | 166 | } |
129 | 167 | finally { |
130 | | - if (-Not($keepZip)) { |
| 168 | + if (-Not($keepDownloadedFile)) { |
131 | 169 | try { |
132 | | - Remove-Item -Path $zip -Force |
| 170 | + Remove-Item -Path $downloadedFile -Force |
133 | 171 | } |
134 | 172 | catch { |
135 | 173 | Write-Debug 'Failed to remove temporary zip file' |
136 | 174 | } |
137 | 175 | } |
138 | 176 | } |
139 | 177 | } |
140 | | - $newExtension = Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath |
141 | 178 | $oldExtension = Get-PhpExtension -Path $phpVersion.ExecutablePath | Where-Object { $_.Handle -eq $newExtension.Handle } |
142 | 179 | if ($null -ne $oldExtension) { |
143 | 180 | if ($oldExtension.Type -eq $Script:EXTENSIONTYPE_BUILTIN) { |
|
0 commit comments