Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| HydeServiceProvider | |
100.00% |
27 / 27 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
| register | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
3 | |||
| boot | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
| discoverBladeViewsIn | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| storeCompiledSiteIn | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Hyde\Framework; |
| 4 | |
| 5 | use Composer\InstalledVersions; |
| 6 | use Hyde\Framework\Actions\CreatesDefaultDirectories; |
| 7 | use Hyde\Framework\Concerns\RegistersDefaultDirectories; |
| 8 | use Hyde\Framework\Contracts\AssetServiceContract; |
| 9 | use Hyde\Framework\Models\BladePage; |
| 10 | use Hyde\Framework\Models\DocumentationPage; |
| 11 | use Hyde\Framework\Models\MarkdownPage; |
| 12 | use Hyde\Framework\Models\MarkdownPost; |
| 13 | use Hyde\Framework\Services\AssetService; |
| 14 | use Illuminate\Support\ServiceProvider; |
| 15 | |
| 16 | /** |
| 17 | * Register and bootstrap Hyde application services. |
| 18 | */ |
| 19 | class HydeServiceProvider extends ServiceProvider |
| 20 | { |
| 21 | use RegistersDefaultDirectories; |
| 22 | |
| 23 | /** |
| 24 | * Register any application services. |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | public function register(): void |
| 29 | { |
| 30 | /** |
| 31 | * @deprecated |
| 32 | */ |
| 33 | $this->app->bind( |
| 34 | 'hyde.version', |
| 35 | function () { |
| 36 | return InstalledVersions::getPrettyVersion('hyde/hyde') ?: 'unreleased'; |
| 37 | } |
| 38 | ); |
| 39 | |
| 40 | /** |
| 41 | * @deprecated |
| 42 | */ |
| 43 | $this->app->bind( |
| 44 | 'framework.version', |
| 45 | function () { |
| 46 | return InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased'; |
| 47 | } |
| 48 | ); |
| 49 | |
| 50 | $this->app->singleton(AssetServiceContract::class, AssetService::class); |
| 51 | |
| 52 | $this->registerDefaultDirectories([ |
| 53 | BladePage::class => '_pages', |
| 54 | MarkdownPage::class => '_pages', |
| 55 | MarkdownPost::class => '_posts', |
| 56 | DocumentationPage::class => '_docs', |
| 57 | ]); |
| 58 | |
| 59 | $this->discoverBladeViewsIn('_pages'); |
| 60 | |
| 61 | $this->storeCompiledSiteIn(config( |
| 62 | 'hyde.site_output_path', Hyde::path('_site') |
| 63 | )); |
| 64 | |
| 65 | $this->commands([ |
| 66 | Commands\HydePublishHomepageCommand::class, |
| 67 | Commands\HydeUpdateConfigsCommand::class, |
| 68 | Commands\HydePublishViewsCommand::class, |
| 69 | Commands\HydeRebuildStaticSiteCommand::class, |
| 70 | Commands\HydeBuildStaticSiteCommand::class, |
| 71 | Commands\HydeBuildSitemapCommand::class, |
| 72 | Commands\HydeBuildRssFeedCommand::class, |
| 73 | Commands\HydeBuildSearchCommand::class, |
| 74 | Commands\HydeMakePostCommand::class, |
| 75 | Commands\HydeMakePageCommand::class, |
| 76 | Commands\HydeValidateCommand::class, |
| 77 | Commands\HydeInstallCommand::class, |
| 78 | Commands\HydeDebugCommand::class, |
| 79 | Commands\HydeServeCommand::class, |
| 80 | ]); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Bootstrap any application services. |
| 85 | * |
| 86 | * @return void |
| 87 | */ |
| 88 | public function boot(): void |
| 89 | { |
| 90 | if (config('hyde.create_default_directories', true)) { |
| 91 | (new CreatesDefaultDirectories)->__invoke(); |
| 92 | } |
| 93 | |
| 94 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'hyde'); |
| 95 | |
| 96 | $this->publishes([ |
| 97 | __DIR__.'/../config' => config_path(), |
| 98 | ], 'configs'); |
| 99 | |
| 100 | $this->publishes([ |
| 101 | __DIR__.'/../resources/views/layouts' => resource_path('views/vendor/hyde/layouts'), |
| 102 | ], 'hyde-layouts'); |
| 103 | |
| 104 | $this->publishes([ |
| 105 | __DIR__.'/../resources/views/components' => resource_path('views/vendor/hyde/components'), |
| 106 | ], 'hyde-components'); |
| 107 | |
| 108 | $this->publishes([ |
| 109 | __DIR__.'/../_pages/404.blade.php' => resource_path('views/pages/404.blade.php'), |
| 110 | ], 'hyde-page-404'); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * If you are loading Blade views from a different directory, |
| 115 | * you need to add the path to the view.php config. This is |
| 116 | * here done automatically when registering this provider. |
| 117 | */ |
| 118 | protected function discoverBladeViewsIn(string $directory): void |
| 119 | { |
| 120 | config(['view.paths' => array_merge( |
| 121 | config('view.paths', []), |
| 122 | [base_path($directory)] |
| 123 | )]); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * The absolute path to the directory when the compiled site is stored. |
| 128 | */ |
| 129 | protected function storeCompiledSiteIn(string $directory): void |
| 130 | { |
| 131 | StaticPageBuilder::$outputPath = $directory; |
| 132 | } |
| 133 | } |