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 InvalidArgumentException; |
15
|
|
|
|
16
|
|
|
class SeedPublisher extends Publisher |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Get the source configuration directory to publish. |
20
|
|
|
* |
21
|
|
|
* @param string $packagePath |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
* |
25
|
|
|
* @throws \InvalidArgumentException |
26
|
|
|
*/ |
27
|
|
|
protected function getSource($packagePath) |
28
|
|
|
{ |
29
|
|
|
$sources = [ |
30
|
|
|
"{$packagePath}/resources/database/seeds", |
31
|
|
|
"{$packagePath}/resources/seeds", |
32
|
|
|
"{$packagePath}/seeds", |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
// iterate through all possible locations |
36
|
|
|
foreach ($sources as $source) { |
37
|
|
|
if ($this->files->isDirectory($source)) { |
38
|
|
|
$paths = []; |
39
|
|
|
|
40
|
|
|
// get all files of the current directory |
41
|
|
|
$files = $this->getSourceFiles($source); |
42
|
|
|
|
43
|
|
|
// iterate through all files |
44
|
|
|
foreach ($files as $file) { |
45
|
|
|
$destinationPath = $this->getDestinationPath('seeds', [ |
46
|
|
|
$this->getFileName($file), |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
// if the destination doesn't exist we can add the file to the queue |
50
|
|
|
if (!$this->files->exists($destinationPath)) { |
51
|
|
|
$paths[$file] = $destinationPath; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $paths; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
throw new InvalidArgumentException('Seeds not found.'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|