|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arcanedev\Support\Providers; |
|
6
|
|
|
|
|
7
|
|
|
use Arcanedev\Support\Exceptions\PackageException; |
|
8
|
|
|
use Arcanedev\Support\Providers\Concerns\{HasConfig, HasFactories, HasMigrations, HasTranslations, HasViews}; |
|
9
|
|
|
use Illuminate\Contracts\Foundation\Application; |
|
10
|
|
|
use ReflectionClass; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class PackageServiceProvider |
|
14
|
|
|
* |
|
15
|
|
|
* @package Arcanedev\Support\Providers |
|
16
|
|
|
* @author ARCANEDEV <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract class PackageServiceProvider extends ServiceProvider |
|
19
|
|
|
{ |
|
20
|
|
|
/* ----------------------------------------------------------------- |
|
21
|
|
|
| Traits |
|
22
|
|
|
| ----------------------------------------------------------------- |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
use HasConfig, |
|
26
|
|
|
HasFactories, |
|
27
|
|
|
HasMigrations, |
|
28
|
|
|
HasTranslations, |
|
29
|
|
|
HasViews; |
|
30
|
|
|
|
|
31
|
|
|
/* ----------------------------------------------------------------- |
|
32
|
|
|
| Properties |
|
33
|
|
|
| ----------------------------------------------------------------- |
|
34
|
|
|
*/ |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Vendor name. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $vendor = 'arcanedev'; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Package name. |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $package = ''; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Package base path. |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $basePath; |
|
56
|
|
|
|
|
57
|
|
|
/* ----------------------------------------------------------------- |
|
58
|
|
|
| Constructor |
|
59
|
|
|
| ----------------------------------------------------------------- |
|
60
|
|
|
*/ |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Create a new service provider instance. |
|
64
|
|
|
* |
|
65
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
|
66
|
|
|
*/ |
|
67
|
18 |
|
public function __construct(Application $app) |
|
68
|
|
|
{ |
|
69
|
18 |
|
parent::__construct($app); |
|
70
|
|
|
|
|
71
|
18 |
|
$this->basePath = $this->resolveBasePath(); |
|
72
|
18 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Resolve the base path of the package. |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
18 |
|
protected function resolveBasePath() |
|
80
|
|
|
{ |
|
81
|
18 |
|
return dirname( |
|
82
|
18 |
|
(new ReflectionClass($this))->getFileName(), 2 |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/* ----------------------------------------------------------------- |
|
87
|
|
|
| Getters & Setters |
|
88
|
|
|
| ----------------------------------------------------------------- |
|
89
|
|
|
*/ |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get the base path of the package. |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
18 |
|
public function getBasePath() |
|
97
|
|
|
{ |
|
98
|
18 |
|
return $this->basePath; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/* ----------------------------------------------------------------- |
|
102
|
|
|
| Main Methods |
|
103
|
|
|
| ----------------------------------------------------------------- |
|
104
|
|
|
*/ |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Register the service provider. |
|
108
|
|
|
*/ |
|
109
|
18 |
|
public function register() |
|
110
|
|
|
{ |
|
111
|
18 |
|
parent::register(); |
|
112
|
|
|
|
|
113
|
18 |
|
$this->checkPackageName(); |
|
114
|
18 |
|
} |
|
115
|
|
|
|
|
116
|
|
|
/* ----------------------------------------------------------------- |
|
117
|
|
|
| Package Methods |
|
118
|
|
|
| ----------------------------------------------------------------- |
|
119
|
|
|
*/ |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Publish all the package files. |
|
123
|
|
|
* |
|
124
|
|
|
* @param bool $load |
|
125
|
|
|
*/ |
|
126
|
|
|
protected function publishAll($load = true) |
|
127
|
|
|
{ |
|
128
|
|
|
$this->publishConfig(); |
|
129
|
|
|
$this->publishMigrations(); |
|
130
|
|
|
$this->publishViews($load); |
|
|
|
|
|
|
131
|
|
|
$this->publishTranslations($load); |
|
|
|
|
|
|
132
|
|
|
$this->publishFactories(); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/* ----------------------------------------------------------------- |
|
136
|
|
|
| Check Methods |
|
137
|
|
|
| ----------------------------------------------------------------- |
|
138
|
|
|
*/ |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Check package name. |
|
142
|
|
|
* |
|
143
|
|
|
* @throws \Arcanedev\Support\Exceptions\PackageException |
|
144
|
|
|
*/ |
|
145
|
18 |
|
private function checkPackageName(): void |
|
146
|
|
|
{ |
|
147
|
18 |
|
if (empty($this->vendor) || empty($this->package)) { |
|
148
|
6 |
|
throw PackageException::unspecifiedName(); |
|
149
|
|
|
} |
|
150
|
18 |
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: