-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathGet-PhpVersionFromUrl.ps1
More file actions
78 lines (74 loc) · 2.82 KB
/
Get-PhpVersionFromUrl.ps1
File metadata and controls
78 lines (74 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function Get-PhpVersionFromUrl
{
<#
.Synopsis
Gets an instance of PhpVersion by parsing its download URL.
.Parameter Url
The PHP download URL (eventually relative to PageUrl).
.Parameter ReleaseState
One of the $Script:RELEASESTATE_... constants.
.Parameter PageUrl
The URL of the page where the download link has been retrieved from.
.Outputs
PhpVersionDownloadable
#>
[OutputType([psobject])]
param (
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]$Url,
[Parameter(Mandatory = $true, Position = 1)]
[ValidateNotNull()]
[ValidateSet('QA', 'Release', 'Archive', 'Snapshot')]
[string] $ReleaseState,
[Parameter(Mandatory = $false, Position = 2)]
[string]$PageUrl
)
begin {
$result = $null
}
process {
$data = @{}
$match = $Url | Select-String -CaseSensitive -Pattern ('(^|/)' + $Script:RX_ZIPARCHIVE + '$')
if ($null -ne $match) {
$groups = $match.Matches[0].Groups
$data.Version = $groups['version'].Value
$data.UnstabilityLevel = $groups['unstabilityLevel'].Value
$data.UnstabilityVersion = $groups['unstabilityVersion'].Value
$data.ThreadSafe = $groups['threadSafe'].Value -ne '-nts'
$data.VCVersion = $groups['vcVersion'].Value
$data.Architecture = $groups['architecture'].Value
} else {
$match = $Url | Select-String -CaseSensitive -Pattern ('(^|/)' + $Script:RX_ZIPARCHIVE_SNAPSHOT + '$')
if ($null -eq $match) {
$match = $Url | Select-String -CaseSensitive -Pattern ('(^|/)' + $Script:RX_ZIPARCHIVE_SNAPSHOT_SHIVAMMATHUR + '$')
}
if ($null -ne $match) {
$groups = $match.Matches[0].Groups
if ($groups['version'].Value -eq '') {
$data.Version = 'master'
} else {
$data.Version = $groups['version'].Value
}
$data.UnstabilityLevel = $Script:UNSTABLEPHP_SNAPSHOT
$data.UnstabilityVersion = $null
$data.ThreadSafe = $groups['threadSafe'].Value -ne 'nts'
$data.VCVersion = $groups['vcVersion'].Value
$data.Architecture = $groups['architecture'].Value
} else {
throw "Unrecognized PHP ZIP archive url: $Url"
}
}
$data.ReleaseState = $ReleaseState
if ($null -ne $PageUrl -and $PageUrl -ne '') {
$data.DownloadUrl = [Uri]::new([Uri]$PageUrl, $Url).AbsoluteUri
} else {
$data.DownloadUrl = $Url
}
$result = [PhpVersionDownloadable]::new($data)
}
end {
$result
}
}