Skip to content

Commit

Permalink
Fix Add-Phalcon to support nts PHP versions #128
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Dec 24, 2019
1 parent cb28730 commit a5d53f0
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/scripts/win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $php_dir = 'C:\tools\php'
$ext_dir = $php_dir + '\ext'
$ProgressPreference = 'SilentlyContinue'
$master_version = '8.0'
$arch='x64'

Function Step-Log($message) {
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
Expand All @@ -33,7 +34,6 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) {
}
Step-Log "Setup PHP and Composer"
if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) {
$arch='x64'
if ($version -lt '7.0') {
Install-Module -Name VcRedist -Force
$arch='x86'
Expand Down Expand Up @@ -63,27 +63,6 @@ if ($version -eq 'master') {
Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir
}

Function Add-Phalcon {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateSet('phalcon3', 'phalcon4')]
[string]
$extension
)
Install-Phpextension psr
$extension_version = $extension.substring($extension.Length - 1)
$domain_uri = "https://github.com"
$uri = Invoke-WebRequest -UseBasicParsing -Uri $domain_uri/phalcon/cphalcon/releases | `
Select-String -Pattern "href=`"(.*phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9].zip)`"" | `
ForEach-Object { $_.matches.groups[1].value } | `
Select-Object -Index 0
Invoke-WebRequest -UseBasicParsing -Uri $domain_uri/$uri -OutFile $ENV:TEMP\phalcon.zip
Expand-Archive -Path $ENV:TEMP\phalcon.zip -DestinationPath $ENV:TEMP\phalcon -Force
Copy-Item -Path $ENV:TEMP\phalcon\php_phalcon.dll -Destination $ext_dir
Enable-Phpextension phalcon
}

Function Add-Extension {
Param (
[Parameter(Position = 0, Mandatory = $true)]
Expand Down Expand Up @@ -122,3 +101,28 @@ Function Add-Extension {
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
}

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
Add-Extension $extension.substring(0, $extension.Length - 1)
} catch {
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
}

0 comments on commit a5d53f0

Please sign in to comment.