WP_CLI
Inflector::singularize()
Returns a word in singular form.
Метод класса: Inflector{}
Хуков нет.
Возвращает
Строку
. The word in singular form.
Использование
$result = Inflector::singularize( $word );
- $word(строка) (обязательный)
- The word in plural form.
Код Inflector::singularize() Inflector::singularize WP-CLI 2.8.0-alpha
public static function singularize( $word ) { if ( isset( self::$cache['singularize'][ $word ] ) ) { return self::$cache['singularize'][ $word ]; } if ( ! isset( self::$singular['merged']['uninflected'] ) ) { self::$singular['merged']['uninflected'] = array_merge( self::$singular['uninflected'], self::$uninflected ); } if ( ! isset( self::$singular['merged']['irregular'] ) ) { self::$singular['merged']['irregular'] = array_merge( self::$singular['irregular'], array_flip( self::$plural['irregular'] ) ); } if ( ! isset( self::$singular['cacheUninflected'] ) || ! isset( self::$singular['cacheIrregular'] ) ) { self::$singular['cacheUninflected'] = '(?:' . join( '|', self::$singular['merged']['uninflected'] ) . ')'; self::$singular['cacheIrregular'] = '(?:' . join( '|', array_keys( self::$singular['merged']['irregular'] ) ) . ')'; } if ( preg_match( '/(.*)\\b(' . self::$singular['cacheIrregular'] . ')$/i', $word, $regs ) ) { self::$cache['singularize'][ $word ] = $regs[1] . substr( $word, 0, 1 ) . substr( self::$singular['merged']['irregular'][ strtolower( $regs[2] ) ], 1 ); return self::$cache['singularize'][ $word ]; } if ( preg_match( '/^(' . self::$singular['cacheUninflected'] . ')$/i', $word, $regs ) ) { self::$cache['singularize'][ $word ] = $word; return $word; } foreach ( self::$singular['rules'] as $rule => $replacement ) { if ( preg_match( $rule, $word ) ) { self::$cache['singularize'][ $word ] = preg_replace( $rule, $replacement, $word ); return self::$cache['singularize'][ $word ]; } } self::$cache['singularize'][ $word ] = $word; return $word; }