Repository navigation
Expand file tree
/
Copy pathLayout.php
More file actions
81 lines (62 loc) · 2.32 KB
/
Copy pathLayout.php
File metadata and controls
81 lines (62 loc) · 2.32 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
74
75
76
77
78
79
80
81
<?php
declare(strict_types=1);
namespace ItalyStrap\ThemeJsonGenerator\Settings;
use ItalyStrap\ThemeJsonGenerator\Schema\ThemeSchemaCoverage;
use ItalyStrap\ThemeJsonGenerator\Settings;
final readonly class Layout
{
use ScopedSettingsWriterTrait;
public const SECTION = 'layout';
public const ALLOW_CUSTOM_CONTENT_AND_WIDE_SIZE = 'allowCustomContentAndWideSize';
public const ALLOW_EDITING = 'allowEditing';
public const CONTENT_SIZE = 'contentSize';
public const WIDE_SIZE = 'wideSize';
public function __construct(
private Settings $settings,
private PresetsInterface $presets,
) {
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::CONTENT_SIZE])]
public function contentSize(string $keyOrValue): self
{
$this->set(self::CONTENT_SIZE, $this->resolveSize($keyOrValue));
return $this;
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::WIDE_SIZE])]
public function wideSize(string $keyOrValue): self
{
$this->set(self::WIDE_SIZE, $this->resolveSize($keyOrValue));
return $this;
}
private function resolveSize(string $keyOrValue): mixed
{
$size = $this->presets->get($keyOrValue);
if ($size instanceof PresetInterface) {
return $size->var();
}
if ($size === null) {
return $keyOrValue;
}
return $size;
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::ALLOW_EDITING])]
public function enableEditing(): self
{
return $this->setBoolean(self::ALLOW_EDITING, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::ALLOW_EDITING])]
public function disableEditing(): self
{
return $this->setBoolean(self::ALLOW_EDITING, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::ALLOW_CUSTOM_CONTENT_AND_WIDE_SIZE])]
public function enableCustomContentAndWideSize(): self
{
return $this->setBoolean(self::ALLOW_CUSTOM_CONTENT_AND_WIDE_SIZE, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::ALLOW_CUSTOM_CONTENT_AND_WIDE_SIZE])]
public function disableCustomContentAndWideSize(): self
{
return $this->setBoolean(self::ALLOW_CUSTOM_CONTENT_AND_WIDE_SIZE, false);
}
}