Skip to content

Commit aa98c1b

Browse files
committed
Download pre-release xdebug versions from xdebug.org
1 parent 8fd7808 commit aa98c1b

File tree

1 file changed

+69
-32
lines changed

1 file changed

+69
-32
lines changed

PhpManager/public/Install-PhpExtension.ps1

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@
5757
if (-Not(Test-Path -LiteralPath $phpVersion.ExtensionsPath -PathType Container)) {
5858
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."
5959
}
60+
if ($null -eq $Version) {
61+
$Version = ''
62+
}
6063
$tempFolder = $null
6164
try {
6265
if (Test-Path -Path $Extension -PathType Leaf) {
63-
if ($null -ne $Version -and $Version -ne '') {
66+
if ($Version -ne '') {
6467
throw 'You can''t specify the -Version argument if you specify an existing file with the -Extension argument'
6568
}
6669
if ($null -ne $MinimumStability -and $MinimumStability -ne '') {
@@ -85,59 +88,93 @@
8588
}
8689
$peclPackageHandle = $foundPeclPackages[0]
8790
$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-
}
9491
$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+
}
99117
}
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"
103123
}
104124
}
105125
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+
}
107139
}
108140
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
110142
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
122160
}
123-
$dllPath = $phpDlls[0].FullName
161+
$newExtension = Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
124162
}
125163
catch {
126-
$keepZip = $false
164+
$keepDownloadedFile = $false
127165
throw
128166
}
129167
finally {
130-
if (-Not($keepZip)) {
168+
if (-Not($keepDownloadedFile)) {
131169
try {
132-
Remove-Item -Path $zip -Force
170+
Remove-Item -Path $downloadedFile -Force
133171
}
134172
catch {
135173
Write-Debug 'Failed to remove temporary zip file'
136174
}
137175
}
138176
}
139177
}
140-
$newExtension = Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
141178
$oldExtension = Get-PhpExtension -Path $phpVersion.ExecutablePath | Where-Object { $_.Handle -eq $newExtension.Handle }
142179
if ($null -ne $oldExtension) {
143180
if ($oldExtension.Type -eq $Script:EXTENSIONTYPE_BUILTIN) {

0 commit comments

Comments
 (0)