Completed
Branch FET-10657-loader (efdbe3)
by
unknown
211:33 queued 198:16
created

CoreLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 45
rs 10
c 1
b 0
f 0
wmc 5
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A load() 0 6 2
1
<?php
2
3
namespace EventEspresso\core\services\loaders;
4
5
use EE_Registry;
6
use EventEspresso\core\services\container\CoffeeShop;
7
use EventEspresso\core\services\container\exceptions\ServiceNotFoundException;
8
use InvalidArgumentException;
9
10
defined('EVENT_ESPRESSO_VERSION') || exit;
11
12
13
14
/**
15
 * Class CoreLoader
16
 * Currently uses EE_Registry for instantiating classes,
17
 * but will later be replaced by the CoffeeShop DI container
18
 *
19
 * @package       Event Espresso
20
 * @author        Brent Christensen
21
 * @since         $VID:$
22
 */
23
class CoreLoader implements LoaderInterface
24
{
25
26
    /**
27
     * @var EE_Registry|CoffeeShop $generator
28
     */
29
    private $generator;
30
31
32
33
    /**
34
     * CoreLoader constructor.
35
     *
36
     * @param EE_Registry|CoffeeShop $generator
37
     * @throws InvalidArgumentException
38
     */
39
    public function __construct($generator)
40
    {
41
        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
42
            throw new InvalidArgumentException(
43
                esc_html__(
44
                    'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
45
                    'event_espresso'
46
                )
47
            );
48
        }
49
        $this->generator = $generator;
50
    }
51
52
53
54
    /**
55
     * @param string $fqcn
56
     * @param array  $arguments
57
     * @return mixed
58
     * @throws ServiceNotFoundException
59
     */
60
    public function load($fqcn, $arguments = array())
61
    {
62
        return $this->generator instanceof EE_Registry
63
            ? $this->generator->create($fqcn, $arguments)
64
            : $this->generator->brew($fqcn, $arguments);
65
    }
66
67
}
68
// End of file CoreLoader.php
69
// Location: core/services/loaders/CoreLoader.php