Guest User

Untitled

a guest
Nov 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2. declare(strict_types = 1);
  3.  
  4. namespace IzyPixel\Services\Traits;
  5.  
  6. use Illuminate\Support\Str;
  7.  
  8. /**
  9. * Class TranslatableConstants
  10. *
  11. * @package IzyPixel\Services\Traits
  12. */
  13. trait TranslatableConstants
  14. {
  15. /**
  16. * @param string $class
  17. * @param string $contains
  18. * @param string $transKey
  19. *
  20. * @return array
  21. * @throws \Exception
  22. */
  23. protected function getConstants(
  24. string $class,
  25. string $contains,
  26. string $transKey
  27. ): array {
  28. $constants = [];
  29. $lengthContains = Str::length($contains);
  30. $classConstants = get_class_constants_start_with($class, $contains);
  31. foreach ($classConstants as $key => $value) {
  32. $key = Str::lower(Str::substr($key, $lengthContains));
  33. $constants[$value] = [
  34. 'key' => $key,
  35. 'name' => trans($transKey.$key),
  36. ];
  37. }
  38.  
  39. return $constants;
  40. }
  41. }
Add Comment
Please, Sign In to add comment