Components.php 959 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Modules\Common\Repository\Options;
  3. use Catch\CatchAdmin;
  4. use Illuminate\Support\Facades\File;
  5. use Illuminate\Support\Str;
  6. class Components implements OptionInterface
  7. {
  8. /**
  9. * @var array|string[]
  10. */
  11. protected array $components = [
  12. [
  13. 'label' => 'layout',
  14. 'value' => '/admin/layout/index.vue'
  15. ]
  16. ];
  17. public function get(): array
  18. {
  19. if ($module = request()->get('module')) {
  20. $components = File::glob(CatchAdmin::getModuleViewsPath($module).'*'.DIRECTORY_SEPARATOR.'*.vue');
  21. foreach ($components as $component) {
  22. $this->components[] = [
  23. 'label' => Str::of($component)->explode(DIRECTORY_SEPARATOR)->pop(2)->pop(),
  24. 'value' => Str::of($component)->replace(CatchAdmin::moduleRootPath(), '')->prepend('/')
  25. ];
  26. }
  27. }
  28. return $this->components;
  29. }
  30. }