Passed
Push — master ( 3a6ce1...f9d3f0 )
by Caen
03:31 queued 12s
created

HydeServiceProvider::initializeConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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();
0 ignored issues
show
Bug introduced by
The method initialize() does not exist on Illuminate\Support\ServiceProvider. It seems like you code against a sub-type of Illuminate\Support\ServiceProvider such as Illuminate\Foundation\Su...rs\RouteServiceProvider or Hyde\Foundation\Provider...gurationServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

116
        $this->getConfigurationProvider()->/** @scrutinizer ignore-call */ initialize();
Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The function Hyde\Foundation\HydeKernel::registerPageClass() has been deprecated: This feature may be replaced by the {@see \Hyde\Foundation\Concerns\HydeExtension} system. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

127
            /** @scrutinizer ignore-deprecated */ HydeKernel::getInstance()->registerPageClass(HtmlPage::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
128
        }
129
130
        if (Features::hasBladePages()) {
131
            HydeKernel::getInstance()->registerPageClass(BladePage::class);
0 ignored issues
show
Deprecated Code introduced by
The function Hyde\Foundation\HydeKernel::registerPageClass() has been deprecated: This feature may be replaced by the {@see \Hyde\Foundation\Concerns\HydeExtension} system. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

131
            /** @scrutinizer ignore-deprecated */ HydeKernel::getInstance()->registerPageClass(BladePage::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
132
        }
133
134
        if (Features::hasMarkdownPages()) {
135
            HydeKernel::getInstance()->registerPageClass(MarkdownPage::class);
0 ignored issues
show
Deprecated Code introduced by
The function Hyde\Foundation\HydeKernel::registerPageClass() has been deprecated: This feature may be replaced by the {@see \Hyde\Foundation\Concerns\HydeExtension} system. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

135
            /** @scrutinizer ignore-deprecated */ HydeKernel::getInstance()->registerPageClass(MarkdownPage::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
136
        }
137
138
        if (Features::hasMarkdownPosts()) {
139
            HydeKernel::getInstance()->registerPageClass(MarkdownPost::class);
0 ignored issues
show
Deprecated Code introduced by
The function Hyde\Foundation\HydeKernel::registerPageClass() has been deprecated: This feature may be replaced by the {@see \Hyde\Foundation\Concerns\HydeExtension} system. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

139
            /** @scrutinizer ignore-deprecated */ HydeKernel::getInstance()->registerPageClass(MarkdownPost::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
140
        }
141
142
        if (Features::hasDocumentationPages()) {
143
            HydeKernel::getInstance()->registerPageClass(DocumentationPage::class);
0 ignored issues
show
Deprecated Code introduced by
The function Hyde\Foundation\HydeKernel::registerPageClass() has been deprecated: This feature may be replaced by the {@see \Hyde\Foundation\Concerns\HydeExtension} system. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

143
            /** @scrutinizer ignore-deprecated */ HydeKernel::getInstance()->registerPageClass(DocumentationPage::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
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);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->app->getPr...ServiceProvider::class) could return the type null which is incompatible with the type-hinted return Hyde\Foundation\Provider...Support\ServiceProvider. Consider adding an additional type-check to rule them out.
Loading history...
158
    }
159
}
160