-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTypeRegistry.php
More file actions
304 lines (270 loc) · 8.22 KB
/
TypeRegistry.php
File metadata and controls
304 lines (270 loc) · 8.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
/**
* Registers Plugin types to the GraphQL schema.
*
* @package WPGraphQL\RankMath
*/
declare( strict_types = 1 );
namespace WPGraphQL\RankMath;
use Exception;
use WPGraphQL\RankMath\Fields;
use WPGraphQL\RankMath\Modules\Redirection\TypeRegistry as RedirectionTypeRegistry;
use WPGraphQL\RankMath\Type\Enum;
use WPGraphQL\RankMath\Type\WPInterface;
use WPGraphQL\RankMath\Type\WPObject;
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Interfaces\Registrable;
/**
* Class - TypeRegistry
*/
class TypeRegistry {
/**
* The local registry of registered types.
*
* @var string[]
*/
public static array $registry = [];
/**
* Gets an array of all the registered GraphQL types along with their class name.
*
* @return string[]
*/
public static function get_registered_types(): array {
if ( empty( self::$registry ) ) {
self::initialize_registry();
}
return self::$registry;
}
/**
* Registers types, connections, unions, and mutations to GraphQL schema.
*/
public static function init(): void {
/**
* Fires before all types have been registered.
*/
do_action( 'graphql_seo_before_register_types' );
// Register individual modules.
RedirectionTypeRegistry::init();
// Initialize the registry.
self::initialize_registry();
/**
* Fires after all types have been registered.
*/
do_action( 'graphql_seo_after_register_types' );
}
/**
* Initializes the plugin type registry.
*/
private static function initialize_registry(): void {
$classes_to_register = array_merge(
self::enums(),
self::inputs(),
self::interfaces(),
self::objects(),
self::connections(),
self::mutations(),
self::fields(),
);
self::register_types( $classes_to_register );
}
/**
* List of Enum classes to register.
*
* @return string[]
*/
private static function enums(): array {
// Enums to register.
$classes_to_register = [
Enum\ArticleTypeEnum::class,
Enum\BulkEditingTypeEnum::class,
Enum\ImagePreviewSizeEnum::class,
Enum\KnowledgeGraphTypeEnum::class,
Enum\OpenGraphLocaleEnum::class,
Enum\OpenGraphProductAvailabilityEnum::class,
Enum\RobotsMetaValueEnum::class,
Enum\SeoScorePositionEnum::class,
Enum\SeoScoreTemplateTypeEnum::class,
Enum\SeoRatingEnum::class,
Enum\SnippetTypeEnum::class,
Enum\TwitterCardTypeEnum::class,
];
/**
* Filters the list of enum classes to register.
*
* Useful for adding/removing specific enums to the schema.
*
* @param array $classes_to_register Array of classes to be registered to the schema.
*/
return apply_filters( 'graphql_seo_registered_enum_classes', $classes_to_register );
}
/**
* List of Input classes to register.
*
* @return string[]
*/
private static function inputs(): array {
$classes_to_register = [];
/**
* Filters the list of input classes to register.
*
* Useful for adding/removing specific inputs to the schema.
*
* @param array $classes_to_register Array of classes to be registered to the schema.
*/
return apply_filters( 'graphql_seo_registered_input_classes', $classes_to_register );
}
/**
* List of Interface classes to register.
*
* @return string[]
*/
public static function interfaces(): array {
$classes_to_register = [
WPInterface\MetaSettingWithArchive::class,
WPInterface\MetaSettingWithRobots::class,
WPInterface\Seo::class,
WPInterface\ContentNodeSeo::class,
WPInterface\NodeWithSeo::class,
];
/**
* Filters the list of interfaces classes to register.
*
* Useful for adding/removing specific interfaces to the schema.
*
* @param array $classes_to_register = Array of classes to be registered to the schema.
*/
return apply_filters( 'graphql_seo_registered_interface_classes', $classes_to_register );
}
/**
* List of Object classes to register.
*
* @return string[]
*/
public static function objects(): array {
$classes_to_register = [
WPObject\AdvancedRobotsMeta::class,
WPObject\SeoScore::class,
WPObject\JsonLd::class,
WPObject\Breadcrumbs::class,
// Open Graph.
WPObject\OpenGraph\Article::class,
WPObject\OpenGraph\Facebook::class,
WPObject\OpenGraph\Image::class,
WPObject\OpenGraph\Product::class,
WPObject\OpenGraph\SlackEnhancedData::class,
WPObject\OpenGraph\TwitterApp::class,
WPObject\OpenGraph\Twitter::class,
WPObject\OpenGraph\Video::class,
WPObject\OpenGraphMeta::class,
// General settings.
WPObject\Settings\General\BreadcrumbsConfig::class,
WPObject\Settings\General\FrontendSeoScore::class,
WPObject\Settings\General\Links::class,
WPObject\Settings\General\Webmaster::class,
WPObject\Settings\General::class,
// Meta settings.
WPObject\Settings\Meta\AuthorArchiveMeta::class,
WPObject\Settings\Meta\ContentTypeMeta::class,
WPObject\Settings\Meta\DateArchiveMeta::class,
WPObject\Settings\Meta\GlobalMeta::class,
WPObject\Settings\Meta\HomepageMeta::class,
WPObject\Settings\Meta\LocalMeta::class,
WPObject\Settings\Meta\SocialMeta::class,
WPObject\Settings\Meta\TaxonomyMeta::class,
WPObject\Settings\Meta::class,
// Sitemap settings.
WPObject\Settings\Sitemap\Author::class,
WPObject\Settings\Sitemap\ContentType::class,
WPObject\Settings\Sitemap\General::class,
WPObject\Settings\Sitemap\Taxonomy::class,
WPObject\Settings\Sitemap::class,
// Settings.
WPObject\Settings::class,
// The individual SEO objects.
WPObject\SeoObjects::class,
];
/**
* Filters the list of object classes to register.
*
* Useful for adding/removing specific objects to the schema.
*
* @param array $classes_to_register = Array of classes to be registered to the schema.
*/
return apply_filters( 'graphql_seo_registered_object_classes', $classes_to_register );
}
/**
* List of Field classes to register.
*
* @return string[]
*/
public static function fields(): array {
$classes_to_register = [
Fields\RootQuery::class,
];
/**
* Filters the list of field classes to register.
*
* Useful for adding/removing specific fields to the schema.
*
* @param array $classes_to_register = Array of classes to be registered to the schema.
*/
return apply_filters( 'graphql_seo_registered_field_classes', $classes_to_register );
}
/**
* List of Connection classes to register.
*
* @return string[]
*/
public static function connections(): array {
$classes_to_register = [];
/**
* Filters the list of connection classes to register.
*
* Useful for adding/removing specific connections to the schema.
*
* @param array $classes_to_register = Array of classes to be registered to the schema.
*/
return apply_filters( 'graphql_seo_registered_connection_classes', $classes_to_register );
}
/**
* Registers mutation.
*
* @return string[]
*/
public static function mutations(): array {
$classes_to_register = [];
/**
* Filters the list of connection classes to register.
*
* Useful for adding/removing specific connections to the schema.
*
* @param array $classes_to_register = Array of classes to be registered to the schema.
*/
$classes_to_register = apply_filters( 'graphql_seo_registered_mutation_classes', $classes_to_register );
return $classes_to_register;
}
/**
* Loops through a list of classes to manually register each GraphQL to the registry, and stores the type name and class in the local registry.
*
* Classes must extend WPGraphQL\Type\AbstractType.
*
* @param string[] $classes_to_register .
*
* @throws \Exception .
*/
private static function register_types( array $classes_to_register ): void {
// Bail if there are no classes to register.
if ( empty( $classes_to_register ) ) {
return;
}
foreach ( $classes_to_register as $class ) {
if ( ! is_a( $class, Registrable::class, true ) ) {
// translators: PHP class.
throw new Exception( sprintf( esc_html__( 'To be registered to the WPGraphQL Plugin Name GraphQL schema, %s needs to implement WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Interfaces\Registrable.', 'wp-graphql-rank-math' ), esc_html( $class ) ) );
}
// Register the type to the GraphQL schema.
$class::init();
// Store the type in the local registry.
self::$registry[] = $class;
}
}
}