This repository was archived by the owner on Aug 22, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSettingsRepository.php
More file actions
73 lines (57 loc) · 1.84 KB
/
SettingsRepository.php
File metadata and controls
73 lines (57 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace Codedge\MagicLink\Repositories;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Collection;
use Statamic\Facades\YAML;
final class SettingsRepository
{
const IS_ENABLED_KEY = 'enabled';
const EXPIRE_TIME_KEY = 'expireTime';
const ALLOWED_ADDRESSES = 'allowedAddresses';
const ALLOWED_DOMAINS = 'allowedDomains';
private array $defaultValues;
protected Filesystem $files;
protected string $path;
public function __construct(Filesystem $files)
{
$this->files = $files;
$this->path = storage_path('statamic-magiclink/settings.yaml');
$this->defaultValues = [
self::IS_ENABLED_KEY => false,
self::EXPIRE_TIME_KEY => config('statamic-magiclink.expire_time'),
self::ALLOWED_ADDRESSES => [],
self::ALLOWED_DOMAINS => [],
];
}
public function isEnabled(): bool
{
return $this->get()->get(self::IS_ENABLED_KEY);
}
public function expireTime(): int
{
return (int) $this->get()->get(self::EXPIRE_TIME_KEY);
}
public function allowedAddresses(): Collection
{
return collect($this->get()->get(self::ALLOWED_ADDRESSES));
}
public function allowedDomains(): Collection
{
return collect($this->get()->get(self::ALLOWED_DOMAINS));
}
public function get(): Collection
{
if (! $this->files->exists($this->path)) {
return collect($this->defaultValues);
}
return collect(YAML::parse($this->files->get($this->path)));
}
public function put(Collection $content)
{
if (! $this->files->isDirectory($dir = dirname($this->path))) {
$this->files->makeDirectory($dir);
}
return $this->files->put($this->path, YAML::dump($content->all()));
}
}