vendor/lm/util/src/Str.php line 41

Open in your IDE?
  1. <?php
  2. namespace Lm\Util;
  3. class Str
  4. {
  5.     /**
  6.      * Convert underscore_strings to camelCase (medial capitals).
  7.      *
  8.      * @link https://stackoverflow.com/questions/2791998/convert-string-with-dashes-to-camelcase
  9.      * @param string $str
  10.      * @return string
  11.      */
  12.     public static function snakeToCamel($str)
  13.     {
  14.         // Remove underscores, capitalize words, squash, lowercase first.
  15.         return lcfirst(str_replace(' '''ucwords(str_replace('_'' '$str))));
  16.     }
  17.     /**
  18.      * Convert underscore_strings to camelCase (medial capitals).
  19.      *
  20.      * @link https://stackoverflow.com/questions/2791998/convert-string-with-dashes-to-camelcase
  21.      * @param string $str
  22.      * @return string
  23.      */
  24.     public static function kebabToCamel($str)
  25.     {
  26.         // Remove underscores, capitalize words, squash, lowercase first.
  27.         return lcfirst(str_replace(' '''ucwords(str_replace('-'' '$str))));
  28.     }
  29.     /**
  30.      * カンマ区切り文字列(=csv)を文字列の配列に変換する
  31.      *
  32.      * @param string $str
  33.      * @param string $delimiter
  34.      * @return false|string[]
  35.      */
  36.     public static function csvToArray($str$delimiter ',')
  37.     {
  38.         //
  39.         $result explode($delimiter$str);
  40.         // TODO: オプション化 - 空白文字のみの要素は省略
  41.         $result array_filter($result, function ($col) {
  42.             return trim($col) !== '';
  43.         });
  44.         // TODO: オプション化 - 前後の空白文字はトリムする
  45.         $result array_map(function ($col) {
  46.             return trim($col);
  47.         }, $result);
  48.         //
  49.         $result array_values($result);
  50.         //
  51.         return $result;
  52.     }
  53.     /**
  54.      * @link https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
  55.      * @param $email
  56.      * @return false|int
  57.      */
  58.     public static function isValidEmailAddress($email)
  59.     {
  60.         return preg_match('/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/'$email);
  61.     }
  62. }