Skip to content

Commit aa980ce

Browse files
authored
Multiple php ext dlls (#134)
* Let Get-PhpExtensionDetail return the absolute path of DLLs * Fix installing pecl_http PHP extension (which includes the raphf PHP extension)
1 parent faf275a commit aa980ce

File tree

4 files changed

+83
-63
lines changed

4 files changed

+83
-63
lines changed
Binary file not shown.
Binary file not shown.

PhpManager/public/Install-PhpExtension.ps1

Lines changed: 74 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
$tempFolder = $null
8484
$finalDllName = $null
8585
$additionalFiles = @()
86+
$newExtensions = @()
8687
try {
8788
if (Test-Path -Path $Extension -PathType Leaf) {
8889
if ($Version -ne '') {
@@ -95,7 +96,7 @@
9596
throw 'You can''t specify the -MaximumStability argument if you specify an existing file with the -Extension argument'
9697
}
9798
$dllPath = [System.IO.Path]::GetFullPath($Extension)
98-
$newExtension = Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
99+
$newExtensions += Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
99100
$moveDll = $false
100101
}
101102
else {
@@ -165,8 +166,17 @@
165166
$dllFiles = @()
166167
}
167168
}
169+
$additionalExtensionsDll = @()
170+
$dllNames = $dllFiles | Where-Object -Property Name -Like "php_*.dll" | Select-Object -ExpandProperty Name
171+
if ($dllNames -is [array] -and $dllNames.Length -eq 2 -and $dllNames -contains 'php_http.dll' -and $dllNames -contains 'php_raphf.dll') {
172+
$newExtensions += Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $(Join-Path -Path $tempFolder -ChildPath 'php_raphf.dll')
173+
$additionalExtensionsDll += 'php_raphf.dll'
174+
}
168175
$dllPath = $null
169176
foreach ($dllFile in $dllFiles) {
177+
if ($additionalExtensionsDll -contains $dllFile.Name) {
178+
continue
179+
}
170180
if ($dllFile.Name -like "php_*.dll") {
171181
if ($dllPath) {
172182
throw ("Multiple PHP DLL found in archive downloaded from {0}" -f $availablePackageVersion.PackageArchiveUrl)
@@ -184,7 +194,7 @@
184194
$keepDownloadedFile = $true
185195
$dllPath = $downloadedFile
186196
}
187-
$newExtension = Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
197+
$newExtensions += Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
188198
$moveDll = $true
189199
}
190200
catch {
@@ -202,73 +212,76 @@
202212
}
203213
}
204214
}
205-
$oldExtension = Get-PhpExtension -Path $phpVersion.ExecutablePath | Where-Object { $_.Handle -eq $newExtension.Handle }
206-
if ($null -ne $oldExtension) {
207-
if ($oldExtension.Type -eq $Script:EXTENSIONTYPE_BUILTIN) {
208-
Write-Verbose ("'{0}' is a builtin extension" -f $oldExtension.Name)
209-
}
210-
Write-Verbose ("Upgrading extension '{0}' from version {1} to version {2}" -f $oldExtension.Name, $oldExtension.Version, $newExtension.Version)
211-
if (-Not(Test-IsFileWritable($oldExtension.Filename))) {
212-
throw "Unable to write to the file $($oldExtension.Filename)"
213-
}
214-
if ($moveDll) {
215-
Move-Item -Path $dllPath -Destination $oldExtension.Filename -Force
216-
} else {
217-
Copy-Item -Path $dllPath -Destination $oldExtension.Filename -Force
218-
}
219-
try {
220-
Reset-Acl -Path $oldExtension.Filename
221-
} catch {
222-
Write-Debug -Message "Failed to reset the ACL for $($oldExtension.Filename): $($_.Exception.Message)"
223-
}
224-
foreach ($additionalFile in $additionalFiles) {
225-
$additionalFileDestination = Join-Path -Path $AdditionalFilesPath -ChildPath $(Split-Path -Path $additionalFile -Leaf)
226-
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
215+
foreach ($newExtension in $newExtensions) {
216+
$oldExtension = Get-PhpExtension -Path $phpVersion.ExecutablePath | Where-Object { $_.Handle -eq $newExtension.Handle }
217+
if ($null -ne $oldExtension) {
218+
if ($oldExtension.Type -eq $Script:EXTENSIONTYPE_BUILTIN) {
219+
Write-Verbose ("'{0}' is a builtin extension" -f $oldExtension.Name)
220+
}
221+
Write-Verbose ("Upgrading extension '{0}' from version {1} to version {2}" -f $oldExtension.Name, $oldExtension.Version, $newExtension.Version)
222+
if (-Not(Test-IsFileWritable($oldExtension.Filename))) {
223+
throw "Unable to write to the file $($oldExtension.Filename)"
224+
}
225+
if ($moveDll) {
226+
Move-Item -Path $newExtension.Filename -Destination $oldExtension.Filename -Force
227+
} else {
228+
Copy-Item -Path $newExtension.Filename -Destination $oldExtension.Filename -Force
229+
}
227230
try {
228-
Reset-Acl -Path $additionalFileDestination
231+
Reset-Acl -Path $oldExtension.Filename
229232
} catch {
230-
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
233+
Write-Debug -Message "Failed to reset the ACL for $($oldExtension.Filename): $($_.Exception.Message)"
234+
}
235+
foreach ($additionalFile in $additionalFiles) {
236+
$additionalFileDestination = Join-Path -Path $AdditionalFilesPath -ChildPath $(Split-Path -Path $additionalFile -Leaf)
237+
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
238+
try {
239+
Reset-Acl -Path $additionalFileDestination
240+
} catch {
241+
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
242+
}
243+
}
244+
if ($oldExtension.State -eq $Script:EXTENSIONSTATE_DISABLED -and -Not($DontEnable)) {
245+
Enable-PhpExtension -Extension $oldExtension.Name -Path $phpVersion.ExecutablePath
231246
}
232247
}
233-
if ($oldExtension.State -eq $Script:EXTENSIONSTATE_DISABLED -and -Not($DontEnable)) {
234-
Enable-PhpExtension -Extension $oldExtension.Name -Path $phpVersion.ExecutablePath
235-
}
236-
}
237-
else {
238-
Write-Verbose ("Installing new extension '{0}' version {1}" -f $newExtension.Name, $newExtension.Version)
239-
if (-not($NoDependencies)) {
240-
Install-PhpExtensionPrerequisite -Extension $newExtension.Handle -InstallPath $AdditionalFilesPath -PhpPath $phpVersion.ActualFolder
241-
}
242-
if ($null -eq $finalDllName) {
243-
$newExtensionFilename = [System.IO.Path]::Combine($phpVersion.ExtensionsPath, [System.IO.Path]::GetFileName($dllPath))
244-
} else {
245-
$newExtensionFilename = [System.IO.Path]::Combine($phpVersion.ExtensionsPath, [System.IO.Path]::GetFileName($finalDllName))
246-
}
247-
if ($moveDll) {
248-
Write-Verbose "Moving ""$dllPath"" to ""$newExtensionFilename"""
249-
Move-Item -Path $dllPath -Destination $newExtensionFilename
250-
} else {
251-
Write-Verbose "Copying ""$dllPath"" to ""$newExtensionFilename"""
252-
Copy-Item -Path $dllPath -Destination $newExtensionFilename
253-
}
254-
try {
255-
Reset-Acl -Path $newExtensionFilename
256-
} catch {
257-
Write-Debug -Message "Failed to reset the ACL for $($newExtensionFilename): $($_.Exception.Message)"
258-
}
259-
foreach ($additionalFile in $additionalFiles) {
260-
$additionalFileDestination = Join-Path -Path $AdditionalFilesPath -ChildPath $(Split-Path -Path $additionalFile -Leaf)
261-
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
248+
else {
249+
Write-Verbose ("Installing new extension '{0}' version {1}" -f $newExtension.Name, $newExtension.Version)
250+
if (-not($NoDependencies)) {
251+
Install-PhpExtensionPrerequisite -Extension $newExtension.Handle -InstallPath $AdditionalFilesPath -PhpPath $phpVersion.ActualFolder
252+
}
253+
if ($null -eq $finalDllName) {
254+
$newExtensionFilename = [System.IO.Path]::Combine($phpVersion.ExtensionsPath, [System.IO.Path]::GetFileName($newExtension.Filename))
255+
} else {
256+
$newExtensionFilename = [System.IO.Path]::Combine($phpVersion.ExtensionsPath, [System.IO.Path]::GetFileName($finalDllName))
257+
}
258+
if ($moveDll) {
259+
Write-Verbose "Moving ""$($newExtension.Filename)"" to ""$newExtensionFilename"""
260+
Move-Item -Path $newExtension.Filename -Destination $newExtensionFilename
261+
} else {
262+
Write-Verbose "Copying ""$($newExtension.Filename)"" to ""$newExtensionFilename"""
263+
Copy-Item -Path $newExtension.Filename -Destination $newExtensionFilename
264+
}
262265
try {
263-
Reset-Acl -Path $additionalFileDestination
266+
Reset-Acl -Path $newExtensionFilename
264267
} catch {
265-
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
268+
Write-Debug -Message "Failed to reset the ACL for $($newExtensionFilename): $($_.Exception.Message)"
269+
}
270+
foreach ($additionalFile in $additionalFiles) {
271+
$additionalFileDestination = Join-Path -Path $AdditionalFilesPath -ChildPath $(Split-Path -Path $additionalFile -Leaf)
272+
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
273+
try {
274+
Reset-Acl -Path $additionalFileDestination
275+
} catch {
276+
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
277+
}
278+
}
279+
if (-Not($DontEnable)) {
280+
Write-Verbose "Enabling extension ""$($newExtension.Name)"" for ""$($phpVersion.ExecutablePath)"""
281+
Enable-PhpExtension -Extension $newExtension.Name -Path $phpVersion.ExecutablePath
266282
}
267283
}
268-
if (-Not($DontEnable)) {
269-
Write-Verbose "Enabling extension ""$($newExtension.Name)"" for ""$($phpVersion.ExecutablePath)"""
270-
Enable-PhpExtension -Extension $newExtension.Name -Path $phpVersion.ExecutablePath
271-
}
284+
$additionalFiles = @()
272285
}
273286
}
274287
finally {

src/Inspect-PhpExtension.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ void parseDll(HMODULE hModule, extensionInfo* extensionInfo)
142142

143143
void parseFile(LPCSTR filename, LPCSTR architecture)
144144
{
145-
HMODULE hModule = LoadLibraryEx(filename, NULL, DONT_RESOLVE_DLL_REFERENCES);
145+
DWORD rc;
146+
TCHAR fullpath[MAX_PATH];
147+
rc = GetFullPathName(filename, MAX_PATH, fullpath, NULL);
148+
if (rc == 0 || rc > MAX_PATH) {
149+
printf("Unable to determine the absolute path of the file %s\n", filename);
150+
return;
151+
}
152+
HMODULE hModule = LoadLibraryEx(fullpath, NULL, DONT_RESOLVE_DLL_REFERENCES);
146153
if (hModule == NULL) {
147154
printf("Unable to open the DLL.\n");
148155
} else {
@@ -162,7 +169,7 @@ void parseFile(LPCSTR filename, LPCSTR architecture)
162169
extensionInfo.type,
163170
extensionInfo.name == NULL ? "" : extensionInfo.name,
164171
extensionInfo.version == NULL ? "" : extensionInfo.version,
165-
filename
172+
fullpath
166173
);
167174
}
168175
FreeLibrary(hModule);

0 commit comments

Comments
 (0)