2019-09-06 06:47:43 +07:00
|
|
|
param (
|
|
|
|
[Parameter(Mandatory=$true)][string]$version = "7.3"
|
|
|
|
)
|
|
|
|
|
2019-10-17 03:11:13 +07:00
|
|
|
$tick = ([char]8730)
|
|
|
|
$cross = ([char]10007)
|
|
|
|
|
|
|
|
Function Step-Log($message) {
|
|
|
|
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m" $message
|
|
|
|
}
|
|
|
|
|
|
|
|
Function Add-Log($mark, $subject, $message) {
|
|
|
|
$code = if($mark -eq $cross) {"31"} else {"32"}
|
|
|
|
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m" $code $mark $subject $message
|
|
|
|
}
|
|
|
|
|
2019-09-09 07:11:17 +07:00
|
|
|
if($version -eq '7.4') {
|
2019-09-17 22:10:27 +07:00
|
|
|
$version = '7.4RC'
|
2019-09-09 07:11:17 +07:00
|
|
|
}
|
2019-09-21 23:06:03 +07:00
|
|
|
|
2019-10-17 03:11:13 +07:00
|
|
|
Step-Log "Setup PhpManager"
|
2019-09-06 06:47:43 +07:00
|
|
|
Install-Module -Name PhpManager -Force -Scope CurrentUser
|
2019-10-17 03:11:13 +07:00
|
|
|
printf "\n"
|
|
|
|
Add-Log $tick "PhpManager" "Installed"
|
2019-09-17 22:10:27 +07:00
|
|
|
|
2019-09-21 23:06:03 +07:00
|
|
|
$installed = $($(php -v)[0] -join '')[4..6] -join ''
|
2019-10-17 03:11:13 +07:00
|
|
|
Step-Log "Setup PHP and Composer"
|
|
|
|
$status = "Switched to PHP$version"
|
2019-09-17 22:10:27 +07:00
|
|
|
if($installed -ne $version) {
|
|
|
|
if($version -lt '7.0') {
|
|
|
|
Install-Module -Name VcRedist -Force
|
|
|
|
}
|
2019-10-22 23:28:30 +07:00
|
|
|
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path C:\tools\php -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
|
2019-10-17 03:11:13 +07:00
|
|
|
$status = "Installed PHP$version"
|
2019-09-21 23:06:03 +07:00
|
|
|
}
|
|
|
|
|
2019-10-04 15:00:16 +07:00
|
|
|
$ext_dir = "C:\tools\php\ext"
|
2019-09-21 23:06:03 +07:00
|
|
|
Add-Content C:\tools\php\php.ini "date.timezone = 'UTC'"
|
2019-10-04 15:00:16 +07:00
|
|
|
Set-PhpIniKey extension_dir $ext_dir
|
2019-09-21 23:06:03 +07:00
|
|
|
if($version -lt '7.4') {
|
|
|
|
Enable-PhpExtension openssl
|
2019-10-23 00:26:27 +07:00
|
|
|
Enable-PhpExtension curl
|
2019-09-21 23:06:03 +07:00
|
|
|
} else {
|
2019-10-23 00:26:27 +07:00
|
|
|
Add-Content C:\tools\php\php.ini "extension=php_openssl.dll`nextension=php_curl.dll"
|
2019-10-04 15:00:16 +07:00
|
|
|
Copy-Item "php_pcov.dll" -Destination $ext_dir"\php_pcov.dll"
|
2019-09-09 07:11:17 +07:00
|
|
|
}
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $tick "PHP" $status
|
2019-09-17 22:10:27 +07:00
|
|
|
|
2019-09-07 19:31:50 +07:00
|
|
|
Install-Composer -Scope System -Path C:\tools\php
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $tick "Composer" "Installed"
|
2019-10-11 06:11:25 +07:00
|
|
|
|
2019-10-17 03:11:13 +07:00
|
|
|
Function Add-Extension($extension, $install_command, $prefix)
|
2019-10-11 06:11:25 +07:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$exist = Test-Path -Path C:\tools\php\ext\php_$extension.dll
|
|
|
|
if(!(php -m | findstr -i ${extension}) -and $exist) {
|
|
|
|
Add-Content C:\tools\php\php.ini "$prefix=php_$extension.dll"
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $tick $extension "Enabled"
|
2019-10-11 06:11:25 +07:00
|
|
|
} elseif(php -m | findstr -i $extension) {
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $tick $extension "Enabled"
|
2019-10-11 06:11:25 +07:00
|
|
|
}
|
|
|
|
} catch [Exception] {
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $cross $extension "Could not enable"
|
2019-10-11 06:11:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
$status = 404
|
|
|
|
try {
|
|
|
|
$status = (Invoke-WebRequest -Uri "https://pecl.php.net/json.php?package=$extension" -UseBasicParsing -DisableKeepAlive).StatusCode
|
|
|
|
} catch [Exception] {
|
|
|
|
$status = 500
|
|
|
|
}
|
|
|
|
|
|
|
|
if($status -eq 200) {
|
|
|
|
if(!(php -m | findstr -i $extension)) {
|
|
|
|
try {
|
|
|
|
Invoke-Expression $install_command
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $tick $extension "Installed and enabled"
|
2019-10-11 06:11:25 +07:00
|
|
|
} catch [Exception] {
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $cross $extension "Could not install on PHP$version"
|
2019-10-11 06:11:25 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(!(php -m | findstr -i $extension)) {
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $cross $extension "Could not find $extension for PHP$version on PECL"
|
2019-10-11 06:11:25 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|