Inflect::pluralize PHP Method

pluralize() public static method

public static pluralize ( $string )
    public static function pluralize($string)
    {
        global $Inflect_Uncountable, $Inflect_Irregular, $Inflect_Singular, $Inflect_Plural;
        // save some time in the case that singular and plural are the same
        if (in_array(strtolower($string), $Inflect_Uncountable)) {
            return $string;
        }
        // check for irregular singular forms
        foreach ($Inflect_Irregular as $pattern => $result) {
            $pattern = '/' . $pattern . '$/i';
            if (preg_match($pattern, $string)) {
                return preg_replace($pattern, $result, $string);
            }
        }
        // check for matches using regular expressions
        foreach ($Inflect_Plural as $pattern => $result) {
            if (preg_match($pattern, $string)) {
                return preg_replace($pattern, $result, $string);
            }
        }
        return $string;
    }

Usage Example

Exemplo n.º 1
0
 public function __construct($model = '', $fields = '', $zip = null, $version = '0.6', $norm = true)
 {
     if (empty($model)) {
         trigger_error('Please provide a model');
         exit;
     }
     if (empty($fields)) {
         trigger_error('Please provide fields');
         exit;
     }
     $this->model->lowercase = strtolower($this->computerize(Inflect::singularize($model)));
     $this->model->capital = ucwords($this->computerize(Inflect::singularize($model)));
     $this->models->lowercase = strtolower($this->computerize(Inflect::pluralize($model)));
     $this->models->capital = ucwords($this->computerize(Inflect::pluralize($model)));
     $this->models->table = $this->computerize($this->models->lowercase);
     $this->models->human = $this->humanize($this->models->lowercase);
     $this->models->human_capital = $this->humanize($this->models->capital);
     $this->models->class = ucwords($this->computerize(Inflect::singularize($model), 'camelcase'));
     $this->models->migration = ucwords($this->computerize(Inflect::pluralize($model), 'camelcase'));
     $this->fields = $this->field_cleaner($fields);
     $this->zip = $zip;
     $this->version = $version;
     if ($this->version < '0.6') {
         $this->norm = false;
     } else {
         $this->norm = $norm;
     }
     $this->include_path = $_SERVER['DOCUMENT_ROOT'] . '/tools/_shared/admin_templates/' . $this->version . ($this->norm ? '_norm' : '') . '/';
     if (!file_exists($this->include_path)) {
         trigger_error('AI files for ' . $this->version . ($this->norm ? '_norm' : '') . ' doesn\'t exist.');
         exit;
     }
 }
All Usage Examples Of Inflect::pluralize