mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Simplify win32 script
- Always specify the PHP install dir - Use default PhpManager functions - Fix CA Authorities (so that HTTPS calls work) - Don't handle the special xdebug case (it's bundled in PhpManager)
This commit is contained in:
parent
1db0b0651d
commit
fec9df11d6
@ -7,17 +7,10 @@ describe('Extension tests', () => {
|
||||
'7.2',
|
||||
'win32'
|
||||
);
|
||||
expect(win32).toContain('Install-PhpExtension xdebug');
|
||||
expect(win32).toContain('Install-PhpExtension pcov');
|
||||
expect(win32).toContain('Add-Extension xdebug');
|
||||
expect(win32).toContain('Add-Extension pcov');
|
||||
win32 = await extensions.addExtension('xdebug, pcov', '7.4', 'win32');
|
||||
const extension_url =
|
||||
'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
|
||||
expect(win32).toContain(
|
||||
'Invoke-WebRequest -Uri ' +
|
||||
extension_url +
|
||||
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll'
|
||||
);
|
||||
expect(win32).toContain('Install-PhpExtension pcov');
|
||||
expect(win32).toContain('Add-Extension pcov');
|
||||
|
||||
win32 = await extensions.addExtension(
|
||||
'does_not_exist',
|
||||
@ -25,9 +18,7 @@ describe('Extension tests', () => {
|
||||
'win32',
|
||||
true
|
||||
);
|
||||
expect(win32).toContain(
|
||||
'Add-Extension does_not_exist "Install-PhpExtension does_not_exist" extension'
|
||||
);
|
||||
expect(win32).toContain('Add-Extension does_not_exist');
|
||||
|
||||
win32 = await extensions.addExtension('xdebug', '7.2', 'fedora');
|
||||
expect(win32).toContain('Platform fedora is not supported');
|
||||
|
25
dist/index.js
vendored
25
dist/index.js
vendored
@ -1648,31 +1648,8 @@ function addExtensionWindows(extension_csv, version) {
|
||||
let script = '\n';
|
||||
yield utils.asyncForEach(extensions, function (extension) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
extension = extension.toLowerCase();
|
||||
// add script to enable extension is already installed along with php
|
||||
let install_command = '';
|
||||
switch (version + extension) {
|
||||
case '7.4xdebug': {
|
||||
const extension_url = 'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
|
||||
install_command =
|
||||
'Invoke-WebRequest -Uri ' +
|
||||
extension_url +
|
||||
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n';
|
||||
install_command += 'Enable-PhpExtension xdebug';
|
||||
break;
|
||||
}
|
||||
case '7.2xdebug':
|
||||
default:
|
||||
install_command = 'Install-PhpExtension ' + extension;
|
||||
break;
|
||||
}
|
||||
script +=
|
||||
'\nAdd-Extension ' +
|
||||
extension +
|
||||
' "' +
|
||||
install_command +
|
||||
'" ' +
|
||||
(yield utils.getExtensionPrefix(extension));
|
||||
script += '\nAdd-Extension ' + extension;
|
||||
});
|
||||
});
|
||||
return script;
|
||||
|
@ -49,33 +49,8 @@ export async function addExtensionWindows(
|
||||
const extensions: Array<string> = await utils.extensionArray(extension_csv);
|
||||
let script = '\n';
|
||||
await utils.asyncForEach(extensions, async function(extension: string) {
|
||||
extension = extension.toLowerCase();
|
||||
// add script to enable extension is already installed along with php
|
||||
|
||||
let install_command = '';
|
||||
switch (version + extension) {
|
||||
case '7.4xdebug': {
|
||||
const extension_url =
|
||||
'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
|
||||
install_command =
|
||||
'Invoke-WebRequest -Uri ' +
|
||||
extension_url +
|
||||
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n';
|
||||
install_command += 'Enable-PhpExtension xdebug';
|
||||
break;
|
||||
}
|
||||
case '7.2xdebug':
|
||||
default:
|
||||
install_command = 'Install-PhpExtension ' + extension;
|
||||
break;
|
||||
}
|
||||
script +=
|
||||
'\nAdd-Extension ' +
|
||||
extension +
|
||||
' "' +
|
||||
install_command +
|
||||
'" ' +
|
||||
(await utils.getExtensionPrefix(extension));
|
||||
script += '\nAdd-Extension ' + extension;
|
||||
});
|
||||
return script;
|
||||
}
|
||||
|
@ -1,89 +1,83 @@
|
||||
param (
|
||||
[Parameter(Mandatory=$true)][string]$version = "7.3",
|
||||
[Parameter(Mandatory=$true)][string]$dir
|
||||
[Parameter(Mandatory = $true)][string]$version = "7.3",
|
||||
[Parameter(Mandatory = $true)][string]$dir
|
||||
)
|
||||
|
||||
$tick = ([char]8730)
|
||||
$cross = ([char]10007)
|
||||
$php_dir = 'C:\tools\php'
|
||||
|
||||
Function Step-Log($message) {
|
||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
|
||||
}
|
||||
|
||||
Function Add-Log($mark, $subject, $message) {
|
||||
$code = if($mark -eq $cross) {"31"} else {"32"}
|
||||
$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\n" $code $mark $subject $message
|
||||
}
|
||||
|
||||
if($version -eq '7.4') {
|
||||
$version = '7.4RC'
|
||||
}
|
||||
|
||||
Step-Log "Setup PhpManager"
|
||||
Install-Module -Name PhpManager -Force -Scope CurrentUser
|
||||
Add-Log $tick "PhpManager" "Installed"
|
||||
|
||||
$installed = $($(php -v)[0] -join '')[4..6] -join ''
|
||||
$installed = $null
|
||||
if (Test-Path -LiteralPath $php_dir -PathType Container) {
|
||||
try {
|
||||
$installed = Get-Php -Path $php_dir
|
||||
}
|
||||
catch {
|
||||
}
|
||||
}
|
||||
Step-Log "Setup PHP and Composer"
|
||||
$status = "Switched to PHP$version"
|
||||
if($installed -ne $version) {
|
||||
if($version -lt '7.0') {
|
||||
if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) {
|
||||
if ($version -lt '7.0') {
|
||||
Install-Module -Name VcRedist -Force
|
||||
}
|
||||
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path C:\tools\php -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
|
||||
$status = "Installed PHP$version"
|
||||
if ($version -eq '7.4') {
|
||||
$version = '7.4RC'
|
||||
}
|
||||
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
|
||||
$installed = Get-Php -Path $php_dir
|
||||
$status = "Installed PHP $($installed.FullVersion)"
|
||||
}
|
||||
else {
|
||||
$status = "Switched to PHP $($installed.FullVersion)"
|
||||
}
|
||||
|
||||
$ext_dir = "C:\tools\php\ext"
|
||||
Add-Content C:\tools\php\php.ini "date.timezone = 'UTC'"
|
||||
Set-PhpIniKey extension_dir $ext_dir
|
||||
if($version -lt '7.4') {
|
||||
Enable-PhpExtension openssl
|
||||
Enable-PhpExtension curl
|
||||
} else {
|
||||
Add-Content C:\tools\php\php.ini "extension=php_openssl.dll`nextension=php_curl.dll"
|
||||
Copy-Item $dir"\..\src\ext\php_pcov.dll" -Destination $ext_dir"\php_pcov.dll"
|
||||
Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir
|
||||
Enable-PhpExtension -Extension openssl, curl -Path $php_dir
|
||||
Update-PhpCAInfo -Path $php_dir -Source CurrentUser
|
||||
if ([Version]$installed.Version -ge '7.4') {
|
||||
Copy-Item "$dir\..\src\ext\php_pcov.dll" -Destination "$($installed.ExtensionsPath)\php_pcov.dll"
|
||||
}
|
||||
Add-Log $tick "PHP" $status
|
||||
|
||||
Install-Composer -Scope System -Path C:\tools\php
|
||||
Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
|
||||
Add-Log $tick "Composer" "Installed"
|
||||
|
||||
Function Add-Extension($extension, $install_command, $prefix)
|
||||
{
|
||||
Function Add-Extension($extension) {
|
||||
try {
|
||||
$existing_extensions = Get-PhpExtension -Path C:\tools\php
|
||||
$match = @($existing_extensions | Where-Object { $_.Name -like $extension })
|
||||
if(!(php -m | findstr -i ${extension}) -and $match) {
|
||||
$filename = $match."Filename".split('\')[-1]
|
||||
Add-Content C:\tools\php\php.ini "`n$prefix=$filename"
|
||||
Add-Log $tick $extension "Enabled"
|
||||
} elseif(php -m | findstr -i $extension) {
|
||||
Add-Log $tick $extension "Enabled"
|
||||
}
|
||||
} catch [Exception] {
|
||||
Add-Log $cross $extension "Could not enable"
|
||||
}
|
||||
|
||||
$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
|
||||
Add-Log $tick $extension "Installed and enabled"
|
||||
} catch [Exception] {
|
||||
Add-Log $cross $extension "Could not install on PHP$version"
|
||||
$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"
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(!(php -m | findstr -i $extension)) {
|
||||
Add-Log $cross $extension "Could not find $extension for PHP$version on PECL"
|
||||
else {
|
||||
Install-PhpExtension -Extension $extension -Path $php_dir
|
||||
Add-Log $tick $extension "Downloaded and enabled"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Add-Log $cross $extension "Could not enable"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user