|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Laravel Service Provider. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) DraperStudio <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace DraperStudio\ServiceProvider\Publisher; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
15
|
|
|
|
|
16
|
|
|
abstract class Publisher |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* The filesystem instance. |
|
20
|
|
|
* |
|
21
|
|
|
* @var \Illuminate\Filesystem\Filesystem |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $files; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The destination of the config files. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $publishPath; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The path to the application's packages. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $packagePath; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The destination paths for source files. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $destinationPaths; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create a new publisher instance. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Illuminate\Filesystem\Filesystem $files |
|
50
|
|
|
* @param string $publishPath |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct(Filesystem $files, $publishPath) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->files = $files; |
|
55
|
|
|
$this->publishPath = $publishPath; |
|
56
|
|
|
|
|
57
|
|
|
$this->destinationPaths = [ |
|
|
|
|
|
|
58
|
|
|
'migrations' => database_path('/migrations/%s_%s'), |
|
59
|
|
|
'seeds' => database_path('/seeds/%s'), |
|
60
|
|
|
'config' => config_path('%s'), |
|
61
|
|
|
'views' => base_path('resources/views/vendor/%s'), |
|
62
|
|
|
'translations' => base_path('resources/lang/%s'), |
|
63
|
|
|
'assets' => public_path('vendor/%s'), |
|
64
|
|
|
'routes' => null, |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Publish files from a given path. |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $package |
|
72
|
|
|
* @param string $source |
|
|
|
|
|
|
73
|
|
|
* |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getFileList($package) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->getSource($package, $this->packagePath); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Set the default package path. |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $packagePath |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setPackagePath($packagePath) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->packagePath = $packagePath; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Set the default package name. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $packageName |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setPackageName($packageName) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->packageName = $packageName; |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the source directory to publish. |
|
103
|
|
|
* |
|
104
|
|
|
* @param string $packagePath |
|
105
|
|
|
* |
|
106
|
|
|
* @return string |
|
107
|
|
|
* |
|
108
|
|
|
* @throws \InvalidArgumentException |
|
109
|
|
|
*/ |
|
110
|
|
|
abstract protected function getSource($packagePath); |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param $file |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
protected function getFileName($file) |
|
118
|
|
|
{ |
|
119
|
|
|
$file = basename($file); |
|
120
|
|
|
|
|
121
|
|
|
if (!ends_with($file, '.php')) { |
|
122
|
|
|
$file = $file.'.php'; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return $file; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Get the target destination path for the files. |
|
130
|
|
|
* |
|
131
|
|
|
* @param string $package |
|
|
|
|
|
|
132
|
|
|
* |
|
133
|
|
|
* @return string |
|
134
|
|
|
*/ |
|
135
|
|
|
protected function getDestinationPath($type, $args) |
|
136
|
|
|
{ |
|
137
|
|
|
return vsprintf($this->destinationPaths[$type], $args); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param $type |
|
142
|
|
|
* @param $files |
|
143
|
|
|
* |
|
144
|
|
|
* @return array |
|
145
|
|
|
*/ |
|
146
|
|
|
protected function getSourceFiles($path) |
|
147
|
|
|
{ |
|
148
|
|
|
$files = []; |
|
149
|
|
|
foreach (glob($path.'/*.php') as $file) { |
|
150
|
|
|
$files[] = $file; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
return $files; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param $path |
|
158
|
|
|
* |
|
159
|
|
|
* @return mixed |
|
160
|
|
|
*/ |
|
161
|
|
|
protected function getClassFromFile($path) |
|
162
|
|
|
{ |
|
163
|
|
|
$count = count($tokens = token_get_all(file_get_contents($path))); |
|
164
|
|
|
|
|
165
|
|
|
for ($i = 2; $i < $count; ++$i) { |
|
166
|
|
|
if ($tokens[$i - 2][0] == T_CLASS && $tokens[$i - 1][0] == T_WHITESPACE && $tokens[$i][0] == T_STRING) { |
|
167
|
|
|
return $tokens[$i][1]; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..