Completed
Push — master ( ff1819...be92a6 )
by Benjamin
05:59
created

AbTestingServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 13
cts 13
cp 1
rs 9.2
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Ben182\AbTesting;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Blade;
7
use Illuminate\Support\ServiceProvider;
8
use Ben182\AbTesting\Commands\FlushCommand;
9
use Ben182\AbTesting\Commands\ReportCommand;
10
11
class AbTestingServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     */
16 48
    public function boot()
17
    {
18
        /*
19
         * Optional methods to load your package assets
20
         */
21
        // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-ab');
22
        // $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-ab');
23 48
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
24
        // $this->loadRoutesFrom(__DIR__.'/routes.php');
25
26 48
        if ($this->app->runningInConsole()) {
27 48
            $this->publishes([
28 48
                __DIR__.'/../config/config.php' => config_path('ab-testing.php'),
29 48
            ], 'config');
30
31
            // Publishing the views.
32
            /*$this->publishes([
33
                __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-ab'),
34
            ], 'views');*/
35
36
            // Publishing assets.
37
            /*$this->publishes([
38
                __DIR__.'/../resources/assets' => public_path('vendor/laravel-ab'),
39
            ], 'assets');*/
40
41
            // Publishing the translation files.
42
            /*$this->publishes([
43
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-ab'),
44
            ], 'lang');*/
45
46
            // Registering package commands.
47 48
            $this->commands([
48 48
                ReportCommand::class,
49
                FlushCommand::class,
50
            ]);
51
        }
52
53
        Request::macro('abExperiment', function () {
54 3
            return app(AbTesting::class)->getExperiment();
55 48
        });
56
57
        Blade::if('abExperiment', function ($experiment) {
58 3
            return app(AbTesting::class)->isExperiment($experiment);
59 48
        });
60 48
    }
61
62
    /**
63
     * Register the application services.
64
     */
65 48
    public function register()
66
    {
67
        // Automatically apply the package configuration
68 48
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'ab-testing');
69
70
        // Register the main class to use with the facade
71
        $this->app->singleton('ab-testing', function () {
72 48
            return new AbTesting;
73 48
        });
74 48
    }
75
}
76