Skip to content

Commit

Permalink
Improve phalcon support
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Oct 24, 2022
1 parent 89f4f7e commit cae6d06
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
32 changes: 22 additions & 10 deletions src/scripts/extensions/phalcon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,45 @@ Function Add-PhalconFromGitHub() {
[string]
$Semver
)
$domain = 'https://github.com'
$domain = 'https://api.github.com/repos'
$nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
$match = Invoke-WebRequest -Uri "$domain/phalcon/cphalcon/releases/v$Semver" | Select-String -Pattern "href=`"(.*phalcon_x64_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`""
$match = $match = (Invoke-RestMethod -Uri "$domain/phalcon/cphalcon/releases/tags/v$Semver").assets | Select-String -Pattern "browser_download_url=(.*phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)"
if($NULL -eq $match) {
$nts = if (!$installed.ThreadSafe) { "-nts" } else { "-ts" }
$match = Invoke-WebRequest -Uri "$domain/phalcon/cphalcon/releases/v$Semver" | Select-String -Pattern "href=`"(.*phalcon-php${version}${nts}-windows.*-x64.zip)`""
$match = (Invoke-RestMethod -Uri "$domain/phalcon/cphalcon/releases/tags/v$Semver").assets | Select-String -Pattern "browser_download_url=(.*phalcon-php${version}${nts}-windows.*-x64.zip)"
}
if($NULL -ne $match) {
$zip_file = $match.Matches[0].Groups[1].Value
Invoke-WebRequest -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1
$zip_url = $match.Matches[0].Groups[1].Value
Invoke-WebRequest -Uri $zip_url -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1
Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force > $null 2>&1
Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll" -Destination "$ext_dir\php_phalcon.dll"
Enable-PhpExtension -Extension phalcon -Path $php_dir
} else {
throw "Unable to get Phalcon release from the GitHub release"
}
}

# Function to get phalcon semver.
Function Get-PhalconSemver() {
if($extension_version -eq '3') {
return '3.4.5'
} elseif (($extension_version -eq '4') -and ($version -eq '7.2')) {
return '4.1.0'
}
return Get-PeclPackageVersion phalcon $extension_version stable stable | Select-Object -First 1
}

# Function to install phalcon
Function Add-PhalconHelper() {
if (($extension_version -eq '4') -or ($extension_version -eq '5')) {
$extension_semver=Get-PeclPackageVersion phalcon $extension_version stable stable | Select-Object -First 1
Add-Extension -Extension phalcon -Stability stable -Extension_version $extension_semver
} elseif ($extension_version -eq '3') {
Add-PhalconFromGitHub -Semver 3.4.5
$semver = Get-PhalconSemver
if (($extension_version -eq '3') -or ($extension_version -eq '5')) {
Add-PhalconFromGitHub $semver
} elseif ($extension_version -eq '4') {
Add-Extension -Extension phalcon -Stability stable -Extension_version $semver
}
}

# Function to add phalcon
Function Add-Phalcon() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/extensions/phalcon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ get_phalcon_version() {
if [ "$extension" = "phalcon5" ]; then
get_pecl_version phalcon stable 5
elif [ "$extension" = "phalcon4" ]; then
echo '4.1.3'
echo '4.1.2'
elif [ "$extension" = "phalcon3" ]; then
echo '3.4.5'
fi
Expand Down Expand Up @@ -32,7 +32,7 @@ add_phalcon_helper() {
package="php${version:?}-$extension"
add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
[ "$extension" = "phalcon4" ] && (install_packages "php${version:?}-psr" || pecl_install psr || pecl_install psr-1.1.0)
(check_package "$package" && install_packages "$package") || add_phalcon_from_repo
(check_package "$package" && install_packages "$package") || pecl_install phalcon-"$(get_phalcon_version)" || add_phalcon_from_repo
fi
}

Expand Down Expand Up @@ -85,7 +85,7 @@ add_phalcon5() {

# Function to add phalcon.
add_phalcon() {
extension=$1
local extension=$1
status='Enabled'
extension_major_version=${extension: -1}
if [[ "$extension_major_version" =~ [3-5] ]]; then
Expand Down

0 comments on commit cae6d06

Please sign in to comment.