rules() public static méthode

Gets or adds inflection and transliteration rules.
public static rules ( string $type, array $config = [] ) : mixed
$type string Either `'transliteration'`, `'uninflected'`, `'singular'` or `'plural'`.
$config array
Résultat mixed If `$config` is empty, returns the rules list specified by `$type`, otherwise returns `null`.
	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);
	}
Exemple #2
0
<?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) {
Exemple #3
0
 public function testAddingUninflectedWords()
 {
     $this->assertEqual(Inflector::pluralize('bord'), 'bords');
     Inflector::rules('uninflected', 'bord');
     $this->assertEqual(Inflector::pluralize('bord'), 'bord');
 }