WP_CLI

Inflector::rules()public staticWP-CLI 1.0

Adds custom inflection $rules, of either 'plural' or 'singular' $type.

Usage:

{{{ Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables')); Inflector::rules('plural', array(

'rules' => array('/^(inflect)ors$/i' => '\1ables'),
'uninflected' => array('dontinflectme'),
'irregular' => array('red' => 'redlings')

)); }}}

Метод класса: Inflector{}

Хуков нет.

Возвращает

null. Ничего.

Использование

$result = Inflector::rules( $type, $rules, $reset );
$type(строка) (обязательный)
The type of inflection, either 'plural' or 'singular'
$rules(массив) (обязательный)
An array of rules to be added.
$reset(true|false)
If true, will unset default inflections for all new rules that are being defined in $rules.
По умолчанию: false

Код Inflector::rules() WP-CLI 2.8.0-alpha

public static function rules( $type, $rules, $reset = false ) {
	foreach ( $rules as $rule => $pattern ) {
		if ( ! is_array( $pattern ) ) {
			continue;
		}

		if ( $reset ) {
			self::${$type}[ $rule ] = $pattern;
		} else {
			self::${$type}[ $rule ] = ( 'uninflected' === $rule )
				? array_merge( $pattern, self::${$type}[ $rule ] )
				: $pattern + self::${$type}[ $rule ];
		}

		unset( $rules[ $rule ], self::${$type}[ 'cache' . ucfirst( $rule ) ] );

		if ( isset( self::${$type}['merged'][ $rule ] ) ) {
			unset( self::${$type}['merged'][ $rule ] );
		}

		if ( 'plural' === $type ) {
			self::$cache['pluralize'] = [];
			self::$cache['tableize']  = [];
		} elseif ( 'singular' === $type ) {
			self::$cache['singularize'] = [];
		}
	}

	self::${$type}['rules'] = $rules + self::${$type}['rules'];
}