Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Spatie\Ignition\Config;
4
 
5
use Illuminate\Contracts\Support\Arrayable;
6
use Spatie\Ignition\Contracts\ConfigManager;
7
use Throwable;
8
 
9
/** @implements Arrayable<string, string|null|bool|array<string, mixed>> */
10
class IgnitionConfig implements Arrayable
11
{
12
    private ConfigManager $manager;
13
 
14
    public static function loadFromConfigFile(): self
15
    {
16
        return (new self())->loadConfigFile();
17
    }
18
 
19
    /**
20
     * @param array<string, mixed> $options
21
     */
22
    public function __construct(protected array $options = [])
23
    {
24
        $defaultOptions = $this->getDefaultOptions();
25
 
26
        $this->options = array_merge($defaultOptions, $options);
27
        $this->manager = $this->initConfigManager();
28
    }
29
 
30
    public function setOption(string $name, string $value): self
31
    {
32
        $this->options[$name] = $value;
33
 
34
        return $this;
35
    }
36
 
37
    private function initConfigManager(): ConfigManager
38
    {
39
        try {
40
            /** @phpstan-ignore-next-line  */
41
            return app(ConfigManager::class);
42
        } catch (Throwable) {
43
            return new FileConfigManager();
44
        }
45
    }
46
 
47
    /** @param array<string, string> $options */
48
    public function merge(array $options): self
49
    {
50
        $this->options = array_merge($this->options, $options);
51
 
52
        return $this;
53
    }
54
 
55
    public function loadConfigFile(): self
56
    {
57
        $this->merge($this->getConfigOptions());
58
 
59
        return $this;
60
    }
61
 
62
    /** @return array<string, mixed> */
63
    public function getConfigOptions(): array
64
    {
65
        return $this->manager->load();
66
    }
67
 
68
    /**
69
     * @param array<string, mixed> $options
70
     * @return bool
71
     */
72
    public function saveValues(array $options): bool
73
    {
74
        return $this->manager->save($options);
75
    }
76
 
77
    public function hideSolutions(): bool
78
    {
79
        return $this->options['hide_solutions'] ?? false;
80
    }
81
 
82
    public function editor(): ?string
83
    {
84
        return $this->options['editor'] ?? null;
85
    }
86
 
87
    /**
88
     * @return array<string, mixed> $options
89
     */
90
    public function editorOptions(): array
91
    {
92
        return $this->options['editor_options'] ?? [];
93
    }
94
 
95
    public function remoteSitesPath(): ?string
96
    {
97
        return $this->options['remote_sites_path'] ?? null;
98
    }
99
 
100
    public function localSitesPath(): ?string
101
    {
102
        return $this->options['local_sites_path'] ?? null;
103
    }
104
 
105
    public function theme(): ?string
106
    {
107
        return $this->options['theme'] ?? null;
108
    }
109
 
110
    public function shareButtonEnabled(): bool
111
    {
112
        return (bool)($this->options['enable_share_button'] ?? false);
113
    }
114
 
115
    public function shareEndpoint(): string
116
    {
117
        return $this->options['share_endpoint']
118
            ?? $this->getDefaultOptions()['share_endpoint'];
119
    }
120
 
121
    public function runnableSolutionsEnabled(): bool
122
    {
123
        return (bool)($this->options['enable_runnable_solutions'] ?? false);
124
    }
125
 
126
    /** @return array<string, string|null|bool|array<string, mixed>> */
127
    public function toArray(): array
128
    {
129
        return [
130
            'editor' => $this->editor(),
131
            'theme' => $this->theme(),
132
            'hideSolutions' => $this->hideSolutions(),
133
            'remoteSitesPath' => $this->remoteSitesPath(),
134
            'localSitesPath' => $this->localSitesPath(),
135
            'enableShareButton' => $this->shareButtonEnabled(),
136
            'enableRunnableSolutions' => $this->runnableSolutionsEnabled(),
137
            'directorySeparator' => DIRECTORY_SEPARATOR,
138
            'editorOptions' => $this->editorOptions(),
139
            'shareEndpoint' => $this->shareEndpoint(),
140
        ];
141
    }
142
 
143
    /**
144
     * @return array<string, mixed> $options
145
     */
146
    protected function getDefaultOptions(): array
147
    {
148
        return [
149
            'share_endpoint' => 'https://flareapp.io/api/public-reports',
150
            'theme' => 'light',
151
            'editor' => 'vscode',
152
            'editor_options' => [
153
                'sublime' => [
154
                    'label' => 'Sublime',
155
                    'url' => 'subl://open?url=file://%path&line=%line',
156
                ],
157
                'textmate' => [
158
                    'label' => 'TextMate',
159
                    'url' => 'txmt://open?url=file://%path&line=%line',
160
                ],
161
                'emacs' => [
162
                    'label' => 'Emacs',
163
                    'url' => 'emacs://open?url=file://%path&line=%line',
164
                ],
165
                'macvim' => [
166
                    'label' => 'MacVim',
167
                    'url' => 'mvim://open/?url=file://%path&line=%line',
168
                ],
169
                'phpstorm' => [
170
                    'label' => 'PhpStorm',
171
                    'url' => 'phpstorm://open?file=%path&line=%line',
172
                ],
173
                'idea' => [
174
                    'label' => 'Idea',
175
                    'url' => 'idea://open?file=%path&line=%line',
176
                ],
177
                'vscode' => [
178
                    'label' => 'VS Code',
179
                    'url' => 'vscode://file/%path:%line',
180
                ],
181
                'vscode-insiders' => [
182
                    'label' => 'VS Code Insiders',
183
                    'url' => 'vscode-insiders://file/%path:%line',
184
                ],
185
                'vscode-remote' => [
186
                    'label' => 'VS Code Remote',
187
                    'url' => 'vscode://vscode-remote/%path:%line',
188
                ],
189
                'vscode-insiders-remote' => [
190
                    'label' => 'VS Code Insiders Remote',
191
                    'url' => 'vscode-insiders://vscode-remote/%path:%line',
192
                ],
193
                'vscodium' => [
194
                    'label' => 'VS Codium',
195
                    'url' => 'vscodium://file/%path:%line',
196
                ],
197
                'atom' => [
198
                    'label' => 'Atom',
199
                    'url' => 'atom://core/open/file?filename=%path&line=%line',
200
                ],
201
                'nova' => [
202
                    'label' => 'Nova',
203
                    'url' => 'nova://core/open/file?filename=%path&line=%line',
204
                ],
205
                'netbeans' => [
206
                    'label' => 'NetBeans',
207
                    'url' => 'netbeans://open/?f=%path:%line',
208
                ],
209
                'xdebug' => [
210
                    'label' => 'Xdebug',
211
                    'url' => 'xdebug://%path@%line',
212
                ],
213
            ],
214
        ];
215
    }
216
}