|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Ship\Engine\Loaders; |
|
4
|
|
|
|
|
5
|
|
|
use App\Ship\Engine\Butlers\Facades\LoaderButler; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class AutoLoaderTrait. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
trait AutoLoaderTrait |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
// using each component loader trait |
|
16
|
|
|
use ConfigsLoaderTrait; |
|
17
|
|
|
use MigrationsLoaderTrait; |
|
18
|
|
|
use ViewsLoaderTrait; |
|
19
|
|
|
use ProvidersLoaderTrait; |
|
20
|
|
|
use ConsolesLoaderTrait; |
|
21
|
|
|
use AliasesLoaderTrait; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* * to be used from the `boot` function of the main service provider |
|
25
|
|
|
*/ |
|
26
|
|
|
public function runLoadersBoot() |
|
27
|
|
|
{ |
|
28
|
|
|
// the config files should be loaded first from all the directories in their own loop |
|
29
|
|
|
$this->loadConfigsFromShip(); |
|
30
|
|
|
$this->loadProvidersFromShip(); |
|
31
|
|
|
|
|
32
|
|
|
// > iterate over all the port folders and autoload most of the components |
|
33
|
|
|
foreach (LoaderButler::getShipFoldersNames() as $portFolderName) { |
|
34
|
|
|
$this->loadMigrationsFromShip(); |
|
35
|
|
|
$this->loadViewsFromShip($portFolderName); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
// > iterate over all the containers folders and autoload most of the components |
|
39
|
|
|
foreach (LoaderButler::getContainersNames() as $containerName) { |
|
40
|
|
|
$this->loadConfigsFromContainers($containerName); |
|
41
|
|
|
$this->loadProvidersFromContainers($containerName); |
|
42
|
|
|
$this->loadMigrationsFromContainers($containerName); |
|
43
|
|
|
$this->loadViewsFromContainers($containerName); |
|
44
|
|
|
$this->loadViewsFromContainers($containerName); |
|
45
|
|
|
$this->loadConsolesFromContainers($containerName); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* to be used from the `register` function of the main service provider |
|
51
|
|
|
*/ |
|
52
|
|
|
public function runLoadersRegister() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->loadContainerFactories(); |
|
|
|
|
|
|
55
|
|
|
$this->loadShipInternalAliases(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.