|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cerbero\SqlDumper\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Cerbero\SqlDumper\Dumpers\DumperInterface; |
|
6
|
|
|
use Illuminate\Contracts\Foundation\Application; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The SQL dumper service provider. |
|
11
|
|
|
* |
|
12
|
|
|
*/ |
|
13
|
|
|
class SqlDumperServiceProvider extends ServiceProvider |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The package configuration path. |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected const CONFIG = __DIR__ . '/../../config/sql_dumper.php'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Indicates if loading of the provider is deferred. |
|
24
|
|
|
* |
|
25
|
|
|
* @var bool |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $defer = true; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Bootstrap application services. |
|
31
|
|
|
* |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
|
public function boot() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->publishes([static::CONFIG => $this->app->configPath('sql_dumper.php')], 'sql-dumper'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Register the bindings |
|
41
|
|
|
* |
|
42
|
|
|
* @return void |
|
43
|
|
|
*/ |
|
44
|
|
|
public function register(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$this->mergeConfigFrom(static::CONFIG, 'sql_dumper'); |
|
47
|
|
|
|
|
48
|
|
|
$this->app->bind(DumperInterface::class, function (Application $app) { |
|
49
|
|
|
$dumper = $this->config('default_dumper'); |
|
50
|
|
|
|
|
51
|
|
|
return $app->make($dumper, $this->config($dumper, [])); |
|
52
|
|
|
}); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Retrieve a configuration value |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $key |
|
59
|
|
|
* @param mixed $default |
|
60
|
|
|
* @return mixed |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function config(string $key, $default = null) |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->app->config->get("sql_dumper.{$key}", $default); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Determine if the provider is deferred. |
|
69
|
|
|
* |
|
70
|
|
|
* @return bool |
|
71
|
|
|
*/ |
|
72
|
|
|
public function isDeferred() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->defer; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Get the services provided by the provider. |
|
79
|
|
|
* |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
|
|
public function provides() |
|
83
|
|
|
{ |
|
84
|
|
|
return [DumperInterface::class]; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|