1
|
|
|
<?php namespace Arcanedev\LaravelMarkdown; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Support\Providers\PackageServiceProvider; |
4
|
|
|
use Illuminate\Contracts\Support\DeferrableProvider; |
5
|
|
|
use Illuminate\Support\Facades\Blade; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class LaravelMarkdownServiceProvider |
9
|
|
|
* |
10
|
|
|
* @package Arcanedev\LaravelMarkdown |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class LaravelMarkdownServiceProvider extends PackageServiceProvider implements DeferrableProvider |
14
|
|
|
{ |
15
|
|
|
/* ----------------------------------------------------------------- |
16
|
|
|
| Properties |
17
|
|
|
| ----------------------------------------------------------------- |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Package name. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $package = 'markdown'; |
26
|
|
|
|
27
|
|
|
/* ----------------------------------------------------------------- |
28
|
|
|
| Main Methods |
29
|
|
|
| ----------------------------------------------------------------- |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Register the service provider. |
34
|
|
|
*/ |
35
|
20 |
|
public function register(): void |
36
|
|
|
{ |
37
|
20 |
|
parent::register(); |
38
|
|
|
|
39
|
20 |
|
$this->registerConfig(); |
40
|
|
|
|
41
|
20 |
|
$this->singleton(Contracts\Parser::class, MarkdownParser::class); |
42
|
20 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Boot the service provider. |
46
|
|
|
*/ |
47
|
20 |
|
public function boot(): void |
48
|
|
|
{ |
49
|
20 |
|
$this->publishConfig(); |
50
|
|
|
|
51
|
20 |
|
$this->extendBladeDirectives(); |
52
|
20 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the services provided by the provider. |
56
|
|
|
* |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
4 |
|
public function provides(): array |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
4 |
|
Contracts\Parser::class, |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/* ----------------------------------------------------------------- |
67
|
|
|
| Other Methods |
68
|
|
|
| ----------------------------------------------------------------- |
69
|
|
|
*/ |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Register Blade directives. |
73
|
|
|
*/ |
74
|
20 |
|
private function extendBladeDirectives(): void |
75
|
|
|
{ |
76
|
|
|
Blade::directive('markdown', function ($markdown) { |
77
|
2 |
|
return empty($markdown) |
78
|
2 |
|
? '<?php markdown()->begin(); ?>' |
79
|
2 |
|
: "<?php echo markdown()->parse($markdown); ?>"; |
80
|
20 |
|
}); |
81
|
|
|
|
82
|
|
|
Blade::directive('endmarkdown', function () { |
83
|
2 |
|
return '<?php echo markdown()->end(); ?>'; |
84
|
20 |
|
}); |
85
|
20 |
|
} |
86
|
|
|
} |
87
|
|
|
|