Additional inflection rules provided through Inflector::rules() now take precedence over the core ones as expected. Fixes #2016

This commit is contained in:
ADmad 2011-09-23 01:14:52 +05:30
parent 0267a048f3
commit 07f6803540
2 changed files with 10 additions and 4 deletions

View file

@ -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;
}
}

View file

@ -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');
}
/**