|
| 1 | +function Get-PhpDepsPackages { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Get PHP dependency packages, applying configured library overrides when required. |
| 5 | + .PARAMETER PhpVersion |
| 6 | + PHP version (e.g., 8.4.18, 8.4, or master). |
| 7 | + .PARAMETER VsVersion |
| 8 | + Visual Studio toolset version (e.g., vs16, vs17). |
| 9 | + .PARAMETER Arch |
| 10 | + Target architecture: x86 or x64. |
| 11 | + #> |
| 12 | + [CmdletBinding()] |
| 13 | + [OutputType([PSCustomObject])] |
| 14 | + param( |
| 15 | + [Parameter(Mandatory=$true)] |
| 16 | + [ValidateNotNullOrEmpty()] |
| 17 | + [string] $PhpVersion, |
| 18 | + [Parameter(Mandatory=$true)] |
| 19 | + [ValidateNotNullOrEmpty()] |
| 20 | + [string] $VsVersion, |
| 21 | + [Parameter(Mandatory=$true)] |
| 22 | + [ValidateSet('x86','x64')] |
| 23 | + [string] $Arch |
| 24 | + ) |
| 25 | + |
| 26 | + begin { |
| 27 | + $baseurl = 'https://downloads.php.net/~windows/php-sdk/deps' |
| 28 | + $configPath = Join-Path $PSScriptRoot '..\config\deps-overrides.json' |
| 29 | + } |
| 30 | + |
| 31 | + process { |
| 32 | + $depsPhpVersion = $PhpVersion |
| 33 | + if ($PhpVersion -ne 'master') { |
| 34 | + $versionParts = $PhpVersion.Split('.') |
| 35 | + if ($versionParts.Count -ge 2) { |
| 36 | + $depsPhpVersion = $versionParts[0..1] -join '.' |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + $seriesUrl = "$baseurl/series/packages-$depsPhpVersion-$VsVersion-$Arch-staging.txt" |
| 41 | + Write-Host "Fetching series listing: $seriesUrl" |
| 42 | + $series = Invoke-WebRequest -Uri $seriesUrl -UseBasicParsing -ErrorAction Stop |
| 43 | + $packages = @() |
| 44 | + if ($series -and $series.Content) { |
| 45 | + $packages = $series.Content -split "[\r\n]+" | Where-Object { $_ -and $_.Trim().Length -gt 0 } |
| 46 | + } |
| 47 | + |
| 48 | + $overrideLibraries = @() |
| 49 | + if ((Test-Path -LiteralPath $configPath) -and $PhpVersion -match '^\d+\.\d+\.\d+$') { |
| 50 | + $config = Get-Content -LiteralPath $configPath -Raw | ConvertFrom-Json |
| 51 | + $seriesConfigProperty = $config.PSObject.Properties[$depsPhpVersion] |
| 52 | + if ($null -ne $seriesConfigProperty) { |
| 53 | + $seriesConfig = $seriesConfigProperty.Value |
| 54 | + if ([version]$PhpVersion -le [version]$seriesConfig.maxVersion) { |
| 55 | + foreach ($libraryProperty in $seriesConfig.libraries.PSObject.Properties) { |
| 56 | + $libraryName = $libraryProperty.Name |
| 57 | + $overrideConfig = $libraryProperty.Value |
| 58 | + $package = $null |
| 59 | + if ($overrideConfig -is [string]) { |
| 60 | + $package = "$libraryName-$overrideConfig-$VsVersion-$Arch.zip" |
| 61 | + } elseif ($overrideConfig.PSObject.Properties.Name -contains 'package') { |
| 62 | + $package = $overrideConfig.package |
| 63 | + } elseif ($overrideConfig.PSObject.Properties.Name -contains 'version') { |
| 64 | + $package = "$libraryName-$($overrideConfig.version)-$VsVersion-$Arch.zip" |
| 65 | + } |
| 66 | + |
| 67 | + if ([string]::IsNullOrWhiteSpace($package)) { |
| 68 | + continue |
| 69 | + } |
| 70 | + |
| 71 | + $overrideLibraries += $libraryName |
| 72 | + $packagePattern = '^' + [regex]::Escape($libraryName) + '-\d' |
| 73 | + $packages = $packages | ForEach-Object { |
| 74 | + if ($_ -match $packagePattern) { |
| 75 | + $package |
| 76 | + } else { |
| 77 | + $_ |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + if (-not ($packages -contains $package)) { |
| 82 | + $packages += $package |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + return [PSCustomObject]@{ |
| 90 | + Packages = @($packages) |
| 91 | + OverrideLibraries = @($overrideLibraries | Select-Object -Unique) |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments