1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Event Espresso |
4
|
|
|
* Manage events, sell tickets, and receive payments from your WordPress website. |
5
|
|
|
* Copyright (c) 2008-2019 Event Espresso All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace EventEspresso\core\services\graphql; |
22
|
|
|
|
23
|
|
|
use EventEspresso\core\services\collections\CollectionDetailsException; |
24
|
|
|
use EventEspresso\core\services\collections\CollectionLoaderException; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class ConnectionsManager |
28
|
|
|
* Loads and registers custom GraphQL Connections |
29
|
|
|
* |
30
|
|
|
* @package EventEspresso\core\services\graphql |
31
|
|
|
* @author Brent Christensen |
32
|
|
|
* @since $VID:$ |
33
|
|
|
*/ |
34
|
|
|
class ConnectionsManager |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var ConnectionCollection|ConnectionInterface[] $connections |
39
|
|
|
*/ |
40
|
|
|
private $connections; |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* ConnectionsManager constructor. |
45
|
|
|
* |
46
|
|
|
* @param ConnectionCollection|ConnectionInterface[] $connections |
47
|
|
|
*/ |
48
|
|
|
public function __construct(ConnectionCollection $connections) |
49
|
|
|
{ |
50
|
|
|
$this->connections = $connections; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @throws CollectionDetailsException |
56
|
|
|
* @throws CollectionLoaderException |
57
|
|
|
* @since $VID:$ |
58
|
|
|
*/ |
59
|
|
|
public function init() |
60
|
|
|
{ |
61
|
|
|
$this->connections->loadConnections(); |
62
|
|
|
add_action('graphql_register_types', [$this, 'registerConnections'], 20); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function registerConnections() |
67
|
|
|
{ |
68
|
|
|
// loop through the collection of types and register their fields |
69
|
|
|
foreach ($this->connections as $connection) { |
70
|
|
|
register_graphql_connection($connection->config()); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |