Passed
Push — master ( 7ec0c0...20e830 )
by Caen
06:19 queued 03:05
created

HydeServiceProvider::getConfigurationProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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)->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

115
        $this->app->register(ConfigurationServiceProvider::class)->/** @scrutinizer ignore-call */ initialize();
Loading history...
116
    }
117
118
    /**
119
     * Register the page model classes that Hyde should use.
120
     */
121
    protected function registerPageModels(): void
122
    {
123
        // TODO use the hyde facade once it gets the method annotations
124
125
        if (Features::hasHtmlPages()) {
126
            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

126
            /** @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...
127
        }
128
129
        if (Features::hasBladePages()) {
130
            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

130
            /** @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...
131
        }
132
133
        if (Features::hasMarkdownPages()) {
134
            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

134
            /** @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...
135
        }
136
137
        if (Features::hasMarkdownPosts()) {
138
            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

138
            /** @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...
139
        }
140
141
        if (Features::hasDocumentationPages()) {
142
            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

142
            /** @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...
143
        }
144
    }
145
146
    /**
147
     * Register module service providers.
148
     */
149
    protected function registerModuleServiceProviders(): void
150
    {
151
        $this->app->register(HydeConsoleServiceProvider::class);
152
    }
153
}
154