Passed
Push — 0.8.x ( dc0566...6e510b )
by Alexander
06:23 queued 03:10
created

AggregateServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 46
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 11 2
A register() 0 6 2
1
<?php
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2023 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
namespace Syscodes\Components\Support;
24
25
/**
26
 * Allows the register of service providers.
27
 */
28
class AggregateServiceProvider extends ServiceProvider
29
{
30
    /**
31
     * The provider class names.
32
     * 
33
     * @var array $providers
34
     */
35
    protected $providers = [];
36
    
37
    /**
38
     * An array of the service provider instances.
39
     * 
40
     * @var array $instances
41
     */
42
    protected $instances = [];
43
    
44
    /**
45
     * Register the service provider.
46
     * 
47
     * @return void
48
     */
49
    public function register()
50
    {
51
        $this->instances = [];
52
        
53
        foreach ($this->providers as $provider) {
54
            $this->instances[] = $this->app->register($provider);
55
        }
56
    }
57
    
58
    /**
59
     * Get the services provided by the provider.
60
     * 
61
     * @return array
62
     */
63
    public function provides(): array
64
    {
65
        $provides = [];
66
        
67
        foreach ($this->providers as $provider) {
68
            $instance = $this->app->resolveProviderClass($provider);
69
            
70
            $provides = array_merge($provides, $instance->provides());
71
        }
72
        
73
        return $provides;
74
    }
75
}