From 07f68035409c1604d0a1bb44e7cda04577aa9e65 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 23 Sep 2011 01:14:52 +0530 Subject: [PATCH] Additional inflection rules provided through Inflector::rules() now take precedence over the core ones as expected. Fixes #2016 --- cake/libs/inflector.php | 8 ++++++-- cake/tests/cases/libs/inflector.test.php | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index 7f3e02f38..b2674cb27 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -369,7 +369,11 @@ class Inflector { if ($reset) { $_this->{$var}[$rule] = $pattern; } else { - $_this->{$var}[$rule] = array_merge($pattern, $_this->{$var}[$rule]); + if ($rule === 'uninflected') { + $_this->{$var}[$rule] = array_merge($pattern, $_this->{$var}[$rule]); + } else { + $_this->{$var}[$rule] = $pattern + $_this->{$var}[$rule]; + } } unset($rules[$rule], $_this->{$var}['cache' . ucfirst($rule)]); if (isset($_this->{$var}['merged'][$rule])) { @@ -382,7 +386,7 @@ class Inflector { } } } - $_this->{$var}['rules'] = array_merge($rules, $_this->{$var}['rules']); + $_this->{$var}['rules'] = $rules + $_this->{$var}['rules']; break; } } diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index 6f0562b3c..fadcd1908 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -434,9 +434,11 @@ class InflectorTest extends CakeTestCase { $this->assertEqual(Inflector::singularize('Bananas'), 'Banazzz', 'Was inflected with old rules. %s'); Inflector::rules('plural', array( - 'rules' => array('/(.*)na$/i' => '\1zzz') + 'rules' => array('/(.*)na$/i' => '\1zzz'), + 'irregular' => array('corpus' => 'corpora') )); - $this->assertEqual(Inflector::pluralize('Banana'), 'Banazzz', 'Was inflected with old rules. %s'); + $this->assertEqual(Inflector::pluralize('Banana'), 'Banazzz', 'Was inflected with old rules: %s'); + $this->assertEqual(Inflector::pluralize('corpus'), 'corpora', 'Was inflected with old irregular form: %s'); } /**