Completed
Branch TASK/11208/update-bundled-gate... (60edbd)
by
unknown
12:10
created

DomainFactory::getShared()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 3
nop 2
dl 0
loc 24
rs 8.6845
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain;
4
5
use DomainException;
6
use EventEspresso\core\domain\values\FullyQualifiedName;
7
use EventEspresso\core\exceptions\InvalidDataTypeException;
8
use EventEspresso\core\exceptions\InvalidInterfaceException;
9
use InvalidArgumentException;
10
use EventEspresso\core\services\loaders\LoaderFactory;
11
12
defined('EVENT_ESPRESSO_VERSION') || exit;
13
14
15
16
/**
17
 * Class DomainFactory
18
 * Factory class for generating addon Domain objects
19
 *
20
 * @package EventEspresso\core\domain
21
 * @author  Brent Christensen
22
 * @since   4.9.50
23
 */
24
class DomainFactory
25
{
26
27
    /**
28
     * @param FullyQualifiedName $domain_fqcn   [required] Fully Qualified Class Name for the Domain class
29
     * @param array $arguments                  [required] array of arguments to be passed to the Domain class
30
     *                                          constructor. Must at least include the following two value objects:
31
     *                                          array(
32
     *                                              EventEspresso\core\domain\values\FilePath $plugin_file
33
     *                                              EventEspresso\core\domain\values\Version $version
34
     *                                          )
35
     * @return mixed
36
     * @throws DomainException
37
     * @throws InvalidArgumentException
38
     * @throws InvalidDataTypeException
39
     * @throws InvalidInterfaceException
40
     */
41
    public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments)
42
    {
43
        if (! isset($arguments[0], $arguments[1])) {
44
            throw new InvalidArgumentException(
45
                esc_html__(
46
                    'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class',
47
                    'event_espresso'
48
                )
49
            );
50
        }
51
        $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments);
52
        if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
53
            throw new DomainException(
54
                sprintf(
55
                    esc_html__(
56
                        'The requested Domain class "%1$s" could not be loaded.',
57
                        'event_espresso'
58
                    ),
59
                    $domain_fqcn
60
                )
61
            );
62
        }
63
        return $domain;
64
    }
65
66
}
67
68
69
70
// Location: DomainFactory.php
71