1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ReliqArts\Docweaver\Service; |
6
|
|
|
|
7
|
|
|
use Illuminate\Contracts\Config\Repository as Config; |
8
|
|
|
use ReliqArts\Docweaver\Contract\ConfigProvider as ConfigProviderContract; |
9
|
|
|
use ReliqArts\Docweaver\Model\TemplateConfig; |
10
|
|
|
|
11
|
|
|
final class ConfigProvider implements ConfigProviderContract |
12
|
|
|
{ |
13
|
|
|
private const NAMESPACE = 'docweaver'; |
14
|
|
|
private const KEY_CACHE_KEY = 'cache.key'; |
15
|
|
|
private const KEY_DEBUG = 'debug'; |
16
|
|
|
private const KEY_TABLE_OF_CONTENTS_PAGE_NAME = 'doc.index'; |
17
|
|
|
private const KEY_VERSIONS_ALLOW_WORDED_DEFAULT = 'versions.allow_worded_default'; |
18
|
|
|
private const KEY_VIEW_MASTER_TEMPLATE = 'view.master_template'; |
19
|
|
|
private const KEY_ROUTE = 'route'; |
20
|
|
|
private const KEY_STORAGE_DIRECTORY = 'storage.dir'; |
21
|
|
|
private const KEY_ROUTE_BINDINGS = 'route.bindings'; |
22
|
|
|
private const KEY_ROUTE_NAME_INDEX = 'route.names.index'; |
23
|
|
|
private const KEY_ROUTE_NAME_PRODUCT_INDEX = 'route.names.product_index'; |
24
|
|
|
private const KEY_ROUTE_NAME_PRODUCT_PAGE = 'route.names.product_page'; |
25
|
|
|
private const KEY_ROUTE_PREFIX = 'route.prefix'; |
26
|
|
|
private const KEY_VIEW_INDEX_TITLE = 'view.docs_title'; |
27
|
|
|
private const KEY_VIEW_MASTER_SECTION = 'view.master_section'; |
28
|
|
|
private const KEY_VIEW_STYLE_STACK = 'view.style_stack'; |
29
|
|
|
private const KEY_VIEW_SCRIPT_STACK = 'view.script_stack'; |
30
|
|
|
private const KEY_VIEW_INDEX_INTRO = 'view.docs_intro'; |
31
|
|
|
private const KEY_VIEW_ACCENTS_PRODUCT_LINE = 'view.accents.product_line'; |
32
|
|
|
private const KEY_VIEW_ACCENTS_FOOTNOTES = 'view.accents.footnotes'; |
33
|
|
|
private const DEFAULT_INDEX_ROUTE_NAME = 'docs'; |
34
|
|
|
private const DEFAULT_PRODUCT_INDEX_ROUTE_NAME = 'docs.index'; |
35
|
|
|
private const DEFAULT_PRODUCT_PAGE_ROUTE_NAME = 'docs.show'; |
36
|
|
|
private const DEFAULT_ROUTE_PREFIX = 'docs'; |
37
|
|
|
private const DEFAULT_CACHE_KEY = 'docweaver.docs'; |
38
|
|
|
private const DEFAULT_TABLE_OF_CONTENTS_PAGE_NAME = 'documentation'; |
39
|
|
|
private const DEFAULT_INDEX_TITLE = 'Documentation'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var Config |
43
|
|
|
*/ |
44
|
|
|
private Config $config; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* ConfigProvider constructor. |
48
|
|
|
*/ |
49
|
|
|
public function __construct(Config $config) |
50
|
|
|
{ |
51
|
|
|
$this->config = $config; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get directory path to where documentation are stored. |
56
|
|
|
* |
57
|
|
|
* @param bool $absolute whether to return full |
58
|
|
|
*/ |
59
|
|
|
public function getDocumentationDirectory($absolute = false): string |
60
|
|
|
{ |
61
|
|
|
$path = $this->get(self::KEY_STORAGE_DIRECTORY); |
62
|
|
|
|
63
|
|
|
if ($absolute) { |
64
|
|
|
$path = base_path($path); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $path; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get route config. |
72
|
|
|
*/ |
73
|
|
|
public function getRouteConfig(): array |
74
|
|
|
{ |
75
|
|
|
return $this->get(self::KEY_ROUTE, []); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get route prefix for docs. |
80
|
|
|
*/ |
81
|
|
|
public function getRoutePrefix(): string |
82
|
|
|
{ |
83
|
|
|
return $this->get(self::KEY_ROUTE_PREFIX, self::DEFAULT_ROUTE_PREFIX); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get bindings for routes. |
88
|
|
|
*/ |
89
|
|
|
public function getRouteGroupBindings(array $bindings = []): array |
90
|
|
|
{ |
91
|
|
|
$defaults = ['prefix' => $this->getRoutePrefix()]; |
92
|
|
|
$bindings = array_merge($this->get(self::KEY_ROUTE_BINDINGS, []), $bindings); |
93
|
|
|
|
94
|
|
|
return array_merge($defaults, $bindings); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function isDebug(): bool |
98
|
|
|
{ |
99
|
|
|
return $this->get(self::KEY_DEBUG, false); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function isWordedDefaultVersionAllowed(): bool |
103
|
|
|
{ |
104
|
|
|
return $this->get(self::KEY_VERSIONS_ALLOW_WORDED_DEFAULT, false); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getIndexRouteName(): string |
108
|
|
|
{ |
109
|
|
|
return $this->get(self::KEY_ROUTE_NAME_INDEX, self::DEFAULT_INDEX_ROUTE_NAME); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getProductIndexRouteName(): string |
113
|
|
|
{ |
114
|
|
|
return $this->get(self::KEY_ROUTE_NAME_PRODUCT_INDEX, self::DEFAULT_PRODUCT_INDEX_ROUTE_NAME); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getProductPageRouteName(): string |
118
|
|
|
{ |
119
|
|
|
return $this->get(self::KEY_ROUTE_NAME_PRODUCT_PAGE, self::DEFAULT_PRODUCT_PAGE_ROUTE_NAME); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getCacheKey(): string |
123
|
|
|
{ |
124
|
|
|
return $this->get(self::KEY_CACHE_KEY, self::DEFAULT_CACHE_KEY); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Page used as content index (or Table of Contents) for product documentation. |
129
|
|
|
*/ |
130
|
|
|
public function getContentIndexPageName(): string |
131
|
|
|
{ |
132
|
|
|
return $this->get(self::KEY_TABLE_OF_CONTENTS_PAGE_NAME, self::DEFAULT_TABLE_OF_CONTENTS_PAGE_NAME); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function getTemplateConfig(): TemplateConfig |
136
|
|
|
{ |
137
|
|
|
$masterTemplate = $this->get(self::KEY_VIEW_MASTER_TEMPLATE); |
138
|
|
|
$masterSection = $this->get(self::KEY_VIEW_MASTER_SECTION); |
139
|
|
|
$styleStack = $this->get(self::KEY_VIEW_STYLE_STACK, ''); |
140
|
|
|
$scriptStack = $this->get(self::KEY_VIEW_SCRIPT_STACK, ''); |
141
|
|
|
$indexTitle = $this->get(self::KEY_VIEW_INDEX_TITLE, self::DEFAULT_INDEX_TITLE); |
142
|
|
|
$indexIntro = $this->get(self::KEY_VIEW_INDEX_INTRO, ''); |
143
|
|
|
$showProductLine = $this->get(self::KEY_VIEW_ACCENTS_PRODUCT_LINE, true); |
144
|
|
|
$showFootnotes = $this->get(self::KEY_VIEW_ACCENTS_FOOTNOTES, true); |
145
|
|
|
|
146
|
|
|
return new TemplateConfig( |
147
|
|
|
$masterTemplate, |
148
|
|
|
$masterSection, |
149
|
|
|
$styleStack, |
150
|
|
|
$scriptStack, |
151
|
|
|
$indexTitle, |
152
|
|
|
$indexIntro, |
153
|
|
|
$showProductLine, |
154
|
|
|
$showFootnotes |
155
|
|
|
); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param mixed $default |
160
|
|
|
* |
161
|
|
|
* @return mixed |
162
|
|
|
*/ |
163
|
|
|
private function get(?string $key, $default = null) |
164
|
|
|
{ |
165
|
|
|
if (empty($key)) { |
166
|
|
|
return $this->config->get(self::NAMESPACE, []); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $this->config->get( |
170
|
|
|
sprintf('%s.%s', self::NAMESPACE, $key), |
171
|
|
|
$default |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|