|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Thinktomorrow\AssetLibrary; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Factory as EloquentFactory; |
|
6
|
|
|
use Illuminate\Routing\Router; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
use Thinktomorrow\AssetLibrary\Models\Asset; |
|
9
|
|
|
|
|
10
|
|
|
class AssetLibraryServiceProvider extends ServiceProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Indicates if loading of the provider is deferred. |
|
14
|
|
|
* |
|
15
|
|
|
* @var bool |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $defer = false; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Perform post-registration booting of services. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
60 |
|
public function boot() |
|
25
|
|
|
{ |
|
26
|
60 |
|
$this->publishes([ |
|
27
|
60 |
|
__DIR__.'/../config/assetlibrary.php' => config_path('assetlibrary.php'), |
|
28
|
60 |
|
], 'config'); |
|
29
|
|
|
|
|
30
|
60 |
|
$this->loadRoutesFrom(__DIR__.'/Http/routes.php'); |
|
31
|
|
|
|
|
32
|
60 |
|
$this->publishMigrations(); |
|
33
|
|
|
|
|
34
|
60 |
|
$this->registerModelBindings(); |
|
35
|
60 |
|
$this->registerEloquentFactoriesFrom(__DIR__.'/../database/factories'); |
|
36
|
60 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Register factories. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $path |
|
42
|
|
|
* @return void |
|
43
|
|
|
*/ |
|
44
|
60 |
|
protected function registerEloquentFactoriesFrom($path) |
|
45
|
|
|
{ |
|
46
|
60 |
|
$this->app->make(EloquentFactory::class)->load($path); |
|
47
|
60 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Register any package services. |
|
51
|
|
|
* |
|
52
|
|
|
* @return void |
|
53
|
|
|
*/ |
|
54
|
60 |
|
public function register() |
|
55
|
|
|
{ |
|
56
|
60 |
|
$this->mergeConfigFrom(__DIR__.'/../config/assetlibrary.php', 'assetlibrary'); |
|
57
|
|
|
|
|
58
|
60 |
|
$this->registerAssetLibrary(); |
|
59
|
60 |
|
} |
|
60
|
|
|
|
|
61
|
60 |
|
protected function registerModelBindings() |
|
62
|
|
|
{ |
|
63
|
|
|
//TODO implement this |
|
64
|
60 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* |
|
68
|
|
|
*/ |
|
69
|
|
|
private function registerAssetLibrary() |
|
70
|
|
|
{ |
|
71
|
60 |
|
$this->app->singleton('asset', function ($app) { |
|
72
|
|
|
return new Asset($app); |
|
73
|
60 |
|
}); |
|
74
|
60 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* |
|
78
|
|
|
*/ |
|
79
|
60 |
|
public function publishMigrations(): void |
|
80
|
|
|
{ |
|
81
|
60 |
View Code Duplication |
if (!class_exists('CreateAssetTable')) { |
|
|
|
|
|
|
82
|
1 |
|
$this->publishes([ |
|
83
|
1 |
|
__DIR__ . '/../database/migrations/create_asset_table.php' => database_path('migrations/' . date('Y_m_d_His', |
|
|
|
|
|
|
84
|
1 |
|
time()) . '_create_asset_table.php'), |
|
85
|
1 |
|
], 'migrations'); |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
60 |
View Code Duplication |
if (! class_exists('CreateMediaTable')) { |
|
|
|
|
|
|
90
|
1 |
|
$this->publishes([ |
|
91
|
1 |
|
__DIR__.'/../../../spatie/laravel-medialibrary/database/migrations/create_media_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_media_table.php'), |
|
|
|
|
|
|
92
|
1 |
|
], 'migrations'); |
|
93
|
|
|
} |
|
94
|
60 |
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.