Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types = 1);
- namespace IzyPixel\Services\Traits;
- use Illuminate\Support\Str;
- /**
- * Class TranslatableConstants
- *
- * @package IzyPixel\Services\Traits
- */
- trait TranslatableConstants
- {
- /**
- * @param string $class
- * @param string $contains
- * @param string $transKey
- *
- * @return array
- * @throws \Exception
- */
- protected function getConstants(
- string $class,
- string $contains,
- string $transKey
- ): array {
- $constants = [];
- $lengthContains = Str::length($contains);
- $classConstants = get_class_constants_start_with($class, $contains);
- foreach ($classConstants as $key => $value) {
- $key = Str::lower(Str::substr($key, $lengthContains));
- $constants[$value] = [
- 'key' => $key,
- 'name' => trans($transKey.$key),
- ];
- }
- return $constants;
- }
- }
Add Comment
Please, Sign In to add comment