|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Hyde\Framework; |
|
6
|
|
|
|
|
7
|
|
|
use Hyde\Console\HydeConsoleServiceProvider; |
|
8
|
|
|
use Hyde\Facades\Features; |
|
9
|
|
|
use Hyde\Foundation\HydeKernel; |
|
10
|
|
|
use Hyde\Foundation\Providers\ConfigurationServiceProvider; |
|
11
|
|
|
use Hyde\Framework\Concerns\RegistersFileLocations; |
|
12
|
|
|
use Hyde\Framework\Services\AssetService; |
|
13
|
|
|
use Hyde\Framework\Views\Components\LinkComponent; |
|
14
|
|
|
use Hyde\Hyde; |
|
15
|
|
|
use Hyde\Markdown\MarkdownConverter; |
|
16
|
|
|
use Hyde\Pages\BladePage; |
|
17
|
|
|
use Hyde\Pages\DocumentationPage; |
|
18
|
|
|
use Hyde\Pages\HtmlPage; |
|
19
|
|
|
use Hyde\Pages\MarkdownPage; |
|
20
|
|
|
use Hyde\Pages\MarkdownPost; |
|
21
|
|
|
use Illuminate\Support\Facades\Blade; |
|
22
|
|
|
use Illuminate\Support\ServiceProvider; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Register and bootstrap Hyde application services. |
|
26
|
|
|
*/ |
|
27
|
|
|
class HydeServiceProvider extends ServiceProvider |
|
28
|
|
|
{ |
|
29
|
|
|
use RegistersFileLocations; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Register any application services. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function register(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->initializeConfiguration(); |
|
37
|
|
|
|
|
38
|
|
|
$this->app->singleton(AssetService::class, AssetService::class); |
|
39
|
|
|
|
|
40
|
|
|
$this->app->singleton(MarkdownConverter::class, function (): MarkdownConverter { |
|
41
|
|
|
return new MarkdownConverter(); |
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
Hyde::setSourceRoot(config('hyde.source_root', '')); |
|
45
|
|
|
|
|
46
|
|
|
$this->registerPageModels(); |
|
47
|
|
|
|
|
48
|
|
|
$this->registerSourceDirectories([ |
|
49
|
|
|
HtmlPage::class => '_pages', |
|
50
|
|
|
BladePage::class => '_pages', |
|
51
|
|
|
MarkdownPage::class => '_pages', |
|
52
|
|
|
MarkdownPost::class => '_posts', |
|
53
|
|
|
DocumentationPage::class => '_docs', |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
$this->registerOutputDirectories([ |
|
57
|
|
|
HtmlPage::class => '', |
|
58
|
|
|
BladePage::class => '', |
|
59
|
|
|
MarkdownPage::class => '', |
|
60
|
|
|
MarkdownPost::class => 'posts', |
|
61
|
|
|
DocumentationPage::class => config('docs.output_directory', 'docs'), |
|
62
|
|
|
]); |
|
63
|
|
|
|
|
64
|
|
|
$this->storeCompiledSiteIn(config('site.output_directory', '_site')); |
|
65
|
|
|
|
|
66
|
|
|
$this->useMediaDirectory(config('site.media_directory', '_media')); |
|
67
|
|
|
|
|
68
|
|
|
$this->discoverBladeViewsIn(BladePage::sourceDirectory()); |
|
69
|
|
|
|
|
70
|
|
|
$this->registerModuleServiceProviders(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Bootstrap any application services. |
|
75
|
|
|
*/ |
|
76
|
|
|
public function boot(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$this->loadViewsFrom(__DIR__.'/../../resources/views', 'hyde'); |
|
79
|
|
|
|
|
80
|
|
|
$this->publishes([ |
|
81
|
|
|
__DIR__.'/../../config' => config_path(), |
|
82
|
|
|
], 'configs'); |
|
83
|
|
|
|
|
84
|
|
|
$this->publishes([ |
|
85
|
|
|
__DIR__.'/../../resources/views/layouts' => resource_path('views/vendor/hyde/layouts'), |
|
86
|
|
|
], 'hyde-layouts'); |
|
87
|
|
|
|
|
88
|
|
|
$this->publishes([ |
|
89
|
|
|
__DIR__.'/../../resources/views/components' => resource_path('views/vendor/hyde/components'), |
|
90
|
|
|
], 'hyde-components'); |
|
91
|
|
|
|
|
92
|
|
|
$this->publishes([ |
|
93
|
|
|
Hyde::vendorPath('resources/views/pages/404.blade.php') => Hyde::path('_pages/404.blade.php'), |
|
94
|
|
|
], 'hyde-page-404'); |
|
95
|
|
|
|
|
96
|
|
|
$this->publishes([ |
|
97
|
|
|
Hyde::vendorPath('resources/views/homepages/welcome.blade.php') => Hyde::path('_pages/index.blade.php'), |
|
98
|
|
|
], 'hyde-welcome-page'); |
|
99
|
|
|
|
|
100
|
|
|
$this->publishes([ |
|
101
|
|
|
Hyde::vendorPath('resources/views/homepages/post-feed.blade.php') => Hyde::path('_pages/index.blade.php'), |
|
102
|
|
|
], 'hyde-posts-page'); |
|
103
|
|
|
|
|
104
|
|
|
$this->publishes([ |
|
105
|
|
|
Hyde::vendorPath('resources/views/homepages/blank.blade.php') => Hyde::path('_pages/index.blade.php'), |
|
106
|
|
|
], 'hyde-blank-page'); |
|
107
|
|
|
|
|
108
|
|
|
Blade::component('link', LinkComponent::class); |
|
109
|
|
|
|
|
110
|
|
|
HydeKernel::getInstance()->readyToBoot(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
protected function initializeConfiguration(): void |
|
114
|
|
|
{ |
|
115
|
|
|
$this->app->register(ConfigurationServiceProvider::class); |
|
116
|
|
|
$this->getConfigurationProvider()->initialize(); |
|
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Register the page model classes that Hyde should use. |
|
121
|
|
|
*/ |
|
122
|
|
|
protected function registerPageModels(): void |
|
123
|
|
|
{ |
|
124
|
|
|
// TODO use the hyde facade once it gets the method annotations |
|
125
|
|
|
|
|
126
|
|
|
if (Features::hasHtmlPages()) { |
|
127
|
|
|
HydeKernel::getInstance()->registerPageClass(HtmlPage::class); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
if (Features::hasBladePages()) { |
|
131
|
|
|
HydeKernel::getInstance()->registerPageClass(BladePage::class); |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
if (Features::hasMarkdownPages()) { |
|
135
|
|
|
HydeKernel::getInstance()->registerPageClass(MarkdownPage::class); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
if (Features::hasMarkdownPosts()) { |
|
139
|
|
|
HydeKernel::getInstance()->registerPageClass(MarkdownPost::class); |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
if (Features::hasDocumentationPages()) { |
|
143
|
|
|
HydeKernel::getInstance()->registerPageClass(DocumentationPage::class); |
|
|
|
|
|
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Register module service providers. |
|
149
|
|
|
*/ |
|
150
|
|
|
protected function registerModuleServiceProviders(): void |
|
151
|
|
|
{ |
|
152
|
|
|
$this->app->register(HydeConsoleServiceProvider::class); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
protected function getConfigurationProvider(): ServiceProvider|ConfigurationServiceProvider |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->app->getProvider(ConfigurationServiceProvider::class); |
|
|
|
|
|
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|