Completed
Push — master ( f8b6bf...bec27e )
by Mahmoud
03:02
created

ProvidersLoaderTrait::loadProvidersFromPort()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace App\Port\Loader\Loaders;
4
5
use App;
6
use App\Port\Foundation\Portals\Facade\PortButler;
7
use App\Port\Loader\Helpers\Facade\LoaderHelper;
8
use DB;
9
use File;
10
use Log;
11
12
/**
13
 * Class ProvidersLoaderTrait.
14
 *
15
 * @author  Mahmoud Zalt <[email protected]>
16
 */
17
trait ProvidersLoaderTrait
18
{
19
20
    /**
21
     * @param $containerName
22
     */
23
    public function loadProvidersFromContainers($containerName)
24
    {
25
        $containerProvidersDirectory = base_path('app/Containers/' . $containerName . '/Providers');
26
27
        $this->loadProviders($containerProvidersDirectory);
28
    }
29
30
    /**
31
     * loadProvidersFromPort
32
     */
33
    public function loadProvidersFromPort()
34
    {
35
        foreach ($this->serviceProviders as $providerClass) {
0 ignored issues
show
Bug introduced by
The property serviceProviders does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
            $this->loadProvider($providerClass);
37
        }
38
    }
39
40
    /**
41
     * @param $directory
42
     */
43
    private function loadProviders($directory)
44
    {
45
        if (File::isDirectory($directory)) {
46
47
            $files = File::allFiles($directory);
48
49
            $mainServiceProviderNameStartWith = 'Main';
50
51
            foreach ($files as $file) {
52
53
                if (File::isFile($file)) {
54
55
                    // Check if this is the Main Service Provider
56
                    if (PortButler::stringStartsWith($file->getFilename(), $mainServiceProviderNameStartWith)) {
57
58
                        $serviceProviderClass = LoaderHelper::getClassFullNameFromFile($file->getPathname());
59
60
                        $this->loadProvider($serviceProviderClass);
61
62
                    }
63
                }
64
            }
65
        }
66
    }
67
68
69
    /*
70
     * loadProvider
71
     */
72
    private function loadProvider($provider)
73
    {
74
        App::register($provider);
75
    }
76
77
78
79
80
81
82
    /**
83
     * loadContainersInternalProviders
84
     */
85
    public function loadContainersInternalProviders()
86
    {
87
        foreach ($this->containerServiceProviders as $provider) {
0 ignored issues
show
Bug introduced by
The property containerServiceProviders does not seem to exist. Did you mean serviceProviders?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
88
            $this->loadProvider($provider);
89
        }
90
    }
91
92
93
94
95
96
}
97