|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelPropertyBag; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
use LaravelPropertyBag\Settings\PropertyBag; |
|
8
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
|
9
|
|
|
|
|
10
|
|
|
class PropertyBagServiceProvider extends ServiceProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Register bindings in the container. |
|
14
|
|
|
* |
|
15
|
|
|
* @return void |
|
16
|
|
|
*/ |
|
17
|
|
|
public function register() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->registerCommands(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Register any other events for your application. |
|
24
|
|
|
* |
|
25
|
|
|
* @return void |
|
26
|
|
|
*/ |
|
27
|
|
|
public function boot() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->publishes([ |
|
30
|
|
|
__DIR__.'/../config/property-bag.php' => config_path('property-bag.php'), |
|
31
|
|
|
], 'config'); |
|
32
|
|
|
|
|
33
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/property-bag.php', 'property-bag'); |
|
34
|
|
|
|
|
35
|
|
|
$this->publishes([ |
|
36
|
|
|
__DIR__.'/Migrations/' => database_path('migrations'), |
|
37
|
|
|
], 'migrations'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Register Artisan commands. |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function registerCommands() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->app->singleton('command.pbag.make', function ($app) { |
|
46
|
|
|
return $app['LaravelPropertyBag\Commands\PublishSettingsConfig']; |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
$this->app->singleton('command.pbag.rules', function ($app) { |
|
50
|
|
|
return $app['LaravelPropertyBag\Commands\PublishRulesFile']; |
|
51
|
|
|
}); |
|
52
|
|
|
|
|
53
|
|
|
$this->commands('command.pbag.make'); |
|
54
|
|
|
|
|
55
|
|
|
$this->commands('command.pbag.rules'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public static function determinePropertyBagModel(): string |
|
59
|
|
|
{ |
|
60
|
|
|
$propertyBagModel = config('property-bag.property_bag_model') ?? PropertyBag::class; |
|
61
|
|
|
|
|
62
|
|
|
if (!is_a($propertyBagModel, Model::class, true)) { |
|
63
|
|
|
throw new ModelNotFoundException($propertyBagModel); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $propertyBagModel; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public static function getPropertyBagModelInstance(): Model |
|
70
|
|
|
{ |
|
71
|
|
|
$propertyBagModelClassName = self::determinePropertyBagModel(); |
|
72
|
|
|
|
|
73
|
|
|
return new $propertyBagModelClassName(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|