yii\helpers\BaseInflector::singularize PHP Метод

singularize() публичный статический Метод

Returns the singular of the $word
public static singularize ( string $word ) : string
$word string the english word to singularize
Результат string Singular noun.
    public static function singularize($word)
    {
        $result = array_search($word, static::$specials, true);
        if ($result !== false) {
            return $result;
        }
        foreach (static::$singulars as $rule => $replacement) {
            if (preg_match($rule, $word)) {
                return preg_replace($rule, $replacement, $word);
            }
        }
        return $word;
    }

Usage Example

 /**
  * Gets the source and returns a string. If a relation is defined adjusts the source in order
  * to match that url.
  *
  * Base source name is defined by the table name in the model
  *
  * @return string
  */
 public function getSource()
 {
     /* @var $modelClass ActiveRecord */
     $modelClass = $this->modelClass;
     $source = $modelClass::tableName();
     if (!empty($this->where['id'])) {
         $source = BaseInflector::singularize($source) . '/' . $this->where['id'];
         unset($this->where['id']);
     } else {
         if (!empty($this->link)) {
             $pre = '';
             foreach ($this->link as $key => $link) {
                 $pre .= "{$key}/{$link}";
             }
             $source = $pre . '/' . $source;
         }
     }
     return 'discovery/' . $source;
 }