1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fomvasss\Taxonomy; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
|
7
|
|
|
class TaxonomyServiceProvider extends ServiceProvider |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Bootstrap the application services. |
11
|
|
|
* |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
|
|
public function boot() |
15
|
|
|
{ |
16
|
|
|
$this->publishConfig(); |
17
|
|
|
|
18
|
|
|
$this->publishMigrations(); |
19
|
|
|
|
20
|
|
|
$this->publishSeeder(); |
21
|
|
|
|
22
|
|
|
$this->overrideModels(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Register the application services. |
27
|
|
|
* |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public function register() |
31
|
|
|
{ |
32
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/taxonomy.php', 'taxonomy'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function publishConfig() |
36
|
|
|
{ |
37
|
|
|
$this->publishes([ |
38
|
|
|
__DIR__ . '/../config/taxonomy.php' => config_path('taxonomy.php') |
|
|
|
|
39
|
|
|
], 'config'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function publishSeeder() |
43
|
|
|
{ |
44
|
|
|
$this->publishes([ |
45
|
|
|
__DIR__ . '/../database/seeders/TaxonomySeeder.php.stub' => database_path('seeders/TaxonomySeeder.php') |
|
|
|
|
46
|
|
|
], 'seeder'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function publishMigrations() |
50
|
|
|
{ |
51
|
|
|
if (! class_exists('CreateTaxonomiesTable')) { |
52
|
|
|
$timestamp = date('Y_m_d_His', time()); |
53
|
|
|
|
54
|
|
|
$this->publishes([ |
55
|
|
|
__DIR__.'/../database/migrations/create_taxonomy_tables.php' => database_path('/migrations/' . $timestamp . '_create_taxonomy_tables.php'), |
|
|
|
|
56
|
|
|
], 'migrations'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function overrideModels() |
61
|
|
|
{ |
62
|
|
|
if (! class_exists('App\Models\Term\Taxonomy') || ! class_exists('App\Models\Vocabulary\Taxonomy')) { |
63
|
|
|
$modelPathStub = __DIR__.'/stubs/models/'; |
64
|
|
|
$modelPath = $this->checkMakeDir(app_path('Models/Taxonomy')) . '/'; |
|
|
|
|
65
|
|
|
|
66
|
|
|
$this->publishes([ |
67
|
|
|
$modelPathStub . 'Term.php.stub' => $modelPath . 'Term.php', |
68
|
|
|
$modelPathStub . 'Vocabulary.php.stub' => $modelPath . 'Vocabulary.php', |
69
|
|
|
], 'models'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function checkMakeDir(string $path) |
74
|
|
|
{ |
75
|
|
|
if (!is_dir($path)) { |
76
|
|
|
mkdir($path, 0755, true); |
77
|
|
|
} |
78
|
|
|
return $path; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|