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


PHP StringHelper::humanizeString方法代码示例

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


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

示例1: __construct

 /**
  * Constructs a node object
  * @param string|array $obj If $obj is a string it is used as the path for the constructed node formatted like: articles/tags/news. If $obj is an array, key value pairs will be assigned to node object properties
  * @param string $displayName ignored when $obj is an array
  */
 public function __construct($obj, $displayName = null)
 {
     if (!is_array($obj)) {
         $path = (string) $obj;
         $this->setPath($path);
         if ($displayName === null) {
             $displayName = StringHelper::humanizeString($this->getLastPathSegment());
         }
         $this->display_name = $displayName;
         $this->url = '/' . $this->path . '/';
     } else {
         $array = $obj;
         $arrayKeys = array_keys($array);
         $missingKeys = array();
         foreach ($this->required_constructor_array_keys as $requiredKey) {
             if (!in_array($requiredKey, $arrayKeys)) {
                 $missingKeys[] = $requiredKey;
             }
         }
         if (count($missingKeys)) {
             throw new \Navinator\Exception('Attempting to create ' . __CLASS__ . ' from invalid array. The required array key(s) were not found: ' . implode(', ', $missingKeys));
         }
         // remove keys in $array that are NOT in $this->default_constructor_array
         $filteredArray = array_intersect_key($array, $this->default_constructor_array);
         // merge with defaults to avoid undefined indexes
         $mergedArray = array_merge($this->default_constructor_array, $filteredArray);
         // use ->setPath to trim and validate the path
         $this->setPath($mergedArray['path']);
         unset($mergedArray['path']);
         foreach ($mergedArray as $key => $val) {
             $this->{$key} = $val;
         }
         if (!$this->display_name) {
             $this->display_name = StringHelper::humanizeString($this->getLastPathSegment());
         }
         if (!$this->url) {
             $this->url = '/' . $this->path . '/';
         }
     }
 }
开发者ID:unstoppablecarl,项目名称:navinator,代码行数:45,代码来源:Node.php

示例2: testHumanizeStr

 /**
  *
  * @dataProvider testHumanizeStrProvider
  */
 public function testHumanizeStr($str, $expected)
 {
     $this->assertEquals($expected, StringHelper::humanizeString($str));
 }
开发者ID:unstoppablecarl,项目名称:navinator,代码行数:8,代码来源:StringHelperTest.php


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