1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Helpers; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Hyde; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Allows features to be enabled and disabled in a simple object-oriented manner. |
9
|
|
|
* |
10
|
|
|
* @see \Hyde\Framework\Testing\Feature\ConfigurableFeaturesTest |
11
|
|
|
* |
12
|
|
|
* Based entirely on Laravel Jetstream (License MIT) |
13
|
|
|
* @see https://jetstream.laravel.com/ |
14
|
|
|
*/ |
15
|
|
|
class Features |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Determine if the given specified is enabled. |
19
|
|
|
* |
20
|
|
|
* @param string $feature |
21
|
|
|
* @return bool |
22
|
|
|
*/ |
23
|
|
|
public static function enabled(string $feature): bool |
24
|
|
|
{ |
25
|
|
|
return in_array($feature, config('hyde.features', [ |
26
|
|
|
// Page Modules |
27
|
|
|
static::blogPosts(), |
28
|
|
|
static::bladePages(), |
29
|
|
|
static::markdownPages(), |
30
|
|
|
static::documentationPages(), |
31
|
|
|
// static::dataCollections(), |
32
|
|
|
|
33
|
|
|
// Frontend Features |
34
|
|
|
static::darkmode(), |
35
|
|
|
static::documentationSearch(), |
36
|
|
|
|
37
|
|
|
// Integrations |
38
|
|
|
static::torchlight(), |
39
|
|
|
])); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// ================================================ |
43
|
|
|
// Determine if a given feature is enabled. |
44
|
|
|
// ================================================ |
45
|
|
|
|
46
|
|
|
public static function hasBlogPosts(): bool |
47
|
|
|
{ |
48
|
|
|
return static::enabled(static::blogPosts()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public static function hasBladePages(): bool |
52
|
|
|
{ |
53
|
|
|
return static::enabled(static::bladePages()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public static function hasMarkdownPages(): bool |
57
|
|
|
{ |
58
|
|
|
return static::enabled(static::markdownPages()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public static function hasDocumentationPages(): bool |
62
|
|
|
{ |
63
|
|
|
return static::enabled(static::documentationPages()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public static function hasDataCollections(): bool |
67
|
|
|
{ |
68
|
|
|
return static::enabled(static::dataCollections()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public static function hasDocumentationSearch(): bool |
72
|
|
|
{ |
73
|
|
|
return static::enabled(static::documentationSearch()) |
74
|
|
|
&& static::hasDocumentationPages(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public static function hasDarkmode(): bool |
78
|
|
|
{ |
79
|
|
|
return static::enabled(static::darkmode()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Torchlight is by default enabled automatically when an API token |
84
|
|
|
* is set in the .env file but is disabled when running tests. |
85
|
|
|
*/ |
86
|
|
|
public static function hasTorchlight(): bool |
87
|
|
|
{ |
88
|
|
|
return static::enabled(static::torchlight()) |
89
|
|
|
&& (config('torchlight.token') !== null) |
90
|
|
|
&& (app('env') !== 'testing'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
// ================================================ |
94
|
|
|
// Enable a given feature to be used in the config. |
95
|
|
|
// ================================================ |
96
|
|
|
|
97
|
|
|
public static function blogPosts(): string |
98
|
|
|
{ |
99
|
|
|
return 'blog-posts'; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public static function bladePages(): string |
103
|
|
|
{ |
104
|
|
|
return 'blade-pages'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public static function markdownPages(): string |
108
|
|
|
{ |
109
|
|
|
return 'markdown-pages'; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public static function documentationPages(): string |
113
|
|
|
{ |
114
|
|
|
return 'documentation-pages'; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public static function documentationSearch(): string |
118
|
|
|
{ |
119
|
|
|
return 'documentation-search'; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public static function dataCollections(): string |
123
|
|
|
{ |
124
|
|
|
return 'data-collections'; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public static function darkmode(): string |
128
|
|
|
{ |
129
|
|
|
return 'darkmode'; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public static function torchlight(): string |
133
|
|
|
{ |
134
|
|
|
return 'torchlight'; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
// ================================================ |
138
|
|
|
// Dynamic features. |
139
|
|
|
// ================================================ |
140
|
|
|
|
141
|
|
|
/** Can a sitemap be generated? */ |
142
|
|
|
public static function sitemap(): bool |
143
|
|
|
{ |
144
|
|
|
return Hyde::hasSiteUrl() |
145
|
|
|
&& config('site.generate_sitemap', true) |
146
|
|
|
&& extension_loaded('simplexml'); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** Can an RSS feed be generated? */ |
150
|
|
|
public static function rss(): bool |
151
|
|
|
{ |
152
|
|
|
return Hyde::hasSiteUrl() |
153
|
|
|
&& static::hasBlogPosts() |
154
|
|
|
&& config('hyde.generate_rss_feed', true) |
155
|
|
|
&& extension_loaded('simplexml'); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|