@@ -181,8 +181,9 @@ public static function atLeast(int $x, int $y, int $z = 0): bool
181
181
/**
182
182
* Adds a directory to the search path for shared libraries.
183
183
*
184
- * This method has no effect if FFI handles are already initialized or
185
- * if the specified path is already included.
184
+ * This method has no effect if FFI handles are already initialized,
185
+ * if the specified path is non-existent, or if the path is already
186
+ * included.
186
187
*
187
188
* @param string $path The path of the library.
188
189
* @return bool `true` if the path was added; otherwise, `false`.
@@ -194,12 +195,20 @@ public static function addLibraryPath(string $path): bool
194
195
return false ;
195
196
}
196
197
197
- if (!in_array ($ path , self ::$ libraryPaths )) {
198
- self ::$ libraryPaths [] = $ path ;
199
- return true ;
198
+ $ path = realpath ($ path );
199
+ if ($ path === false ) {
200
+ return false ;
201
+ }
202
+
203
+ $ path .= DIRECTORY_SEPARATOR ;
204
+
205
+ if (in_array ($ path , self ::$ libraryPaths )) {
206
+ return false ;
200
207
}
201
208
202
- return false ;
209
+ self ::$ libraryPaths [] = $ path ;
210
+
211
+ return true ;
203
212
}
204
213
205
214
/**
@@ -248,9 +257,6 @@ private static function libraryLoad(
248
257
foreach (self ::$ libraryPaths as $ path ) {
249
258
Utils::debugLog ("trying path " , ["path " => $ path ]);
250
259
try {
251
- if ($ path !== '' ) {
252
- $ path .= '/ ' ;
253
- }
254
260
$ library = \FFI ::cdef ($ interface , $ path . $ libraryName );
255
261
Utils::debugLog ("success " , []);
256
262
return $ library ;
@@ -289,9 +295,9 @@ private static function init(): void
289
295
290
296
if (PHP_OS_FAMILY === "OSX " || PHP_OS_FAMILY === "Darwin " ) {
291
297
// Homebrew on Apple Silicon
292
- self ::$ libraryPaths [] = "/opt/homebrew/lib " ;
298
+ self ::addLibraryPath ( "/opt/homebrew/lib " ) ;
293
299
// See https://github.com/Homebrew/brew/issues/13481#issuecomment-1207203483
294
- self ::$ libraryPaths [] = "/usr/local/lib " ;
300
+ self ::addLibraryPath ( "/usr/local/lib " ) ;
295
301
}
296
302
297
303
$ vips = self ::libraryLoad ($ vips_libname , <<<'CPP'
0 commit comments