Completed
Branch EDTR/graphql-data-loaders (8642bb)
by
unknown
09:27 queued 44s
created

DataLoaderManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A init() 0 7 2
1
<?php
2
3
namespace EventEspresso\core\services\graphql;
4
5
use EventEspresso\core\services\graphql\loaders\GQLDataDomainInterface;
6
use EventEspresso\core\services\collections\CollectionDetailsException;
7
use EventEspresso\core\services\collections\CollectionLoaderException;
8
use EventEspresso\core\services\graphql\loaders\DataLoaderCollection;
9
10
/**
11
 * Class DataLoaderManager
12
 * Retrieves data loader classes for each domain and registers their data loaders with GQL
13
 *
14
 * @package EventEspresso\core\services\graphql
15
 * @author  Brent Christensen
16
 * @since   $VID:$
17
 */
18
class DataLoaderManager implements GQLManagerInterface
19
{
20
21
    /**
22
     * @var DataLoaderCollection|GQLDataDomainInterface[] $data_loaders
23
     */
24
    private $data_loaders;
25
26
27
    /**
28
     * @param DataLoaderCollection|GQLDataDomainInterface[] $data_loaders
29
     */
30
    public function __construct(DataLoaderCollection $data_loaders)
31
    {
32
        $this->data_loaders = $data_loaders;
33
    }
34
35
36
    /**
37
     * @throws CollectionDetailsException
38
     * @throws CollectionLoaderException
39
     * @since $VID:$
40
     */
41
    public function init()
42
    {
43
        $data_loaders = $this->data_loaders->getDataLoaders();
44
        foreach ($data_loaders as $data_loader) {
45
            add_filter('graphql_data_loaders', [$data_loader, 'registerLoaders'], 10, 2);
46
        }
47
    }
48
}
49