Passed
Push — master ( 0309cf...ba8f5f )
by Ilya
02:37
created

LaraflashServiceProvider::offerPublishing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Coderello\Laraflash\Providers;
4
5
use Illuminate\Foundation\Application;
6
use Illuminate\Support\ServiceProvider;
7
use Coderello\Laraflash\Laraflash\Laraflash;
8
use Coderello\Laraflash\Laraflash\LaraflashPreparer;
9
use Coderello\Laraflash\Laraflash\LaraflashRenderer;
10
use Coderello\Laraflash\FlashMessage\FlashMessageFactory;
11
use Coderello\Laraflash\Laraflash\LaraflashPreparerContract;
12
use Coderello\Laraflash\Laraflash\LaraflashRendererContract;
13
use Coderello\Laraflash\FlashMessage\ViewFlashMessageRenderer;
14
use Coderello\Laraflash\MessagesStorage\MessagesStorageManager;
15
use Coderello\Laraflash\MessagesStorage\SessionMessagesStorage;
16
use Coderello\Laraflash\MessagesStorage\MessagesStorageContract;
17
use Coderello\Laraflash\FlashMessage\FlashMessageFactoryContract;
18
use Coderello\Laraflash\FlashMessage\FlashMessageRendererContract;
19
20
class LaraflashServiceProvider extends ServiceProvider
21
{
22
    /**
23
     * Bootstrap any application services.
24
     *
25
     * @return void
26
     */
27 59
    public function boot()
28
    {
29 59
        $this->registerResources();
30
31 59
        $this->offerPublishing();
32 59
    }
33
34
    /**
35
     * Register any application services.
36
     *
37
     * @return void
38
     */
39 59
    public function register()
40
    {
41 59
        $this->registerBindings();
42
43 59
        $this->configure();
44 59
    }
45
46
    /**
47
     * Register the Laraflash bindings.
48
     *
49
     * @return void
50
     */
51 59
    protected function registerBindings()
52
    {
53 59
        $this->app->bind(MessagesStorageContract::class, SessionMessagesStorage::class);
54
55 59
        $this->app->bind(LaraflashRendererContract::class, LaraflashRenderer::class);
56
57 59
        $this->app->bind(FlashMessageRendererContract::class, ViewFlashMessageRenderer::class);
58
59 59
        $this->app->bind(LaraflashPreparerContract::class, LaraflashPreparer::class);
60
61 59
        $this->app->bind(FlashMessageFactoryContract::class, FlashMessageFactory::class);
62
63
        $this->app->singleton(MessagesStorageManager::class, function (Application $app) {
64
            return new MessagesStorageManager($app);
65 59
        });
66
67
        $this->app->bind(MessagesStorageContract::class, function (Application $app) {
68
            /** @var MessagesStorageManager $messagesStorageManager */
69
            $messagesStorageManager = $app->make(MessagesStorageManager::class);
70
71
            return $messagesStorageManager->driver();
72 59
        });
73
74
        $this->app->singleton('laraflash', function (Application $app) {
75
            return $app->make(Laraflash::class);
76 59
        });
77 59
    }
78
79
    /**
80
     * Setup the resource publishing groups for Laraflash.
81
     *
82
     * @return void
83
     */
84 59
    protected function offerPublishing()
85
    {
86 59
        $this->publishes([
87 59
            __DIR__.'/../../resources/views' => $this->app->resourcePath('views/vendor/laraflash'),
88 59
        ], 'laraflash-views');
89
90 59
        $this->publishes([
91 59
            __DIR__.'/../../config/laraflash.php' => $this->app->configPath('laraflash.php'),
92 59
        ], 'laraflash-config');
93 59
    }
94
95
    /**
96
     * Register the Laraflash resources.
97
     *
98
     * @return void
99
     */
100 59
    protected function registerResources()
101
    {
102 59
        $this->loadViewsFrom(__DIR__.'/../../resources/views/components/skins', 'laraflash_skin');
103 59
    }
104
105
    /**
106
     * Setup the configuration for Laraflash.
107
     *
108
     * @return void
109
     */
110 59
    protected function configure()
111
    {
112 59
        $this->mergeConfigFrom(
113 59
            __DIR__.'/../../config/laraflash.php',
114 59
            'laraflash'
115
        );
116 59
    }
117
}
118