You are here

public static function Inflector::rules in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php \Doctrine\Common\Inflector\Inflector::rules()

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') )); }}}

Parameters

string $type The type of inflection, either 'plural' or 'singular':

array $rules An array of rules to be added.:

boolean $reset If true, will unset default inflections for all: new rules that are being defined in $rules.

Return value

void

4 calls to Inflector::rules()
InflectorTest::testCustomPluralRule in vendor/doctrine/inflector/tests/Doctrine/Tests/Common/Inflector/InflectorTest.php
testCustomPluralRule method
InflectorTest::testCustomRuleWithReset in vendor/doctrine/inflector/tests/Doctrine/Tests/Common/Inflector/InflectorTest.php
Test resetting inflection rules.
InflectorTest::testCustomSingularRule in vendor/doctrine/inflector/tests/Doctrine/Tests/Common/Inflector/InflectorTest.php
testCustomSingularRule method
InflectorTest::testRulesClearsCaches in vendor/doctrine/inflector/tests/Doctrine/Tests/Common/Inflector/InflectorTest.php
test that setting new rules clears the inflector caches.

File

vendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php, line 281

Class

Inflector
Doctrine inflector has static methods for inflecting text.

Namespace

Doctrine\Common\Inflector

Code

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] = $rule === 'uninflected' ? 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 ($type === 'plural') {
      self::$cache['pluralize'] = self::$cache['tableize'] = array();
    }
    elseif ($type === 'singular') {
      self::$cache['singularize'] = array();
    }
  }
  self::${$type}['rules'] = $rules + self::${$type}['rules'];
}