1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Port\Seeder\Loaders; |
4
|
|
|
|
5
|
|
|
use App\Port\Foundation\Portals\Facade\PortButler; |
6
|
|
|
use App\Port\Seeder\Testing\LiveTestingSeeder; |
7
|
|
|
use Illuminate\Database\Seeder as LaravelSeeder; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Seeder. |
11
|
|
|
* |
12
|
|
|
* @author Mahmoud Zalt <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
abstract class SeederLoaderAbstract extends LaravelSeeder |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Manually seeding some Port Seeders whenever needed |
19
|
|
|
* |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
protected $portSeedersClasses = [ |
23
|
|
|
LiveTestingSeeder::class, |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Default seeders directory in the container |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $seedersPath = '/Data/Seeders'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Run the database seeds. |
35
|
|
|
* Then Automatically register all Seeders from Containers. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function run() |
40
|
|
|
{ |
41
|
|
|
$this->seedContainers(); |
42
|
|
|
$this->seedPort(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
private function seedContainers() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
foreach (PortButler::getContainersNames() as $containerName) { |
51
|
|
|
|
52
|
|
|
$containersDirectory = base_path('app/Containers/' . $containerName . $this->seedersPath); |
53
|
|
|
|
54
|
|
|
if (\File::isDirectory($containersDirectory)) { |
55
|
|
|
|
56
|
|
|
$files = \File::allFiles($containersDirectory); |
57
|
|
|
|
58
|
|
|
foreach ($files as $seederClass) { |
59
|
|
|
|
60
|
|
|
if (\File::isFile($seederClass)) { |
61
|
|
|
|
62
|
|
|
$pathName = $seederClass->getPathname(); |
63
|
|
|
|
64
|
|
|
$seederClass = PortButler::getClassFullNameFromFile($pathName); |
65
|
|
|
|
66
|
|
|
$this->seed($seederClass); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* |
77
|
|
|
*/ |
78
|
|
|
private function seedPort() |
79
|
|
|
{ |
80
|
|
|
foreach ($this->portSeedersClasses as $seederClass) { |
81
|
|
|
$this->seed($seederClass); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $class |
87
|
|
|
*/ |
88
|
|
|
private function seed($class) |
89
|
|
|
{ |
90
|
|
|
$this->call($class); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.