@@ 21-106 (lines=86) @@ | ||
18 | * @author Brent Christensen |
|
19 | * @since $VID:$ |
|
20 | */ |
|
21 | 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 | } |
@@ 21-106 (lines=86) @@ | ||
18 | * @author Brent Christensen |
|
19 | * @since $VID:$ |
|
20 | */ |
|
21 | 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 | } |
@@ 21-106 (lines=86) @@ | ||
18 | * @author Brent Christensen |
|
19 | * @since $VID:$ |
|
20 | */ |
|
21 | class TypeCollection extends Collection |
|
22 | { |
|
23 | ||
24 | const COLLECTION_NAME = 'espresso_graphql_types'; |
|
25 | ||
26 | /** |
|
27 | * @var CollectionLoader $loader |
|
28 | */ |
|
29 | protected $loader; |
|
30 | ||
31 | /** |
|
32 | * TypeCollection constructor |
|
33 | * |
|
34 | * @throws InvalidInterfaceException |
|
35 | */ |
|
36 | public function __construct() |
|
37 | { |
|
38 | parent::__construct( |
|
39 | 'EventEspresso\core\services\graphql\types\TypeInterface', |
|
40 | TypeCollection::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 | TypeCollection::COLLECTION_NAME, |
|
57 | // collection interface |
|
58 | 'EventEspresso\core\services\graphql\types\TypeInterface', |
|
59 | // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
60 | apply_filters( |
|
61 | 'FHEE__EventEspresso_core_services_graphql_TypeCollection__loadCollection__collection_FQCNs', |
|
62 | ['EventEspresso\core\domain\services\graphql\types'] |
|
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 loadTypes() |
|
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 | } |