2019-09-06 06:47:43 +07:00
|
|
|
param (
|
2019-12-26 20:01:18 +07:00
|
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
|
|
|
[string]
|
|
|
|
$version = '7.4',
|
|
|
|
[Parameter(Position = 1, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
|
|
|
[string]
|
|
|
|
$dir
|
2019-09-06 06:47:43 +07:00
|
|
|
)
|
|
|
|
|
2019-10-17 03:11:13 +07:00
|
|
|
Function Step-Log($message) {
|
2019-10-23 16:57:40 +07:00
|
|
|
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
|
2019-10-17 03:11:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
Function Add-Log($mark, $subject, $message) {
|
2019-11-25 17:53:13 +07:00
|
|
|
$code = if ($mark -eq $cross) { "31" } else { "32" }
|
2019-10-23 16:57:40 +07:00
|
|
|
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $code $mark $subject $message
|
2019-10-17 03:11:13 +07:00
|
|
|
}
|
|
|
|
|
2020-03-16 12:48:01 +07:00
|
|
|
Function Install-PhpManager() {
|
|
|
|
$repo = "mlocati/powershell-phpmanager"
|
|
|
|
$zip_file = "$php_dir\PhpManager.zip"
|
|
|
|
$tags = Invoke-WebRequest https://api.github.com/repos/$repo/tags | ConvertFrom-Json
|
|
|
|
$tag = $tags[0].Name
|
|
|
|
$module_path = "$php_dir\PhpManager\powershell-phpmanager-$tag\PhpManager"
|
|
|
|
Invoke-WebRequest -UseBasicParsing -Uri https://github.com/$repo/archive/$tag.zip -OutFile $zip_file
|
|
|
|
Expand-Archive -Path $zip_file -DestinationPath $php_dir\PhpManager
|
|
|
|
Import-Module $module_path
|
|
|
|
Add-Content -Path $PsHome\profile.ps1 -Value "Import-Module $module_path"
|
|
|
|
}
|
|
|
|
|
2019-11-25 22:35:11 +07:00
|
|
|
Function Add-Extension {
|
|
|
|
Param (
|
|
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
|
|
|
[string]
|
|
|
|
$extension,
|
|
|
|
[Parameter(Position = 1, Mandatory = $false)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
|
|
|
|
[string]
|
|
|
|
$mininum_stability = 'stable'
|
|
|
|
)
|
2019-10-11 06:11:25 +07:00
|
|
|
try {
|
2019-11-25 17:53:13 +07:00
|
|
|
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
|
2020-01-30 13:33:30 +07:00
|
|
|
if ($null -ne $extension_info) {
|
2019-11-25 17:53:13 +07:00
|
|
|
switch ($extension_info.State) {
|
|
|
|
'Builtin' {
|
|
|
|
Add-Log $tick $extension "Enabled"
|
|
|
|
}
|
|
|
|
'Enabled' {
|
|
|
|
Add-Log $tick $extension "Enabled"
|
|
|
|
}
|
|
|
|
default {
|
|
|
|
Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
|
|
|
|
Add-Log $tick $extension "Enabled"
|
|
|
|
}
|
2019-10-11 06:11:25 +07:00
|
|
|
}
|
|
|
|
}
|
2019-11-25 17:53:13 +07:00
|
|
|
else {
|
2019-11-25 20:03:28 +07:00
|
|
|
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir
|
2020-01-30 13:33:30 +07:00
|
|
|
Add-Log $tick $extension "Installed and enabled"
|
2019-10-11 06:11:25 +07:00
|
|
|
}
|
|
|
|
}
|
2019-11-25 17:53:13 +07:00
|
|
|
catch {
|
2019-12-09 09:39:03 +07:00
|
|
|
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
|
2019-11-25 17:53:13 +07:00
|
|
|
}
|
|
|
|
}
|
2019-12-24 00:49:38 +07:00
|
|
|
|
2019-12-26 20:01:18 +07:00
|
|
|
Function Remove-Extension() {
|
2019-12-24 00:49:38 +07:00
|
|
|
Param (
|
|
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
2019-12-26 20:01:18 +07:00
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
2019-12-24 00:49:38 +07:00
|
|
|
[string]
|
|
|
|
$extension
|
|
|
|
)
|
2019-12-26 20:01:18 +07:00
|
|
|
if(php -m | findstr -i $extension) {
|
|
|
|
Disable-PhpExtension $extension $php_dir
|
|
|
|
}
|
|
|
|
if (Test-Path $ext_dir\php_$extension.dll) {
|
|
|
|
Remove-Item $ext_dir\php_$extension.dll
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-27 08:26:49 +07:00
|
|
|
Function Add-Tool() {
|
|
|
|
Param (
|
|
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
|
|
|
[string]
|
|
|
|
$url,
|
|
|
|
[Parameter(Position = 1, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
|
|
|
[string]
|
|
|
|
$tool
|
|
|
|
)
|
2020-01-26 12:41:36 +07:00
|
|
|
if (Test-Path $php_dir\$tool) {
|
|
|
|
Remove-Item $php_dir\$tool
|
|
|
|
}
|
|
|
|
if ($tool -eq "composer") {
|
2019-12-28 02:12:00 +07:00
|
|
|
Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
|
2020-01-14 13:36:52 +07:00
|
|
|
composer -q global config process-timeout 0
|
2020-01-26 12:41:36 +07:00
|
|
|
} elseif ($tool -eq "symfony") {
|
|
|
|
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool.exe
|
|
|
|
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.exe" > $null 2>&1
|
2019-12-28 02:12:00 +07:00
|
|
|
} else {
|
2020-01-07 09:36:14 +07:00
|
|
|
try {
|
|
|
|
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool
|
|
|
|
$bat_content = @()
|
|
|
|
$bat_content += "@ECHO off"
|
|
|
|
$bat_content += "setlocal DISABLEDELAYEDEXPANSION"
|
|
|
|
$bat_content += "SET BIN_TARGET=%~dp0/" + $tool
|
|
|
|
$bat_content += "php %BIN_TARGET% %*"
|
|
|
|
Set-Content -Path $php_dir\$tool.bat -Value $bat_content
|
|
|
|
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat" > $null 2>&1
|
2020-01-26 12:41:36 +07:00
|
|
|
} catch { }
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
2020-01-21 03:10:24 +07:00
|
|
|
if($tool -eq "phive") {
|
|
|
|
Add-Extension curl >$null 2>&1
|
|
|
|
Add-Extension mbstring >$null 2>&1
|
|
|
|
Add-Extension xml >$null 2>&1
|
|
|
|
}
|
2020-02-03 01:21:44 +07:00
|
|
|
if($tool -eq "cs2pr") {
|
|
|
|
(Get-Content $php_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $php_dir/cs2pr
|
|
|
|
}
|
2020-01-26 18:51:04 +07:00
|
|
|
if (((Get-ChildItem -Path $php_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
|
2020-01-26 12:41:36 +07:00
|
|
|
Add-Log $tick $tool "Added"
|
|
|
|
} else {
|
|
|
|
Add-Log $cross $tool "Could not add $tool"
|
|
|
|
}
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
|
|
|
|
2020-03-01 07:50:48 +07:00
|
|
|
Function Add-Composertool() {
|
2020-01-07 09:36:14 +07:00
|
|
|
Param (
|
|
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
|
|
|
[string]
|
|
|
|
$tool,
|
|
|
|
[Parameter(Position = 1, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
|
|
|
[string]
|
|
|
|
$release,
|
|
|
|
[Parameter(Position = 2, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
|
|
|
[string]
|
|
|
|
$prefix
|
|
|
|
)
|
|
|
|
composer -q global require $prefix$release 2>&1 | out-null
|
|
|
|
if($?) {
|
|
|
|
$composer_dir = composer -q global config home | ForEach-Object { $_ -replace "/", "\" }
|
|
|
|
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $composer_dir\vendor\bin\$tool.bat"
|
|
|
|
Add-Log $tick $tool "Added"
|
|
|
|
} else {
|
|
|
|
Add-Log $cross $tool "Could not setup $tool"
|
2019-12-27 08:26:49 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-01 07:50:48 +07:00
|
|
|
Function Add-Pecl() {
|
2020-01-26 02:34:09 +07:00
|
|
|
Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows"
|
2019-12-27 08:26:49 +07:00
|
|
|
}
|
|
|
|
|
2019-12-26 20:01:18 +07:00
|
|
|
# Variables
|
|
|
|
$tick = ([char]8730)
|
|
|
|
$cross = ([char]10007)
|
|
|
|
$php_dir = 'C:\tools\php'
|
2020-05-13 22:29:26 +07:00
|
|
|
$ext_dir = "$php_dir\ext"
|
2019-12-26 20:01:18 +07:00
|
|
|
$ProgressPreference = 'SilentlyContinue'
|
|
|
|
$master_version = '8.0'
|
2020-01-20 23:20:44 +07:00
|
|
|
$arch = 'x64'
|
2020-05-13 22:29:26 +07:00
|
|
|
$ts = $env:PHPTS -eq 'ts'
|
|
|
|
if($env:PHPTS -ne 'ts') {
|
|
|
|
$env:PHPTS = 'nts'
|
2020-01-20 23:20:44 +07:00
|
|
|
}
|
2019-12-26 20:01:18 +07:00
|
|
|
|
|
|
|
Step-Log "Setup PhpManager"
|
2020-03-16 12:48:01 +07:00
|
|
|
Install-PhpManager >$null 2>&1
|
2019-12-26 20:01:18 +07:00
|
|
|
Add-Log $tick "PhpManager" "Installed"
|
|
|
|
|
2020-05-13 22:29:26 +07:00
|
|
|
Step-Log "Setup PHP"
|
2019-12-26 20:01:18 +07:00
|
|
|
$installed = $null
|
|
|
|
if (Test-Path -LiteralPath $php_dir -PathType Container) {
|
|
|
|
try {
|
|
|
|
$installed = Get-Php -Path $php_dir
|
2020-05-13 22:29:26 +07:00
|
|
|
} catch { }
|
2019-12-24 00:49:38 +07:00
|
|
|
}
|
2020-01-16 11:46:44 +07:00
|
|
|
$status = "Installed"
|
2020-01-20 23:20:44 +07:00
|
|
|
if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.'))) -or $ts -ne $installed.ThreadSafe) {
|
2019-12-26 20:01:18 +07:00
|
|
|
if ($version -lt '7.0') {
|
|
|
|
Install-Module -Name VcRedist -Force
|
|
|
|
$arch='x86'
|
|
|
|
}
|
|
|
|
if ($version -eq $master_version) {
|
|
|
|
$version = 'master'
|
|
|
|
}
|
|
|
|
|
2020-01-20 23:20:44 +07:00
|
|
|
Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
|
2020-01-16 11:46:44 +07:00
|
|
|
} else {
|
2020-03-01 07:50:48 +07:00
|
|
|
$status = "Found"
|
2019-12-26 20:01:18 +07:00
|
|
|
}
|
|
|
|
|
2019-12-29 01:59:28 +07:00
|
|
|
$installed = Get-Php -Path $php_dir
|
2019-12-26 20:01:18 +07:00
|
|
|
Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir
|
2020-05-13 22:29:26 +07:00
|
|
|
Enable-PhpExtension -Extension openssl, curl, opcache, mbstring -Path $php_dir
|
2019-12-26 20:01:18 +07:00
|
|
|
Update-PhpCAInfo -Path $php_dir -Source CurrentUser
|
|
|
|
if ($version -eq 'master') {
|
2020-05-13 22:29:26 +07:00
|
|
|
Copy-Item $dir"\..\src\bin\php_$env:PHPTS`_pcov.dll" -Destination $ext_dir"\php_pcov.dll"
|
2019-12-26 20:01:18 +07:00
|
|
|
Set-PhpIniKey -Key 'opcache.jit_buffer_size' -Value '256M' -Path $php_dir
|
|
|
|
Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir
|
|
|
|
}
|
2020-01-16 11:46:44 +07:00
|
|
|
Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)"
|