IgnitionConfig.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Facade\Ignition;
  3. use Illuminate\Contracts\Support\Arrayable;
  4. use Illuminate\Support\Arr;
  5. class IgnitionConfig implements Arrayable
  6. {
  7. /** @var array */
  8. protected $options;
  9. public function __construct(array $options = [])
  10. {
  11. $this->options = $this->mergeWithDefaultConfig($options);
  12. }
  13. public function getEditor(): ?string
  14. {
  15. return Arr::get($this->options, 'editor');
  16. }
  17. public function getRemoteSitesPath(): ?string
  18. {
  19. return Arr::get($this->options, 'remote_sites_path');
  20. }
  21. public function getLocalSitesPath(): ?string
  22. {
  23. return Arr::get($this->options, 'local_sites_path');
  24. }
  25. public function getTheme(): ?string
  26. {
  27. return Arr::get($this->options, 'theme');
  28. }
  29. public function getEnableShareButton(): bool
  30. {
  31. if (! app()->isBooted()) {
  32. return false;
  33. }
  34. return Arr::get($this->options, 'enable_share_button', true);
  35. }
  36. public function getEnableRunnableSolutions(): bool
  37. {
  38. $enabled = Arr::get($this->options, 'enable_runnable_solutions', null);
  39. if ($enabled === null) {
  40. $enabled = config('app.debug');
  41. }
  42. return $enabled ?? false;
  43. }
  44. public function toArray(): array
  45. {
  46. return [
  47. 'editor' => $this->getEditor(),
  48. 'remoteSitesPath' => $this->getRemoteSitesPath(),
  49. 'localSitesPath' => $this->getLocalSitesPath(),
  50. 'theme' => $this->getTheme(),
  51. 'enableShareButton' => $this->getEnableShareButton(),
  52. 'enableRunnableSolutions' => $this->getEnableRunnableSolutions(),
  53. 'directorySeparator' => DIRECTORY_SEPARATOR,
  54. ];
  55. }
  56. protected function mergeWithDefaultConfig(array $options = []): array
  57. {
  58. return array_merge(config('ignition') ?: include __DIR__.'/../config/ignition.php', $options);
  59. }
  60. }