|
1
|
|
|
<?php namespace Cviebrock\EloquentTaggable; |
|
2
|
|
|
|
|
3
|
|
|
use Cviebrock\EloquentTaggable\Services\TagService; |
|
4
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
5
|
|
|
use Illuminate\Support\Collection; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider as LaravelServiceProvider; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class ServiceProvider |
|
11
|
|
|
* |
|
12
|
|
|
* @package Cviebrock\EloquentTaggable |
|
13
|
|
|
*/ |
|
14
|
|
|
class ServiceProvider extends LaravelServiceProvider |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @inheritdoc |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $defer = false; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Bootstrap the application events. |
|
24
|
|
|
*/ |
|
25
|
23 |
|
public function boot(Filesystem $filesystem) |
|
26
|
|
|
{ |
|
27
|
23 |
|
$this->publishes([ |
|
28
|
23 |
|
__DIR__ . '/../resources/config/taggable.php' => config_path('taggable.php'), |
|
29
|
23 |
|
], 'config'); |
|
30
|
|
|
|
|
31
|
23 |
|
|
|
32
|
|
|
$this->publishes([ |
|
33
|
1 |
|
__DIR__.'/../resources/database/migrations/0000_00_00_000000_create_taggable_table.php' => $this->getMigrationFileName($filesystem) |
|
34
|
1 |
|
], 'eloquent-taggable-migrations'); |
|
35
|
1 |
|
|
|
36
|
|
|
$package_migration = glob($this->app->databasePath()."/migrations/*_create_taggable_table.php"); |
|
37
|
1 |
|
|
|
38
|
1 |
|
if (count($package_migration) > 0) { |
|
39
|
1 |
|
$this->loadMigrationsFrom(database_path('migrations')); |
|
40
|
1 |
|
} else { |
|
41
|
23 |
|
$this->loadMigrationsFrom( |
|
42
|
|
|
__DIR__.'/../resources/database/migrations' |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
23 |
|
* Register the service provider. |
|
49
|
|
|
* |
|
50
|
23 |
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
23 |
|
public function register() |
|
53
|
23 |
|
{ |
|
54
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../resources/config/taggable.php', 'taggable'); |
|
55
|
|
|
|
|
56
|
|
|
$this->app->singleton(TagService::class); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param Filesystem $filesystem |
|
61
|
|
|
* @return mixed |
|
62
|
|
|
*/ |
|
63
|
|
|
private function getMigrationFileName(Filesystem $filesystem) |
|
64
|
|
|
{ |
|
65
|
|
|
$timestamp = date('Y_m_d_His'); |
|
66
|
|
|
|
|
67
|
|
|
return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) |
|
68
|
|
|
->flatMap(function ($path) use ($filesystem) { |
|
69
|
|
|
return $filesystem->glob($path.'*_create_taggable_table.php'); |
|
70
|
|
|
})->push($this->app->databasePath()."/migrations/{$timestamp}_create_taggable_table.php") |
|
71
|
|
|
->first(); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|