1
|
|
|
<?php namespace Arcanedev\Support\Providers; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Support\Exceptions\PackageException; |
4
|
|
|
use Arcanedev\Support\Providers\Concerns\{ |
5
|
|
|
HasConfig, HasFactories, HasMigrations, HasTranslations, HasViews |
6
|
|
|
}; |
7
|
|
|
use Illuminate\Contracts\Foundation\Application; |
8
|
|
|
use ReflectionClass; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class PackageServiceProvider |
12
|
|
|
* |
13
|
|
|
* @package Arcanedev\Support\Providers |
14
|
|
|
* @author ARCANEDEV <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
abstract class PackageServiceProvider extends ServiceProvider |
17
|
|
|
{ |
18
|
|
|
/* ----------------------------------------------------------------- |
19
|
|
|
| Traits |
20
|
|
|
| ----------------------------------------------------------------- |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
use HasConfig, |
24
|
|
|
HasFactories, |
25
|
|
|
HasMigrations, |
26
|
|
|
HasTranslations, |
27
|
|
|
HasViews; |
28
|
|
|
|
29
|
|
|
/* ----------------------------------------------------------------- |
30
|
|
|
| Properties |
31
|
|
|
| ----------------------------------------------------------------- |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Vendor name. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $vendor = 'arcanedev'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Package name. |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $package = ''; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Package base path. |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected $basePath; |
54
|
|
|
|
55
|
|
|
/* ----------------------------------------------------------------- |
56
|
|
|
| Constructor |
57
|
|
|
| ----------------------------------------------------------------- |
58
|
|
|
*/ |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Create a new service provider instance. |
62
|
|
|
* |
63
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
64
|
|
|
*/ |
65
|
6 |
|
public function __construct(Application $app) |
66
|
|
|
{ |
67
|
6 |
|
parent::__construct($app); |
68
|
|
|
|
69
|
6 |
|
$this->basePath = $this->resolveBasePath(); |
70
|
6 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Resolve the base path of the package. |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
6 |
|
protected function resolveBasePath() |
78
|
|
|
{ |
79
|
6 |
|
return dirname( |
80
|
6 |
|
(new ReflectionClass($this))->getFileName(), 2 |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/* ----------------------------------------------------------------- |
85
|
|
|
| Getters & Setters |
86
|
|
|
| ----------------------------------------------------------------- |
87
|
|
|
*/ |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the base path of the package. |
91
|
|
|
* |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
6 |
|
public function getBasePath() |
95
|
|
|
{ |
96
|
6 |
|
return $this->basePath; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the base database path. |
101
|
|
|
* |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
protected function getDatabasePath() |
105
|
|
|
{ |
106
|
|
|
return $this->getBasePath().DS.'database'; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get the base resources path. |
111
|
|
|
* |
112
|
|
|
* @deprecated Use the getBasePath() instead! |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
protected function getResourcesPath() |
117
|
|
|
{ |
118
|
|
|
return $this->getBasePath().DS.'resources'; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/* ----------------------------------------------------------------- |
122
|
|
|
| Main Methods |
123
|
|
|
| ----------------------------------------------------------------- |
124
|
|
|
*/ |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Register the service provider. |
128
|
|
|
*/ |
129
|
6 |
|
public function register() |
130
|
|
|
{ |
131
|
6 |
|
parent::register(); |
132
|
|
|
|
133
|
6 |
|
$this->checkPackageName(); |
134
|
6 |
|
} |
135
|
|
|
|
136
|
|
|
/* ----------------------------------------------------------------- |
137
|
|
|
| Package Methods |
138
|
|
|
| ----------------------------------------------------------------- |
139
|
|
|
*/ |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Publish all the package files. |
143
|
|
|
* |
144
|
|
|
* @param bool $load |
145
|
|
|
*/ |
146
|
|
|
protected function publishAll($load = true) |
147
|
|
|
{ |
148
|
|
|
$this->publishConfig(); |
149
|
|
|
$this->publishMigrations(); |
150
|
|
|
$this->publishViews($load); |
151
|
|
|
$this->publishTranslations($load); |
152
|
|
|
$this->publishFactories(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/* ------------------------------------------------------------------------------------------------ |
156
|
|
|
| Check Functions |
157
|
|
|
| ------------------------------------------------------------------------------------------------ |
158
|
|
|
*/ |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Check package name. |
162
|
|
|
* |
163
|
|
|
* @throws \Arcanedev\Support\Exceptions\PackageException |
164
|
|
|
*/ |
165
|
6 |
|
private function checkPackageName() |
166
|
|
|
{ |
167
|
6 |
|
if (empty($this->vendor) || empty($this->package)) |
168
|
2 |
|
throw new PackageException('You must specify the vendor/package name.'); |
169
|
6 |
|
} |
170
|
|
|
} |
171
|
|
|
|