2019-09-06 06:47:43 +07:00
|
|
|
param (
|
2019-12-18 23:14:02 +07:00
|
|
|
[Parameter(Mandatory = $true)][string]$version = "7.4",
|
|
|
|
[Parameter(Mandatory=$true)][string]$dir
|
2019-09-06 06:47:43 +07:00
|
|
|
)
|
|
|
|
|
2019-10-17 03:11:13 +07:00
|
|
|
$tick = ([char]8730)
|
|
|
|
$cross = ([char]10007)
|
2019-11-25 17:53:13 +07:00
|
|
|
$php_dir = 'C:\tools\php'
|
2019-12-18 23:14:02 +07:00
|
|
|
$ext_dir = $php_dir + '\ext'
|
2019-12-18 20:22:46 +07:00
|
|
|
$ProgressPreference = 'SilentlyContinue'
|
2019-12-18 23:14:02 +07:00
|
|
|
$master_version = '8.0'
|
2019-12-24 00:49:38 +07:00
|
|
|
$arch='x64'
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
Add-Log $tick "PhpManager" "Installed"
|
2019-09-17 22:10:27 +07:00
|
|
|
|
2019-11-25 17:53:13 +07:00
|
|
|
$installed = $null
|
|
|
|
if (Test-Path -LiteralPath $php_dir -PathType Container) {
|
|
|
|
try {
|
|
|
|
$installed = Get-Php -Path $php_dir
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
}
|
|
|
|
}
|
2019-10-17 03:11:13 +07:00
|
|
|
Step-Log "Setup PHP and Composer"
|
2019-11-25 17:53:13 +07:00
|
|
|
if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) {
|
|
|
|
if ($version -lt '7.0') {
|
2019-09-17 22:10:27 +07:00
|
|
|
Install-Module -Name VcRedist -Force
|
2019-12-18 19:20:25 +07:00
|
|
|
$arch='x86'
|
2019-09-17 22:10:27 +07:00
|
|
|
}
|
2019-12-18 23:14:02 +07:00
|
|
|
if ($version -eq $master_version) {
|
|
|
|
$version = 'master'
|
|
|
|
}
|
2019-11-28 07:40:27 +07:00
|
|
|
|
2019-12-18 19:20:25 +07:00
|
|
|
Install-Php -Version $version -Architecture $arch -ThreadSafe $true -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
|
2019-11-25 17:53:13 +07:00
|
|
|
$installed = Get-Php -Path $php_dir
|
|
|
|
$status = "Installed PHP $($installed.FullVersion)"
|
|
|
|
}
|
|
|
|
else {
|
2019-11-30 07:28:14 +07:00
|
|
|
$status = "PHP $($installed.FullVersion) Found"
|
2019-09-21 23:06:03 +07:00
|
|
|
}
|
|
|
|
|
2019-11-25 17:53:13 +07:00
|
|
|
Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir
|
2019-12-18 23:14:02 +07:00
|
|
|
Enable-PhpExtension -Extension openssl, curl, opcache -Path $php_dir
|
2019-11-29 12:22:07 +07:00
|
|
|
Update-PhpCAInfo -Path $php_dir -Source CurrentUser
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $tick "PHP" $status
|
2019-09-17 22:10:27 +07:00
|
|
|
|
2019-11-25 17:53:13 +07:00
|
|
|
Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
|
2019-10-17 03:11:13 +07:00
|
|
|
Add-Log $tick "Composer" "Installed"
|
2019-12-18 23:14:02 +07:00
|
|
|
if ($version -eq 'master') {
|
|
|
|
Copy-Item $dir"\..\src\ext\php_pcov.dll" -Destination $ext_dir"\php_pcov.dll"
|
|
|
|
Set-PhpIniKey -Key 'opcache.jit_buffer_size' -Value '256M' -Path $php_dir
|
|
|
|
Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir
|
|
|
|
}
|
2019-10-11 06:11:25 +07:00
|
|
|
|
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 }
|
|
|
|
if ($null -ne $extension_info) {
|
|
|
|
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
|
2019-11-25 23:25:52 +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
|
|
|
|
|
|
|
Function Add-Phalcon {
|
|
|
|
Param (
|
|
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateSet('phalcon3', 'phalcon4')]
|
|
|
|
[string]
|
|
|
|
$extension
|
|
|
|
)
|
|
|
|
$extension_version = $extension.substring($extension.Length - 1)
|
|
|
|
$nts = if(! $installed.ThreadSafe ) { "_nts" } else { "" }
|
|
|
|
$domain = "https://github.com"
|
|
|
|
Install-Phpextension psr
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`""
|
|
|
|
$zip_file = $match.Matches[0].Groups[1].Value
|
|
|
|
Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $PSScriptRoot\phalcon.zip
|
|
|
|
Expand-Archive -Path $PSScriptRoot\phalcon.zip -DestinationPath $PSScriptRoot\phalcon -Force > $null 2>&1
|
|
|
|
New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $PSScriptRoot\phalcon\php_phalcon.dll > $null 2>&1
|
|
|
|
Enable-PhpExtension -Extension phalcon -Path $php_dir
|
|
|
|
Add-Log $tick $extension "Installed and enabled"
|
|
|
|
} catch {
|
|
|
|
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
|
|
|
|
}
|
|
|
|
}
|