private/Get-PhpSrc.ps1
|
function Get-PhpSrc { <# .SYNOPSIS Get the PHP source code. .PARAMETER PhpVersion PHP Version #> [OutputType()] param ( [Parameter(Mandatory = $true, Position=0, HelpMessage='PHP Version')] [string] $PhpVersion ) begin { } process { Add-Type -Assembly "System.IO.Compression.Filesystem" $baseUrl = "https://github.com/php/php-src/archive" $zipFile = "php-$PhpVersion.zip" $directory = "php-$PhpVersion-src" if ( $PhpVersion.Contains(".")) { $ref = "php-$PhpVersion" $url = "$baseUrl/refs/tags/php-$PhpVersion.zip" } else { $ref = $PhpVersion $url = "$baseUrl/$PhpVersion.zip" } $currentDirectory = (Get-Location).Path $zipFilePath = Join-Path $currentDirectory $zipFile $directoryPath = Join-Path $currentDirectory $directory $srcZipFilePath = Join-Path $currentDirectory "php-$PhpVersion-src.zip" Get-File -Url $url -Outfile $zipFile [System.IO.Compression.ZipFile]::ExtractToDirectory($zipFilePath, $currentDirectory) Rename-Item -Path "php-src-$ref" -NewName $directory if ($PhpVersion -match '^7\.2\.\d+$') { Set-Content -Path (Join-Path $directoryPath 'win32/build/mkdist.php') -Value ((Get-Content -Raw -Path (Join-Path $directoryPath 'win32/build/mkdist.php')).Replace('$hdr_data{$i}', '$hdr_data[$i]')) -NoNewline } [System.IO.Compression.ZipFile]::CreateFromDirectory($directoryPath, $srcZipFilePath) } end { } } |