From 50bbf77d0c499afa015b4a6317be3ce69bf01400 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:08:33 +0100 Subject: [PATCH] Fix module domain detection in Form::getTranslationDomain() The usage of preg_replace had two errors: 1) The regular expression was wrong 2) $matches[0] always contains the full matched string, not the first parenthesized subpattern The correct version of preg_replace would've been: if (preg_match('/^Icinga\\\\Module\\\\([A-Za-z]+)\\\\/', get_called_class(), $matches) === 1) { return strtolower($matches[1]); } But since there's no benefit of using a regular expression here except less speed, I replaced it with using explode. refs #7551 --- library/Icinga/Web/Form.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 850285baa..64712961f 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -806,19 +806,20 @@ class Form extends Zend_Form } /** - * Return the translation domain for this form + * Get the translation domain for this form * - * The returned translation domain is either determined based on - * this form's class path or it is the default `icinga' domain + * The returned translation domain is either determined based on this form's qualified name or it is the default + * 'icinga' domain * - * @return string + * @return string */ protected function getTranslationDomain() { - if (preg_match('@^Icinga\\\\Module\\\\([A-z]+)\\\\.*$@', get_called_class(), $matches) === 1) { - return strtolower($matches[0]); + $parts = explode('\\', get_called_class()); + if ($parts[1] === 'Module') { + // Assume format Icinga\Module\ModuleName\Forms\... + return strtolower($parts[2]); } - return 'icinga'; }