Helper.php 862 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace League\CLImate\Util;
  3. class Helper
  4. {
  5. /**
  6. * @param string|array $var
  7. *
  8. * @return array
  9. */
  10. public static function toArray($var)
  11. {
  12. if (!is_array($var)) {
  13. return [$var];
  14. }
  15. return $var;
  16. }
  17. /**
  18. * Flatten a multi-dimensional array
  19. *
  20. * @param array $arr
  21. *
  22. * @return array
  23. */
  24. public static function flatten(array $arr)
  25. {
  26. $flattened = [];
  27. array_walk_recursive($arr, function ($a) use (&$flattened) {
  28. $flattened[] = $a;
  29. });
  30. return $flattened;
  31. }
  32. /**
  33. * Convert a string to snake case
  34. *
  35. * @param string $str
  36. *
  37. * @return string
  38. */
  39. public static function snakeCase($str)
  40. {
  41. return strtolower(preg_replace('/(.)([A-Z])/', '$1_$2', $str));
  42. }
  43. }