|
16 | 16 | .Parameter Scope
|
17 | 17 | Install Composer the current user only ('User' - default), or at system-level ('System').
|
18 | 18 |
|
| 19 | + .Parameter Version |
| 20 | + Specify this option to install a specific Composer version. It can be a full version (eg 1.10.16) or a major version (eg 1) |
| 21 | +
|
19 | 22 | .Parameter NoAddToPath
|
20 | 23 | Specify this option to don't add the Composer install path to the PATH environment variable.
|
21 | 24 |
|
|
31 | 34 | [Parameter(Mandatory = $false, Position = 2, HelpMessage = 'Install for current user of for any user')]
|
32 | 35 | [ValidateSet('User', 'System')]
|
33 | 36 | [string] $Scope,
|
| 37 | + [Parameter(Mandatory = $false, Position = 3, HelpMessage = 'Composer version to be installed')] |
| 38 | + [ValidatePattern('^\d+(\.\d+\.\d+(\-(alpha|beta|RC)\d*)*)?$')] |
| 39 | + [string] $Version, |
34 | 40 | [switch] $NoAddToPath,
|
35 | 41 | [switch] $NoCache
|
36 | 42 | )
|
|
60 | 66 | $installerUrl = 'https://getcomposer.org/installer';
|
61 | 67 | $installer = ''
|
62 | 68 | $tempPhar = ''
|
| 69 | + $actualPharUrl = '' |
63 | 70 | $pathCreatedHere = $false
|
64 | 71 | try {
|
65 | 72 | if ($NoCache) {
|
|
75 | 82 | $arguments += $installer
|
76 | 83 | $arguments += '--install-dir=' + (Split-Path -Path $tempPhar -Parent)
|
77 | 84 | $arguments += '--filename=' + (Split-Path -Path $tempPhar -Leaf)
|
| 85 | + if ($Version -ne '') { |
| 86 | + if ($Version -match '\.') { |
| 87 | + $arguments += '--version=' + $Version |
| 88 | + } else { |
| 89 | + $actualPharUrl = "https://getcomposer.org/composer-$Version.phar" |
| 90 | + switch ($Version) { |
| 91 | + '1' { |
| 92 | + $testVersion = '1.10.16' |
| 93 | + } |
| 94 | + '2' { |
| 95 | + $testVersion = '2.0.1' |
| 96 | + } |
| 97 | + default { |
| 98 | + $testVersion = "$Version.0.1" |
| 99 | + } |
| 100 | + } |
| 101 | + $arguments += "--version=$testVersion" |
| 102 | + $arguments += '--check' |
| 103 | + } |
| 104 | + } |
78 | 105 | $arguments += '2>&1'
|
79 | 106 | Write-Verbose "Launching Composer installer"
|
80 | 107 | $installerResult = & $phpVersion.ExecutablePath $arguments
|
81 | 108 | if ($LASTEXITCODE -ne 0) {
|
82 | 109 | throw $installerResult
|
83 | 110 | }
|
84 |
| - Write-Verbose "Composer succeeded" |
| 111 | + Write-Verbose "Composer installed succeeded" |
| 112 | + if ($actualPharUrl -ne '') { |
| 113 | + Write-Verbose "Downloading Composer" |
| 114 | + Set-NetSecurityProtocolType |
| 115 | + Write-Verbose "Downloading from $actualPharUrl" |
| 116 | + Invoke-WebRequest -UseBasicParsing -Uri $actualPharUrl -OutFile $tempPhar |
| 117 | + } |
85 | 118 | Write-Verbose "Installing to $Path"
|
86 | 119 | If (-Not(Test-Path -LiteralPath $Path)) {
|
87 | 120 | New-Item -ItemType Directory -Path $Path | Out-Null
|
|
108 | 141 | Set-Content -Path $destBat -Value $lines
|
109 | 142 | if (-not($NoAddToPath)) {
|
110 | 143 | Write-Verbose 'Adding to PATH'
|
| 144 | + if (-not($Scope)) { |
| 145 | + $Scope = 'User' |
| 146 | + } |
111 | 147 | Edit-FolderInPath -Operation Add -Path $Path -Persist $Scope -CurrentProcess
|
112 | 148 | }
|
113 | 149 | } catch {
|
|
0 commit comments