Completed
Push — master ( 9d15b5...b28445 )
by ARCANEDEV
12s
created

LaravelMarkdownServiceProvider::getBasePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php namespace Arcanedev\LaravelMarkdown;
2
3
use Arcanedev\Support\PackageServiceProvider;
4
use Parsedown;
5
6
/**
7
 * Class     LaravelMarkdownServiceProvider
8
 *
9
 * @package  Arcanedev\LaravelMarkdown
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class LaravelMarkdownServiceProvider extends PackageServiceProvider
13
{
14
    /* -----------------------------------------------------------------
15
     |  Properties
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * Package name.
21
     *
22
     * @var string
23
     */
24
    protected $package = 'markdown';
25
26
    /**
27
     * Indicates if loading of the provider is deferred.
28
     *
29
     * @var bool
30
     */
31
    protected $defer   = true;
32
33
    /* -----------------------------------------------------------------
34
     |  Main Methods
35
     | -----------------------------------------------------------------
36
     */
37
38
    /**
39
     * Register the service provider.
40
     */
41 30
    public function register()
42
    {
43 30
        parent::register();
44
45 30
        $this->registerConfig();
46
47 30
        $this->registerMarkdownParser();
48 30
    }
49
50
    /**
51
     * Boot the service provider.
52
     */
53 30
    public function boot()
54
    {
55 30
        parent::boot();
56
57 30
        $this->publishConfig();
58 30
        $this->registerBladeDirectives();
59 30
    }
60
61
    /**
62
     * Get the services provided by the provider.
63
     *
64
     * @return array
65
     */
66 4
    public function provides()
67
    {
68
        return [
69 4
            Contracts\Parser::class,
70
        ];
71
    }
72
73
    /* -----------------------------------------------------------------
74
     |  Other Methods
75
     | -----------------------------------------------------------------
76
     */
77
78
    /**
79
     * Register the Markdown parser.
80
     */
81
    private function registerMarkdownParser()
82
    {
83 30
        $this->singleton(Contracts\Parser::class, function () {
84 26
            return new MarkdownParser(new Parsedown);
85 30
        });
86 30
    }
87
88
    /**
89
     * Register Blade directives.
90
     */
91 30
    private function registerBladeDirectives()
92
    {
93
        /** @var  \Illuminate\View\Compilers\BladeCompiler  $blade */
94 30
        $blade = $this->app['view']->getEngineResolver()->resolve('blade')->getCompiler();
95
96 30
        $blade->directive('parsedown', function ($markdown) {
97 2
            return "<?php echo markdown()->parse($markdown); ?>";
98 30
        });
99
100 30
        $blade->directive('markdown', function () {
101 2
            return '<?php markdown()->begin(); ?>';
102 30
        });
103
104 30
        $blade->directive('endmarkdown', function () {
105 2
            return '<?php echo markdown()->end(); ?>';
106 30
        });
107
    }
108
}
109