ParamHelpers.php 971 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Mpociot\ApiDoc\Tools\Traits;
  3. trait ParamHelpers {
  4. /**
  5. * Create proper arrays from dot-noted parameter names
  6. *
  7. * @param array $params
  8. * @return array
  9. */
  10. protected function cleanParams(array $params)
  11. {
  12. $values = [];
  13. foreach ($params as $name => $details) {
  14. $this->cleanValueFrom($name, $details['value'], $values);
  15. }
  16. return $values;
  17. }
  18. /**
  19. * Converts dot notation names to arrays and sets the value at the right depth
  20. *
  21. * @param string $name
  22. * @param mixed $value
  23. * @param array $values The array that holds the result
  24. * @return void
  25. */
  26. protected function cleanValueFrom($name, $value, array &$values = [])
  27. {
  28. if (str_contains($name, '[')) {
  29. $name = str_replace(['][', '[', ']', '..'], ['.', '.', '', '.*.'], $name);
  30. }
  31. array_set($values, str_replace('.*', '.0', $name), $value);
  32. }
  33. }