From a0c675376166be4a23f1d457a0b37a4072be6b4c Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Mon, 19 Apr 2021 10:25:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Use=20`php=5Fini=5Fscanned=5Ffil?= =?UTF-8?q?es`=20for=20.ini=20scan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using `php-config --ini-dir` seems to fail on PHP 7.2 and below, likely because said option was not available in these earlier versions. Because all we need are the additional .ini files, calling php_ini_scanned_files is a better solution since it is supported from PHP 5 and up. This commit fixes the crash issue that was caused by running the failing `php-config` command. More information: https://www.php.net/manual/en/function.php-ini-scanned-files.php --- phpmon/Domain/Core/PhpInstallation.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/phpmon/Domain/Core/PhpInstallation.swift b/phpmon/Domain/Core/PhpInstallation.swift index cbc924a..0f0630c 100644 --- a/phpmon/Domain/Core/PhpInstallation.swift +++ b/phpmon/Domain/Core/PhpInstallation.swift @@ -43,15 +43,15 @@ class PhpInstallation { post_max_size: Self.getByteCount(key: "post_max_size") ) - // Determine which folder(s) to scan for additional files - let iniFolder = Command.execute(path: Paths.phpConfig, arguments: ["--ini-dir"], trimNewlines: true) + // Return a list of .ini files parsed after php.ini + let paths = Command.execute(path: Paths.php, arguments: ["-r", "echo php_ini_scanned_files();"]) + .replacingOccurrences(of: "\n", with: "") + .split(separator: ",") + .map { String($0) } - // Check the contents of the ini dir - let enumerator = FileManager.default.enumerator(atPath: URL(fileURLWithPath: iniFolder).path) - let filePaths = enumerator?.allObjects as! [String] - - filePaths.filter { $0.contains(".ini") }.forEach { (iniFileName) in - let extensions = PhpExtension.load(from: URL(fileURLWithPath: "\(iniFolder)/\(iniFileName)")) + // See if any extensions are present in said .ini files + paths.forEach { (iniFilePath) in + let extensions = PhpExtension.load(from: URL(fileURLWithPath: iniFilePath)) if extensions.count > 0 { self.extensions.append(contentsOf: extensions) }