本文整理汇总了PHP中lithium\util\Inflector::rules方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::rules方法的具体用法?PHP Inflector::rules怎么用?PHP Inflector::rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\util\Inflector
的用法示例。
在下文中一共展示了Inflector::rules方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTransliteration
public function testTransliteration() {
$data = array(
'transliteration' => array(
'\$' => 'dollar',
'&' => 'and'
)
);
Catalog::write('runtime', 'inflection', 'en', $data);
Inflector::rules(
'transliteration', Catalog::read('runtime', 'inflection.transliteration', 'en')
);
$result = Inflector::slug('this & that');
$expected = 'this-and-that';
$this->assertEqual($expected, $result);
$data = array(
'transliteration' => array(
't' => 'd',
'&' => 'und'
)
);
Catalog::write('runtime', 'inflection', 'de', $data);
Inflector::rules(
'transliteration', Catalog::read('runtime', 'inflection.transliteration', 'de')
);
$result = Inflector::slug('this & that');
$expected = 'dhis-und-dhad';
$this->assertEqual($expected, $result);
}
示例2: function
<?php
/**
* radium: lithium application framework
*
* @copyright Copyright 2013, brünsicke.com GmbH (http://bruensicke.com)
* @license http://opensource.org/licenses/BSD-3-Clause The BSD License
*/
use lithium\util\Inflector;
use lithium\util\Validator;
use radium\media\Mime;
/*
* We want to avoid method names like `statuses()` - therefore, we go this route
*/
Inflector::rules('uninflected', 'status');
/*
* apply new validation rules to the Validator class, because we need them
*/
Validator::add(array('sha1' => '/^[A-Fa-f0-9]{40}$/', 'slug' => '/^[a-z0-9\\_\\-\\.]*$/', 'loose_slug' => '/^[a-zA-Z0-9\\_\\-\\.]*$/', 'strict_slug' => '/^[a-z][a-z0-9\\_\\-]*$/', 'isUnique' => function ($value, $format, $options) {
$conditions = array($options['field'] => $value);
foreach ((array) $options['model']::meta('key') as $field) {
if (!empty($options['values'][$field])) {
$conditions[$field] = array('!=' => $options['values'][$field]);
}
}
$fields = $options['field'];
$result = $options['model']::find('first', compact('fields', 'conditions'));
return (bool) empty($result);
}, 'status' => function ($value, $format, $options) {
return (bool) $options['model']::status($value);
}, 'type' => function ($value, $format, $options) {
示例3: testAddingUninflectedWords
public function testAddingUninflectedWords()
{
$this->assertEqual(Inflector::pluralize('bord'), 'bords');
Inflector::rules('uninflected', 'bord');
$this->assertEqual(Inflector::pluralize('bord'), 'bord');
}