1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of laravel.su package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace App\Providers; |
12
|
|
|
|
13
|
|
|
use cebe\markdown\GithubMarkdown; |
14
|
|
|
use App\Models\Docs\ContentObserver; |
15
|
|
|
use Illuminate\Support\ServiceProvider; |
16
|
|
|
use App\Services\ContentRenderer\RawTextRenderer; |
17
|
|
|
use App\Services\ContentRenderer\MarkdownRenderer; |
18
|
|
|
use App\Services\ContentRenderer\LaravelDocsRenderer; |
19
|
|
|
use App\Services\ContentRenderer\ContentRenderInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class ContentRendererServiceProvider. |
23
|
|
|
*/ |
24
|
|
|
class ContentRendererServiceProvider extends ServiceProvider |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
|
|
public function register(): void |
30
|
|
|
{ |
31
|
|
|
$this->registerDefaultBehaviour(); |
32
|
|
|
|
33
|
|
|
// Documentation renderer |
34
|
|
|
$this->app->when(ContentObserver::class) |
35
|
|
|
->needs(ContentRenderInterface::class) |
36
|
|
|
->give(function () { |
37
|
|
|
return new LaravelDocsRenderer(new GithubMarkdown()); |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
// Tips content renderer |
41
|
|
|
$this->app->when(RawTextRenderer::class) |
42
|
|
|
->needs(ContentRenderInterface::class) |
43
|
|
|
->give(function() { |
44
|
|
|
return new RawTextRenderer(new GithubMarkdown()); |
45
|
|
|
}); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
private function registerDefaultBehaviour() |
52
|
|
|
{ |
53
|
|
|
$this->app->singleton(MarkdownRenderer::class, function () { |
54
|
|
|
return new MarkdownRenderer(new GithubMarkdown()); |
55
|
|
|
}); |
56
|
|
|
|
57
|
|
|
$this->app->alias(MarkdownRenderer::class, ContentRenderInterface::class); |
58
|
|
|
$this->app->alias(MarkdownRenderer::class, 'md'); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|