Passed
Push — master ( 868a85...47fe80 )
by Morten Poul
03:20
created

TranslatorServiceProvider::publishMigrations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Signifly\Translator;
4
5
use Illuminate\Support\ServiceProvider;
6
use Signifly\Translator\Contracts\Translator as TranslatorContract;
7
8
class TranslatorServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        if ($this->app->runningInConsole()) {
18
            $this->publishConfigs();
19
            $this->publishMigrations();
20
        }
21
22
        $this->mergeConfigFrom(__DIR__.'/../config/translator.php', 'translator');
23
    }
24
25
    /**
26
     * Register the service provider.
27
     *
28
     * @return void
29
     */
30
    public function register()
31
    {
32
        $this->app->singleton(TranslatorContract::class, function ($app) {
33
            return new Translator($app['config']);
34
        });
35
    }
36
37
    /**
38
     * Get the services provided by the provider.
39
     *
40
     * @return array
41
     */
42
    public function provides()
43
    {
44
        return [TranslatorContract::class];
45
    }
46
47
    protected function publishConfigs(): void
48
    {
49
        $this->publishes([
50
            __DIR__.'/../config/translator.php' => config_path('translator.php'),
51
        ], 'translator-config');
52
    }
53
54
    protected function publishMigrations(): void
55
    {
56
        if (class_exists('CreateTranslationsTable')) {
57
            return;
58
        }
59
60
        $timestamp = date('Y_m_d_His', time());
61
62
        $this->publishes([
63
            __DIR__.'/../migrations/create_translations_table.php.stub' => database_path("/migrations/{$timestamp}_create_translations_table.php"),
64
        ], 'translator-migrations');
65
    }
66
}
67