本文整理汇总了PHP中AkInflector::_loadConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP AkInflector::_loadConfig方法的具体用法?PHP AkInflector::_loadConfig怎么用?PHP AkInflector::_loadConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AkInflector
的用法示例。
在下文中一共展示了AkInflector::_loadConfig方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _inflect
function _inflect($word, $new_value, $type, $dictionary = null)
{
static $_cached;
static $_loaded;
if ($dictionary == null || $dictionary == 'inflector') {
$dictionary = 'inflector';
} else {
$dictionary = 'inflector/' . $dictionary;
}
if (!isset($_loaded[$dictionary])) {
$_loaded[$dictionary] = true;
$_cached[$dictionary] = array('singularize' => array(), 'pluralize' => array());
}
$config = AkInflector::_loadConfig($dictionary);
if (!in_array($type, array('singularize', 'pluralize'))) {
return $word;
}
if (isset($new_value)) {
$_cached[$dictionary][$type][$word] = $new_value;
return;
}
$_original_word = $word;
if (!isset($_cached[$dictionary][$type][$_original_word])) {
$lowercased_word = strtolower($word);
if (in_array($lowercased_word, $config[$type]['uncountable'])) {
return $word;
}
foreach ($config[$type]['irregular'] as $_plural => $_singular) {
if ($type == 'singularize') {
if (preg_match('/(' . $_singular . ')$/iu', $word, $arr)) {
$_cached[$dictionary][$type][$_original_word] = preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
return $_cached[$dictionary][$type][$_original_word];
}
} else {
if (preg_match('/(' . $_plural . ')$/iu', $word, $arr)) {
$_cached[$dictionary][$type][$_original_word] = preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
return $_cached[$dictionary][$type][$_original_word];
}
}
}
$replacements = isset($config[$type]['replacements']) ? $config[$type]['replacements'] : false;
if ($replacements !== false) {
$replacements_keys = array_keys($replacements);
foreach ($replacements_keys as $idx => $key) {
$replacements_keys[$idx] = '/' . $key . '/u';
}
$replacements_values = array_values($replacements);
}
foreach ($config[$type]['rules'] as $rule => $replacement) {
if (preg_match($rule . 'u', $word, $match)) {
if (strstr($replacement, '@') && $replacements) {
foreach ($match as $k => $v) {
$replacement = preg_replace("/(@{$k})/u", preg_replace($replacements_keys, $replacements_values, $v), $replacement);
}
}
$_cached[$dictionary][$type][$_original_word] = preg_replace($rule . 'u', $replacement, $word);
return $_cached[$dictionary][$type][$_original_word];
}
}
$_cached[$dictionary][$type][$_original_word] = $word;
return $_cached[$dictionary][$type][$_original_word];
}
return $_cached[$dictionary][$type][$_original_word];
}