1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Port\Loader\Loaders; |
4
|
|
|
|
5
|
|
|
use App; |
6
|
|
|
use App\Port\Foundation\Portals\Facade\PortButler; |
7
|
|
|
use DB; |
8
|
|
|
use File; |
9
|
|
|
use Log; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ProvidersLoaderTrait. |
13
|
|
|
* |
14
|
|
|
* @author Mahmoud Zalt <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
trait ProvidersLoaderTrait |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* runProvidersAutoLoader |
21
|
|
|
*/ |
22
|
|
|
public function runProvidersAutoLoader() |
23
|
|
|
{ |
24
|
|
|
$this->loadProvidersFromPort(); |
25
|
|
|
$this->loadProvidersFromContainers(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* loadProvidersFromContainers |
30
|
|
|
*/ |
31
|
|
View Code Duplication |
private function loadProvidersFromContainers() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$mainServiceProviderNameStartWith = 'Main'; |
34
|
|
|
|
35
|
|
|
foreach (PortButler::getContainersNames() as $containerName) { |
36
|
|
|
|
37
|
|
|
$containerProvidersDirectory = base_path('app/Containers/' . $containerName . '/Providers'); |
38
|
|
|
|
39
|
|
|
if (File::isDirectory($containerProvidersDirectory)) { |
40
|
|
|
|
41
|
|
|
$files = \File::allFiles($containerProvidersDirectory); |
42
|
|
|
|
43
|
|
|
foreach ($files as $file) { |
44
|
|
|
|
45
|
|
|
if (\File::isFile($file)) { |
46
|
|
|
|
47
|
|
|
// Check if this is the Main Service Provider |
48
|
|
|
if (PortButler::stringStartsWith($file->getFilename(), $mainServiceProviderNameStartWith)) { |
49
|
|
|
$serviceProviderClass = PortButler::getClassFullNameFromFile($file->getPathname()); |
50
|
|
|
|
51
|
|
|
$this->loadProvider($serviceProviderClass); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* loadProvidersFromPort |
61
|
|
|
*/ |
62
|
|
|
private function loadProvidersFromPort() |
63
|
|
|
{ |
64
|
|
|
foreach ($this->serviceProviders as $providerClass) { |
|
|
|
|
65
|
|
|
$this->loadProvider($providerClass); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/* |
70
|
|
|
* loadProvider |
71
|
|
|
*/ |
72
|
|
|
private function loadProvider($provider) |
73
|
|
|
{ |
74
|
|
|
App::register($provider); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* loadContainersInternalProviders |
79
|
|
|
*/ |
80
|
|
|
public function loadContainersInternalProviders() |
81
|
|
|
{ |
82
|
|
|
foreach ($this->containerServiceProviders as $provider) { |
|
|
|
|
83
|
|
|
$this->loadProvider($provider); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.