diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-04-14 05:11:26 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-04-14 05:11:26 +0300 |
commit | 409d6924e2777d90b196e39df8926f70959ee8d6 (patch) | |
tree | 64efd27c269529cdfea879341eec429956246bc6 /plugins/Diagnostics | |
parent | 6fff7358e367352efba646fbe3fc569f4a9222af (diff) |
Reduce code duplication
Diffstat (limited to 'plugins/Diagnostics')
4 files changed, 8 insertions, 45 deletions
diff --git a/plugins/Diagnostics/Diagnostic/PhpExtensionsCheck.php b/plugins/Diagnostics/Diagnostic/PhpExtensionsCheck.php index 417aee1710..901c18c580 100644 --- a/plugins/Diagnostics/Diagnostic/PhpExtensionsCheck.php +++ b/plugins/Diagnostics/Diagnostic/PhpExtensionsCheck.php @@ -27,9 +27,10 @@ class PhpExtensionsCheck implements Diagnostic $longErrorMessage = ''; $requiredExtensions = $this->getRequiredExtensions(); + $loadedExtensions = @get_loaded_extensions(); foreach ($requiredExtensions as $extension) { - if (! in_array($extension, $this->getPhpExtensionsLoaded())) { + if (! in_array($extension, $loadedExtensions)) { $status = DiagnosticResult::STATUS_ERROR; $comment = $extension . ': ' . $this->translator->translate('Installation_RestartWebServer'); $longErrorMessage .= '<p>' . $this->getHelpMessage($extension) . '</p>'; @@ -67,11 +68,6 @@ class PhpExtensionsCheck implements Diagnostic return $requiredExtensions; } - private function getPhpExtensionsLoaded() - { - return @get_loaded_extensions(); - } - private function getHelpMessage($missingExtension) { $messages = array( diff --git a/plugins/Diagnostics/Diagnostic/PhpFunctionsCheck.php b/plugins/Diagnostics/Diagnostic/PhpFunctionsCheck.php index 6288d33cbd..7e68c9538e 100644 --- a/plugins/Diagnostics/Diagnostic/PhpFunctionsCheck.php +++ b/plugins/Diagnostics/Diagnostic/PhpFunctionsCheck.php @@ -26,7 +26,7 @@ class PhpFunctionsCheck implements Diagnostic $result = new DiagnosticResult($label); foreach ($this->getRequiredFunctions() as $function) { - if (! $this->functionExists($function)) { + if (! self::functionExists($function)) { $status = DiagnosticResult::STATUS_ERROR; $comment = sprintf( '%s <br/><br/><em>%s</em><br/><em>%s</em><br/>', @@ -66,7 +66,7 @@ class PhpFunctionsCheck implements Diagnostic * @param string $function * @return bool */ - private function functionExists($function) + public static function functionExists($function) { // eval() is a language construct if ($function == 'eval') { diff --git a/plugins/Diagnostics/Diagnostic/RecommendedExtensionsCheck.php b/plugins/Diagnostics/Diagnostic/RecommendedExtensionsCheck.php index ebbb74c933..c68a65d0a6 100644 --- a/plugins/Diagnostics/Diagnostic/RecommendedExtensionsCheck.php +++ b/plugins/Diagnostics/Diagnostic/RecommendedExtensionsCheck.php @@ -25,8 +25,10 @@ class RecommendedExtensionsCheck implements Diagnostic $result = new DiagnosticResult($label); + $loadedExtensions = @get_loaded_extensions(); + foreach ($this->getRecommendedExtensions() as $extension) { - if (! in_array($extension, $this->getPhpExtensionsLoaded())) { + if (! in_array($extension, $loadedExtensions)) { $status = DiagnosticResult::STATUS_WARNING; $comment = $extension . '<br/>' . $this->getHelpMessage($extension); } else { @@ -64,9 +66,4 @@ class RecommendedExtensionsCheck implements Diagnostic return $this->translator->translate($messages[$missingExtension]); } - - private function getPhpExtensionsLoaded() - { - return @get_loaded_extensions(); - } } diff --git a/plugins/Diagnostics/Diagnostic/RecommendedFunctionsCheck.php b/plugins/Diagnostics/Diagnostic/RecommendedFunctionsCheck.php index 1db14ade8c..eedf8e9224 100644 --- a/plugins/Diagnostics/Diagnostic/RecommendedFunctionsCheck.php +++ b/plugins/Diagnostics/Diagnostic/RecommendedFunctionsCheck.php @@ -26,7 +26,7 @@ class RecommendedFunctionsCheck implements Diagnostic $result = new DiagnosticResult($label); foreach ($this->getRecommendedFunctions() as $function) { - if (! $this->functionExists($function)) { + if (! PhpFunctionsCheck::functionExists($function)) { $status = DiagnosticResult::STATUS_WARNING; $comment = $function . '<br/>' . $this->getHelpMessage($function); } else { @@ -66,34 +66,4 @@ class RecommendedFunctionsCheck implements Diagnostic return $this->translator->translate($messages[$function]); } - - /** - * Tests if a function exists. Also handles the case where a function is disabled via Suhosin. - * - * @param string $function - * @return bool - */ - private function functionExists($function) - { - // eval() is a language construct - if ($function == 'eval') { - // does not check suhosin.executor.eval.whitelist (or blacklist) - if (extension_loaded('suhosin')) { - return @ini_get("suhosin.executor.disable_eval") != "1"; - } - return true; - } - - $exists = function_exists($function); - - if (extension_loaded('suhosin')) { - $blacklist = @ini_get("suhosin.executor.func.blacklist"); - if (!empty($blacklist)) { - $blacklistFunctions = array_map('strtolower', array_map('trim', explode(',', $blacklist))); - return $exists && !in_array($function, $blacklistFunctions); - } - } - - return $exists; - } } |