Completed
Push — master ( fb455c...75e31d )
by ARCANEDEV
06:38
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
     * Package name.
20
     *
21
     * @var string
22
     */
23
    protected $package = 'markdown';
24
25
    /**
26
     * Indicates if loading of the provider is deferred.
27
     *
28
     * @var bool
29
     */
30
    protected $defer   = true;
31
32
    /* ------------------------------------------------------------------------------------------------
33
     |  Getters & Setters
34
     | ------------------------------------------------------------------------------------------------
35
     */
36
    /**
37
     * Get the base path of the package.
38
     *
39
     * @return string
40
     */
41 126
    public function getBasePath()
42
    {
43 126
        return dirname(__DIR__);
44
    }
45
46
    /* ------------------------------------------------------------------------------------------------
47
     |  Main Functions
48
     | ------------------------------------------------------------------------------------------------
49
     */
50
    /**
51
     * Register the service provider.
52
     */
53 126
    public function register()
54
    {
55 126
        $this->registerConfig();
56
57
        $this->singleton(Contracts\Parser::class, function () {
58 108
            return new MarkdownParser(new Parsedown);
59 126
        });
60
61 126
        $this->singleton('arcanedev.markdown', Contracts\Parser::class);
62 126
    }
63
64
    /**
65
     * Boot the service provider.
66
     */
67 126
    public function boot()
68
    {
69 126
        $this->publishConfig();
70 126
        $this->registerBladeDirectives();
71 126
    }
72
73
    /**
74
     * Get the services provided by the provider.
75
     *
76
     * @return array
77
     */
78 18
    public function provides()
79
    {
80
        return [
81 18
            Contracts\Parser::class,
82 6
            'arcanedev.markdown',
83 6
        ];
84
    }
85
86
    /* ------------------------------------------------------------------------------------------------
87
     |  Other Functions
88
     | ------------------------------------------------------------------------------------------------
89
     */
90
    /**
91
     * Register Blade directives.
92
     */
93 126
    private function registerBladeDirectives()
94
    {
95
        /** @var  \Illuminate\View\Compilers\BladeCompiler  $blade */
96 126
        $blade = $this->app['view']->getEngineResolver()->resolve('blade')->getCompiler();
97
98
        $blade->directive('parsedown', function ($markdown) {
99 9
            return "<?php echo markdown()->parse($markdown); ?>";
100 126
        });
101
102
        $blade->directive('markdown', function () {
103 9
            return '<?php markdown()->begin(); ?>';
104 126
        });
105
106 126
        $blade->directive('endmarkdown', function () {
107 9
            return '<?php echo markdown()->end(); ?>';
108 126
        });
109 126
    }
110
}
111