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