Completed
Branch EDTR/refactor-fast-api-fetch (d0e0df)
by
unknown
09:08 queued 34s
created

ConnectionCollection::loadCollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 26
loc 26
rs 9.504
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\services\graphql\connections;
4
5
use EventEspresso\core\exceptions\InvalidInterfaceException;
6
use EventEspresso\core\services\collections\Collection;
7
use EventEspresso\core\services\collections\CollectionDetails;
8
use EventEspresso\core\services\collections\CollectionDetailsException;
9
use EventEspresso\core\services\collections\CollectionInterface;
10
use EventEspresso\core\services\collections\CollectionLoader;
11
use EventEspresso\core\services\collections\CollectionLoaderException;
12
13
/**
14
 * Class ConnectionCollection
15
 * SplObjectStorage Collection of EventEspresso\core\services\graphql\connections\ConnectionInterface objects
16
 *
17
 * @package EventEspresso\core\services\graphql
18
 * @author  Brent Christensen
19
 * @since   $VID:$
20
 */
21 View Code Duplication
class ConnectionCollection extends Collection
22
{
23
24
    const COLLECTION_NAME = 'espresso_graphql_connections';
25
26
    /**
27
     * @var CollectionLoader $loader
28
     */
29
    protected $loader;
30
31
    /**
32
     * ConnectionCollection constructor
33
     *
34
     * @throws InvalidInterfaceException
35
     */
36
    public function __construct()
37
    {
38
        parent::__construct(
39
            'EventEspresso\core\services\graphql\connections\ConnectionInterface',
40
            ConnectionCollection::COLLECTION_NAME
41
        );
42
    }
43
44
45
    /**
46
     * @throws CollectionDetailsException
47
     * @throws CollectionLoaderException
48
     * @since $VID:$
49
     */
50
    private function loadCollection()
51
    {
52
        if (! $this->loader instanceof CollectionLoader) {
53
            $this->loader = new CollectionLoader(
54
                new CollectionDetails(
55
                // collection name
56
                    ConnectionCollection::COLLECTION_NAME,
57
                    // collection interface
58
                    'EventEspresso\core\services\graphql\connections\ConnectionInterface',
59
                    // FQCNs for classes to add (all classes within each namespace will be loaded)
60
                    apply_filters(
61
                        'FHEE__EventEspresso_core_services_graphql_ConnectionCollection__loadCollection__collection_FQCNs',
62
                        ['EventEspresso\core\domain\services\graphql\connections']
63
                    ),
64
                    // filepaths to classes to add
65
                    array(),
66
                    // file mask to use if parsing folder for files to add
67
                    '',
68
                    // what to use as identifier for collection entities
69
                    // using CLASS NAME prevents duplicates (works like a singleton)
70
                    CollectionDetails::ID_CLASS_NAME
71
                ),
72
                $this
73
            );
74
        }
75
    }
76
77
78
    /**
79
     * @return CollectionInterface
80
     * @throws CollectionDetailsException
81
     * @throws CollectionLoaderException
82
     * @since $VID:$
83
     */
84
    public function loadConnections()
85
    {
86
        $this->loadCollection();
87
        return $this->loader->getCollection();
88
    }
89
90
91
    /**
92
     * getIdentifier
93
     * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
94
     * If no $identifier is supplied, then the  fully qualified class name is used
95
     *
96
     * @param        $object
97
     * @param mixed  $identifier
98
     * @return bool
99
     */
100
    public function getIdentifier($object, $identifier = null)
101
    {
102
        return ! empty($identifier)
103
            ? $identifier
104
            : get_class($object);
105
    }
106
}