1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\services\graphql\resolvers; |
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 ResolverCollection |
15
|
|
|
* SplObjectStorage Collection of EventEspresso\core\services\graphql\ResolverInterface objects |
16
|
|
|
* |
17
|
|
|
* @package EventEspresso\core\services\graphql |
18
|
|
|
* @author Brent Christensen |
19
|
|
|
* @since $VID:$ |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
class ResolverCollection extends Collection |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
const COLLECTION_NAME = 'espresso_graphql_resolvers'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var CollectionLoader $loader |
28
|
|
|
*/ |
29
|
|
|
protected $loader; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* ResolverCollection constructor |
33
|
|
|
* |
34
|
|
|
* @throws InvalidInterfaceException |
35
|
|
|
*/ |
36
|
|
|
public function __construct() |
37
|
|
|
{ |
38
|
|
|
parent::__construct( |
39
|
|
|
'EventEspresso\core\services\graphql\ResolverInterface', |
40
|
|
|
ResolverCollection::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
|
|
|
ResolverCollection::COLLECTION_NAME, |
57
|
|
|
// collection interface |
58
|
|
|
'EventEspresso\core\services\graphql\ResolverInterface', |
59
|
|
|
// FQCNs for classes to add (all classes within each namespace will be loaded) |
60
|
|
|
apply_filters( |
61
|
|
|
'FHEE__EventEspresso_core_services_graphql_ResolverCollection__loadCollection__collection_FQCNs', |
62
|
|
|
['EventEspresso\core\domain\services\graphql\resolvers'] |
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 loadResolvers() |
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
|
|
|
} |