BackupServiceProvider::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Cornford\Backup\Providers;
4
5
use Cornford\Backup\BackupFactory;
6
use Cornford\Backup\Commands\BackupCommandExport;
7
use Cornford\Backup\Commands\BackupCommandRestore;
8
use Illuminate\Support\ServiceProvider;
9
10
class BackupServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Indicates if loading of the provider is deferred.
14
     *
15
     * @var bool
16
     */
17
    protected $defer = true;
18
19
    /**
20
     * Bootstrap the application events.
21
     *
22
     * @return void
23
     */
24
    public function boot(): void
25
    {
26
        $configPath = __DIR__ . '/../../config/config.php';
27
        $this->publishes([$configPath => config_path('backup.php')], 'backup');
28
    }
29
30
    /**
31
     * Register the service provider.
32
     *
33
     * @return void
34
     */
35
    public function register(): void
36
    {
37
        $configPath = __DIR__ . '/../../config/config.php';
38
        $this->mergeConfigFrom($configPath, 'backup');
39
40
        $this->app->singleton(
41
            'backup',
42
            function ($app) {
43
                $config = array_merge($app['config']->get('database'), $app['config']->get('backup'));
44
45
                return (new BackupFactory())->build($config);
46
            }
47
        );
48
49
        $this->app->singleton(
50
            'db.export',
51
            function ($app) {
52
                return new BackupCommandExport(new BackupFactory(), $app['config']);
53
            }
54
        );
55
56
        $this->app->singleton(
57
            'db.restore',
58
            function ($app) {
59
                return new BackupCommandRestore(new BackupFactory(), $app['config']);
60
            }
61
        );
62
63
        $this->commands(
64
            'db.export',
65
            'db.restore'
66
        );
67
    }
68
69
    /**
70
     * Get the services provided by the provider.
71
     *
72
     * @return string[]
73
     */
74
    public function provides(): array
75
    {
76
        return ['backup'];
77
    }
78
}
79