当前位置: 首页>>代码示例>>PHP>>正文


PHP Inflector::sentence方法代码示例

本文整理汇总了PHP中yii\helpers\Inflector::sentence方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::sentence方法的具体用法?PHP Inflector::sentence怎么用?PHP Inflector::sentence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\Inflector的用法示例。


在下文中一共展示了Inflector::sentence方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSentence

 public function testSentence()
 {
     $array = [];
     $this->assertEquals('', Inflector::sentence($array));
     $array = ['Spain'];
     $this->assertEquals('Spain', Inflector::sentence($array));
     $array = ['Spain', 'France'];
     $this->assertEquals('Spain and France', Inflector::sentence($array));
     $array = ['Spain', 'France', 'Italy'];
     $this->assertEquals('Spain, France and Italy', Inflector::sentence($array));
     $array = ['Spain', 'France', 'Italy', 'Germany'];
     $this->assertEquals('Spain, France, Italy and Germany', Inflector::sentence($array));
     $array = ['Spain', 'France'];
     $this->assertEquals('Spain or France', Inflector::sentence($array, ' or '));
     $array = ['Spain', 'France', 'Italy'];
     $this->assertEquals('Spain, France or Italy', Inflector::sentence($array, ' or '));
     $array = ['Spain', 'France'];
     $this->assertEquals('Spain and France', Inflector::sentence($array, ' and ', ' or ', ' - '));
     $array = ['Spain', 'France', 'Italy'];
     $this->assertEquals('Spain - France or Italy', Inflector::sentence($array, ' and ', ' or ', ' - '));
 }
开发者ID:howq,项目名称:yii2,代码行数:21,代码来源:InflectorTest.php

示例2: addComboNotUniqueError

 /**
  * Builds and adds [[comboNotUnique]] error message to the specified model attribute.
  * @param \yii\base\Model $model the data model.
  * @param string $attribute the name of the attribute.
  */
 private function addComboNotUniqueError($model, $attribute)
 {
     $attributeCombo = [];
     $valueCombo = [];
     foreach ($this->targetAttribute as $key => $value) {
         if (is_int($key)) {
             $attributeCombo[] = $model->getAttributeLabel($value);
             $valueCombo[] = '"' . $model->{$value} . '"';
         } else {
             $attributeCombo[] = $model->getAttributeLabel($key);
             $valueCombo[] = '"' . $model->{$key} . '"';
         }
     }
     $this->addError($model, $attribute, $this->message, ['attributes' => Inflector::sentence($attributeCombo), 'values' => implode('-', $valueCombo)]);
 }
开发者ID:yiisoft,项目名称:yii2,代码行数:20,代码来源:UniqueValidator.php

示例3: asTimeText

 /**
  * Formats time value with given unit to text.
  *
  * @param  mixed   $value time value to be formatted.
  * @param  integer $unit  unit type of value.
  * Must be one on the following: [[TIMETEXT_YEARS]], [[TIMETEXT_MONTHS]] or [[TIMETEXT_DAYS]].
  * @return string formatted time text.
  * @throws InvalidConfigException if no unit is given and [[timeTextUnit]] is not defined.
  */
 public function asTimeText($value, $unit = null)
 {
     if ($unit === null) {
         if ($this->timeTextUnit === null) {
             throw new InvalidConfigException('The unit for this formatter is not defined.');
         }
         $unit = $this->timeTextUnit;
     }
     $value = $this->normalizeNumericValue($value);
     $components = $this->getTimeComponents($value, $unit);
     $componentsText = [];
     if ($components[0] > 0) {
         $componentsText[] = Yii::t('asBase', '{a, plural, =1{1 year} other{# years}}', ['a' => $components[0]]);
     }
     if ($components[1] > 0) {
         $componentsText[] = Yii::t('asBase', '{m, plural, =1{1 month} other{# months}}', ['m' => $components[1]]);
     }
     if ($components[2] > 0) {
         $componentsText[] = Yii::t('asBase', '{d, plural, =1{1 day} other{# days}}', ['d' => $components[2]]);
     }
     return Inflector::sentence($componentsText);
 }
开发者ID:alesar-code,项目名称:yii2-base,代码行数:31,代码来源:Formatter.php


注:本文中的yii\helpers\Inflector::sentence方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。