Skip to content
Browse files

Additional inflection rules provided through Inflector::rules() now t…

…ake precedence over the core ones as expected. Fixes #2016
  • Loading branch information...
1 parent 0267a04 commit 07f68035409c1604d0a1bb44e7cda04577aa9e65 @ADmad ADmad committed
Showing with 10 additions and 4 deletions.
  1. +6 −2 cake/libs/inflector.php
  2. +4 −2 cake/tests/cases/libs/inflector.test.php
View
8 cake/libs/inflector.php
@@ -369,7 +369,11 @@ function rules($type, $rules, $reset = false) {
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 @@ function rules($type, $rules, $reset = false) {
}
}
}
- $_this->{$var}['rules'] = array_merge($rules, $_this->{$var}['rules']);
+ $_this->{$var}['rules'] = $rules + $_this->{$var}['rules'];
break;
}
}
View
6 cake/tests/cases/libs/inflector.test.php
@@ -434,9 +434,11 @@ function testRulesClearsCaches() {
$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');
}
/**

0 comments on commit 07f6803

Please sign in to comment.
Something went wrong with that request. Please try again.