@@ -11,48 +11,48 @@ |
||
11 | 11 | class FormElementDelete extends EntityMutator |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Defines the mutation data modification closure. |
|
16 | - * |
|
17 | - * @param EEM_Form_Element $model |
|
18 | - * @return callable |
|
19 | - */ |
|
20 | - public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
21 | - { |
|
22 | - /** |
|
23 | - * Deletes an entity. |
|
24 | - * |
|
25 | - * @param array $input The input for the mutation |
|
26 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | - try { |
|
32 | - /** @var EE_Form_Element $entity */ |
|
33 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
14 | + /** |
|
15 | + * Defines the mutation data modification closure. |
|
16 | + * |
|
17 | + * @param EEM_Form_Element $model |
|
18 | + * @return callable |
|
19 | + */ |
|
20 | + public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
21 | + { |
|
22 | + /** |
|
23 | + * Deletes an entity. |
|
24 | + * |
|
25 | + * @param array $input The input for the mutation |
|
26 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | + try { |
|
32 | + /** @var EE_Form_Element $entity */ |
|
33 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
34 | 34 | |
35 | - $result = $entity->delete(); |
|
36 | - EntityMutator::validateResults($result); |
|
35 | + $result = $entity->delete(); |
|
36 | + EntityMutator::validateResults($result); |
|
37 | 37 | |
38 | - do_action( |
|
39 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_delete', |
|
40 | - $entity, |
|
41 | - $input |
|
42 | - ); |
|
43 | - } catch (Exception $exception) { |
|
44 | - EntityMutator::handleExceptions( |
|
45 | - $exception, |
|
46 | - esc_html__( |
|
47 | - 'The form element could not be deleted because of the following error(s)', |
|
48 | - 'event_espresso' |
|
49 | - ) |
|
50 | - ); |
|
51 | - } |
|
38 | + do_action( |
|
39 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_delete', |
|
40 | + $entity, |
|
41 | + $input |
|
42 | + ); |
|
43 | + } catch (Exception $exception) { |
|
44 | + EntityMutator::handleExceptions( |
|
45 | + $exception, |
|
46 | + esc_html__( |
|
47 | + 'The form element could not be deleted because of the following error(s)', |
|
48 | + 'event_espresso' |
|
49 | + ) |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - return [ |
|
54 | - 'deleted' => $entity, |
|
55 | - ]; |
|
56 | - }; |
|
57 | - } |
|
53 | + return [ |
|
54 | + 'deleted' => $entity, |
|
55 | + ]; |
|
56 | + }; |
|
57 | + } |
|
58 | 58 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
30 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | 31 | try { |
32 | 32 | /** @var EE_Form_Element $entity */ |
33 | 33 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -12,51 +12,51 @@ |
||
12 | 12 | class FormElementCreate extends EntityMutator |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Defines the mutation data modification closure. |
|
17 | - * |
|
18 | - * @param EEM_Form_Element $model |
|
19 | - * @return callable |
|
20 | - */ |
|
21 | - public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
22 | - { |
|
23 | - /** |
|
24 | - * Creates an entity. |
|
25 | - * |
|
26 | - * @param array $input The input for the mutation |
|
27 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
28 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
32 | - $id = null; |
|
33 | - try { |
|
34 | - EntityMutator::checkPermissions($model); |
|
35 | - |
|
36 | - $args = FormElementMutation::prepareFields($input); |
|
37 | - |
|
38 | - $entity = EE_Form_Element::new_instance($args); |
|
39 | - $id = $entity->save(); |
|
40 | - EntityMutator::validateResults($id); |
|
41 | - |
|
42 | - do_action( |
|
43 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_create', |
|
44 | - $entity, |
|
45 | - $input |
|
46 | - ); |
|
47 | - } catch (Exception $exception) { |
|
48 | - EntityMutator::handleExceptions( |
|
49 | - $exception, |
|
50 | - esc_html__( |
|
51 | - 'The form element could not be created because of the following error(s)', |
|
52 | - 'event_espresso' |
|
53 | - ) |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - return [ |
|
58 | - 'id' => $id, |
|
59 | - ]; |
|
60 | - }; |
|
61 | - } |
|
15 | + /** |
|
16 | + * Defines the mutation data modification closure. |
|
17 | + * |
|
18 | + * @param EEM_Form_Element $model |
|
19 | + * @return callable |
|
20 | + */ |
|
21 | + public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
22 | + { |
|
23 | + /** |
|
24 | + * Creates an entity. |
|
25 | + * |
|
26 | + * @param array $input The input for the mutation |
|
27 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
28 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
32 | + $id = null; |
|
33 | + try { |
|
34 | + EntityMutator::checkPermissions($model); |
|
35 | + |
|
36 | + $args = FormElementMutation::prepareFields($input); |
|
37 | + |
|
38 | + $entity = EE_Form_Element::new_instance($args); |
|
39 | + $id = $entity->save(); |
|
40 | + EntityMutator::validateResults($id); |
|
41 | + |
|
42 | + do_action( |
|
43 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_create', |
|
44 | + $entity, |
|
45 | + $input |
|
46 | + ); |
|
47 | + } catch (Exception $exception) { |
|
48 | + EntityMutator::handleExceptions( |
|
49 | + $exception, |
|
50 | + esc_html__( |
|
51 | + 'The form element could not be created because of the following error(s)', |
|
52 | + 'event_espresso' |
|
53 | + ) |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + return [ |
|
58 | + 'id' => $id, |
|
59 | + ]; |
|
60 | + }; |
|
61 | + } |
|
62 | 62 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
32 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
33 | 33 | $id = null; |
34 | 34 | try { |
35 | 35 | EntityMutator::checkPermissions($model); |
@@ -14,52 +14,52 @@ |
||
14 | 14 | class FormElementUpdate extends EntityMutator |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Form_Element $model |
|
21 | - * @return callable |
|
22 | - */ |
|
23 | - public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
24 | - { |
|
25 | - /** |
|
26 | - * Updates an entity. |
|
27 | - * |
|
28 | - * @param array $input The input for the mutation |
|
29 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | - * @return array |
|
32 | - * @throws EE_Error |
|
33 | - * @throws ReflectionException |
|
34 | - */ |
|
35 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | - try { |
|
37 | - /** @var EE_Form_Element $entity */ |
|
38 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Form_Element $model |
|
21 | + * @return callable |
|
22 | + */ |
|
23 | + public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
24 | + { |
|
25 | + /** |
|
26 | + * Updates an entity. |
|
27 | + * |
|
28 | + * @param array $input The input for the mutation |
|
29 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | + * @return array |
|
32 | + * @throws EE_Error |
|
33 | + * @throws ReflectionException |
|
34 | + */ |
|
35 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | + try { |
|
37 | + /** @var EE_Form_Element $entity */ |
|
38 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
39 | 39 | |
40 | - $args = FormElementMutation::prepareFields($input); |
|
40 | + $args = FormElementMutation::prepareFields($input); |
|
41 | 41 | |
42 | - // Update the entity |
|
43 | - $entity->save($args); |
|
42 | + // Update the entity |
|
43 | + $entity->save($args); |
|
44 | 44 | |
45 | - do_action( |
|
46 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_update', |
|
47 | - $entity, |
|
48 | - $input |
|
49 | - ); |
|
50 | - } catch (Exception $exception) { |
|
51 | - EntityMutator::handleExceptions( |
|
52 | - $exception, |
|
53 | - esc_html__( |
|
54 | - 'The form element could not be updated because of the following error(s)', |
|
55 | - 'event_espresso' |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
45 | + do_action( |
|
46 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_update', |
|
47 | + $entity, |
|
48 | + $input |
|
49 | + ); |
|
50 | + } catch (Exception $exception) { |
|
51 | + EntityMutator::handleExceptions( |
|
52 | + $exception, |
|
53 | + esc_html__( |
|
54 | + 'The form element could not be updated because of the following error(s)', |
|
55 | + 'event_espresso' |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - return [ |
|
61 | - 'id' => $entity->UUID(), |
|
62 | - ]; |
|
63 | - }; |
|
64 | - } |
|
60 | + return [ |
|
61 | + 'id' => $entity->UUID(), |
|
62 | + ]; |
|
63 | + }; |
|
64 | + } |
|
65 | 65 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @throws EE_Error |
33 | 33 | * @throws ReflectionException |
34 | 34 | */ |
35 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
35 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | 36 | try { |
37 | 37 | /** @var EE_Form_Element $entity */ |
38 | 38 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -49,7 +49,7 @@ |
||
49 | 49 | $args['FSC_status'] = sanitize_text_field($input['status']); |
50 | 50 | } |
51 | 51 | |
52 | - if (! empty($input['wpUser'])) { |
|
52 | + if ( ! empty($input['wpUser'])) { |
|
53 | 53 | $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
54 | 54 | $args['FSC_wpUser'] = ! empty($parts['id']) ? $parts['id'] : null; |
55 | 55 | } |
@@ -15,54 +15,54 @@ |
||
15 | 15 | class FormSectionMutation |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Maps the GraphQL input to a format that the model functions can use |
|
20 | - * |
|
21 | - * @param array $input Data coming from the GraphQL mutation query input |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public static function prepareFields(array $input): array |
|
25 | - { |
|
26 | - $args = []; |
|
18 | + /** |
|
19 | + * Maps the GraphQL input to a format that the model functions can use |
|
20 | + * |
|
21 | + * @param array $input Data coming from the GraphQL mutation query input |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public static function prepareFields(array $input): array |
|
25 | + { |
|
26 | + $args = []; |
|
27 | 27 | |
28 | - if (isset($input['id'])) { |
|
29 | - $args['FSC_UUID'] = sanitize_text_field($input['id']); |
|
30 | - } |
|
28 | + if (isset($input['id'])) { |
|
29 | + $args['FSC_UUID'] = sanitize_text_field($input['id']); |
|
30 | + } |
|
31 | 31 | |
32 | - if (isset($input['appliesTo'])) { |
|
33 | - $args['FSC_appliesTo'] = sanitize_text_field($input['appliesTo']); |
|
34 | - } |
|
32 | + if (isset($input['appliesTo'])) { |
|
33 | + $args['FSC_appliesTo'] = sanitize_text_field($input['appliesTo']); |
|
34 | + } |
|
35 | 35 | |
36 | - if (isset($input['attributes'])) { |
|
37 | - $args['FSC_attributes'] = Attributes::fromJson(sanitize_text_field($input['attributes']))->toJson(); |
|
38 | - } |
|
36 | + if (isset($input['attributes'])) { |
|
37 | + $args['FSC_attributes'] = Attributes::fromJson(sanitize_text_field($input['attributes']))->toJson(); |
|
38 | + } |
|
39 | 39 | |
40 | - if (isset($input['belongsTo'])) { |
|
41 | - $args['FSC_belongsTo'] = sanitize_text_field($input['belongsTo']); |
|
42 | - } |
|
40 | + if (isset($input['belongsTo'])) { |
|
41 | + $args['FSC_belongsTo'] = sanitize_text_field($input['belongsTo']); |
|
42 | + } |
|
43 | 43 | |
44 | - if (isset($input['label'])) { |
|
45 | - $args['FSC_label'] = FormLabel::fromJson(sanitize_text_field($input['label']))->toJson(); |
|
46 | - } |
|
44 | + if (isset($input['label'])) { |
|
45 | + $args['FSC_label'] = FormLabel::fromJson(sanitize_text_field($input['label']))->toJson(); |
|
46 | + } |
|
47 | 47 | |
48 | - // order can be 0 |
|
49 | - if (array_key_exists('order', $input)) { |
|
50 | - $args['FSC_order'] = absint($input['order']); |
|
51 | - } |
|
48 | + // order can be 0 |
|
49 | + if (array_key_exists('order', $input)) { |
|
50 | + $args['FSC_order'] = absint($input['order']); |
|
51 | + } |
|
52 | 52 | |
53 | - if (isset($input['status'])) { |
|
54 | - $args['FSC_status'] = sanitize_text_field($input['status']); |
|
55 | - } |
|
53 | + if (isset($input['status'])) { |
|
54 | + $args['FSC_status'] = sanitize_text_field($input['status']); |
|
55 | + } |
|
56 | 56 | |
57 | - if (! empty($input['wpUser'])) { |
|
58 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
59 | - $args['FSC_wpUser'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
60 | - } |
|
57 | + if (! empty($input['wpUser'])) { |
|
58 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
59 | + $args['FSC_wpUser'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
60 | + } |
|
61 | 61 | |
62 | - return apply_filters( |
|
63 | - 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__form_section_args', |
|
64 | - $args, |
|
65 | - $input |
|
66 | - ); |
|
67 | - } |
|
62 | + return apply_filters( |
|
63 | + 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__form_section_args', |
|
64 | + $args, |
|
65 | + $input |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | } |
@@ -15,27 +15,27 @@ |
||
15 | 15 | */ |
16 | 16 | class FormElementLoader extends AbstractLoader |
17 | 17 | { |
18 | - /** |
|
19 | - * @return EEM_Base |
|
20 | - * @throws EE_Error |
|
21 | - * @throws InvalidArgumentException |
|
22 | - * @throws InvalidDataTypeException |
|
23 | - * @throws InvalidInterfaceException |
|
24 | - * @throws ReflectionException |
|
25 | - */ |
|
26 | - protected function getQuery(): EEM_Base |
|
27 | - { |
|
28 | - return EEM_Form_Element::instance(); |
|
29 | - } |
|
18 | + /** |
|
19 | + * @return EEM_Base |
|
20 | + * @throws EE_Error |
|
21 | + * @throws InvalidArgumentException |
|
22 | + * @throws InvalidDataTypeException |
|
23 | + * @throws InvalidInterfaceException |
|
24 | + * @throws ReflectionException |
|
25 | + */ |
|
26 | + protected function getQuery(): EEM_Base |
|
27 | + { |
|
28 | + return EEM_Form_Element::instance(); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param array $keys |
|
33 | - * @return array |
|
34 | - */ |
|
35 | - protected function getWhereParams(array $keys): array |
|
36 | - { |
|
37 | - return [ |
|
38 | - 'FIN_UUID' => ['IN', $keys], |
|
39 | - ]; |
|
40 | - } |
|
31 | + /** |
|
32 | + * @param array $keys |
|
33 | + * @return array |
|
34 | + */ |
|
35 | + protected function getWhereParams(array $keys): array |
|
36 | + { |
|
37 | + return [ |
|
38 | + 'FIN_UUID' => ['IN', $keys], |
|
39 | + ]; |
|
40 | + } |
|
41 | 41 | } |
@@ -19,28 +19,28 @@ |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param $entity |
|
24 | - * @param $args |
|
25 | - * @param $context |
|
26 | - * @param $info |
|
27 | - * @return AbstractConnectionResolver |
|
28 | - * @throws Exception |
|
29 | - */ |
|
30 | - abstract public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver; |
|
22 | + /** |
|
23 | + * @param $entity |
|
24 | + * @param $args |
|
25 | + * @param $context |
|
26 | + * @param $info |
|
27 | + * @return AbstractConnectionResolver |
|
28 | + * @throws Exception |
|
29 | + */ |
|
30 | + abstract public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @param $entity |
|
35 | - * @param $args |
|
36 | - * @param $context |
|
37 | - * @param $info |
|
38 | - * @return mixed|array|Deferred |
|
39 | - * @throws Exception |
|
40 | - */ |
|
41 | - public function resolveConnection($entity, $args, $context, $info) |
|
42 | - { |
|
43 | - $resolver = $this->getConnectionResolver($entity, $args, $context, $info); |
|
44 | - return $resolver->get_connection(); |
|
45 | - } |
|
33 | + /** |
|
34 | + * @param $entity |
|
35 | + * @param $args |
|
36 | + * @param $context |
|
37 | + * @param $info |
|
38 | + * @return mixed|array|Deferred |
|
39 | + * @throws Exception |
|
40 | + */ |
|
41 | + public function resolveConnection($entity, $args, $context, $info) |
|
42 | + { |
|
43 | + $resolver = $this->getConnectionResolver($entity, $args, $context, $info); |
|
44 | + return $resolver->get_connection(); |
|
45 | + } |
|
46 | 46 | } |
@@ -19,223 +19,223 @@ |
||
19 | 19 | */ |
20 | 20 | class GQLRequests extends Route |
21 | 21 | { |
22 | - /** |
|
23 | - * @var AssetManifestFactory |
|
24 | - */ |
|
25 | - private $manifest_factory; |
|
22 | + /** |
|
23 | + * @var AssetManifestFactory |
|
24 | + */ |
|
25 | + private $manifest_factory; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * AssetRequests constructor. |
|
30 | - * |
|
31 | - * @param EE_Dependency_Map $dependency_map |
|
32 | - * @param LoaderInterface $loader |
|
33 | - * @param RequestInterface $request |
|
34 | - * @param AssetManifestFactory $manifest_factory |
|
35 | - */ |
|
36 | - public function __construct( |
|
37 | - EE_Dependency_Map $dependency_map, |
|
38 | - LoaderInterface $loader, |
|
39 | - RequestInterface $request, |
|
40 | - AssetManifestFactory $manifest_factory |
|
41 | - ) { |
|
42 | - $this->manifest_factory = $manifest_factory; |
|
43 | - parent::__construct($dependency_map, $loader, $request); |
|
44 | - } |
|
28 | + /** |
|
29 | + * AssetRequests constructor. |
|
30 | + * |
|
31 | + * @param EE_Dependency_Map $dependency_map |
|
32 | + * @param LoaderInterface $loader |
|
33 | + * @param RequestInterface $request |
|
34 | + * @param AssetManifestFactory $manifest_factory |
|
35 | + */ |
|
36 | + public function __construct( |
|
37 | + EE_Dependency_Map $dependency_map, |
|
38 | + LoaderInterface $loader, |
|
39 | + RequestInterface $request, |
|
40 | + AssetManifestFactory $manifest_factory |
|
41 | + ) { |
|
42 | + $this->manifest_factory = $manifest_factory; |
|
43 | + parent::__construct($dependency_map, $loader, $request); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * returns true if the current request matches this route |
|
49 | - * |
|
50 | - * @return bool |
|
51 | - * @since $VID:$ |
|
52 | - */ |
|
53 | - public function matchesCurrentRequest(): bool |
|
54 | - { |
|
55 | - global $pagenow; |
|
56 | - return ( |
|
57 | - $this->request->isGQL() |
|
58 | - || $this->request->isUnitTesting() |
|
59 | - || ( |
|
60 | - $this->request->isAdmin() |
|
61 | - && $this->request->getRequestParam('page') === 'espresso_events' |
|
62 | - && ( |
|
63 | - $this->request->getRequestParam('action') === 'create_new' |
|
64 | - || $this->request->getRequestParam('action') === 'edit' |
|
65 | - ) |
|
66 | - ) |
|
67 | - || ( |
|
68 | - $pagenow |
|
69 | - && ( |
|
70 | - $pagenow === 'post-new.php' |
|
71 | - || ( |
|
72 | - $pagenow === 'post.php' |
|
73 | - && $this->request->getRequestParam('action') === 'edit' |
|
74 | - ) |
|
75 | - ) |
|
76 | - ) |
|
77 | - ); |
|
78 | - } |
|
47 | + /** |
|
48 | + * returns true if the current request matches this route |
|
49 | + * |
|
50 | + * @return bool |
|
51 | + * @since $VID:$ |
|
52 | + */ |
|
53 | + public function matchesCurrentRequest(): bool |
|
54 | + { |
|
55 | + global $pagenow; |
|
56 | + return ( |
|
57 | + $this->request->isGQL() |
|
58 | + || $this->request->isUnitTesting() |
|
59 | + || ( |
|
60 | + $this->request->isAdmin() |
|
61 | + && $this->request->getRequestParam('page') === 'espresso_events' |
|
62 | + && ( |
|
63 | + $this->request->getRequestParam('action') === 'create_new' |
|
64 | + || $this->request->getRequestParam('action') === 'edit' |
|
65 | + ) |
|
66 | + ) |
|
67 | + || ( |
|
68 | + $pagenow |
|
69 | + && ( |
|
70 | + $pagenow === 'post-new.php' |
|
71 | + || ( |
|
72 | + $pagenow === 'post.php' |
|
73 | + && $this->request->getRequestParam('action') === 'edit' |
|
74 | + ) |
|
75 | + ) |
|
76 | + ) |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * @since $VID:$ |
|
83 | - */ |
|
84 | - protected function registerDependencies() |
|
85 | - { |
|
86 | - $this->dependency_map->registerDependencies( |
|
87 | - 'EventEspresso\core\services\graphql\GraphQLManager', |
|
88 | - [ |
|
89 | - 'EventEspresso\core\services\graphql\ConnectionsManager' => EE_Dependency_Map::load_from_cache, |
|
90 | - 'EventEspresso\core\services\graphql\DataLoaderManager' => EE_Dependency_Map::load_from_cache, |
|
91 | - 'EventEspresso\core\services\graphql\EnumsManager' => EE_Dependency_Map::load_from_cache, |
|
92 | - 'EventEspresso\core\services\graphql\InputsManager' => EE_Dependency_Map::load_from_cache, |
|
93 | - 'EventEspresso\core\services\graphql\TypesManager' => EE_Dependency_Map::load_from_cache, |
|
94 | - ] |
|
95 | - ); |
|
96 | - $this->dependency_map->registerDependencies( |
|
97 | - 'EventEspresso\core\services\graphql\TypesManager', |
|
98 | - [ |
|
99 | - 'EventEspresso\core\services\graphql\types\TypeCollection' => EE_Dependency_Map::load_from_cache, |
|
100 | - ] |
|
101 | - ); |
|
102 | - $this->dependency_map->registerDependencies( |
|
103 | - 'EventEspresso\core\services\graphql\InputsManager', |
|
104 | - [ |
|
105 | - 'EventEspresso\core\services\graphql\inputs\InputCollection' => EE_Dependency_Map::load_from_cache, |
|
106 | - ] |
|
107 | - ); |
|
108 | - $this->dependency_map->registerDependencies( |
|
109 | - 'EventEspresso\core\services\graphql\EnumsManager', |
|
110 | - [ |
|
111 | - 'EventEspresso\core\services\graphql\enums\EnumCollection' => EE_Dependency_Map::load_from_cache, |
|
112 | - ] |
|
113 | - ); |
|
114 | - $this->dependency_map->registerDependencies( |
|
115 | - 'EventEspresso\core\services\graphql\ConnectionsManager', |
|
116 | - [ |
|
117 | - 'EventEspresso\core\services\graphql\connections\ConnectionCollection' => EE_Dependency_Map::load_from_cache, |
|
118 | - ] |
|
119 | - ); |
|
120 | - $this->dependency_map->registerDependencies( |
|
121 | - 'EventEspresso\core\services\graphql\DataLoaderManager', |
|
122 | - [ |
|
123 | - 'EventEspresso\core\services\graphql\loaders\DataLoaderCollection' => EE_Dependency_Map::load_from_cache, |
|
124 | - ] |
|
125 | - ); |
|
126 | - $this->dependency_map->registerDependencies( |
|
127 | - 'EventEspresso\core\domain\services\graphql\types\Datetime', |
|
128 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
129 | - ); |
|
130 | - $this->dependency_map->registerDependencies( |
|
131 | - 'EventEspresso\core\domain\services\graphql\types\Attendee', |
|
132 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
133 | - ); |
|
134 | - $this->dependency_map->registerDependencies( |
|
135 | - 'EventEspresso\core\domain\services\graphql\types\Event', |
|
136 | - ['EEM_Event' => EE_Dependency_Map::load_from_cache] |
|
137 | - ); |
|
138 | - $this->dependency_map->registerDependencies( |
|
139 | - 'EventEspresso\core\domain\services\graphql\types\FormElement', |
|
140 | - ['EEM_Form_Element' => EE_Dependency_Map::load_from_cache] |
|
141 | - ); |
|
142 | - $this->dependency_map->registerDependencies( |
|
143 | - 'EventEspresso\core\domain\services\graphql\types\FormSection', |
|
144 | - ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
145 | - ); |
|
146 | - $this->dependency_map->registerDependencies( |
|
147 | - 'EventEspresso\core\domain\services\graphql\types\Ticket', |
|
148 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
149 | - ); |
|
150 | - $this->dependency_map->registerDependencies( |
|
151 | - 'EventEspresso\core\domain\services\graphql\types\Price', |
|
152 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
153 | - ); |
|
154 | - $this->dependency_map->registerDependencies( |
|
155 | - 'EventEspresso\core\domain\services\graphql\types\PriceType', |
|
156 | - ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
157 | - ); |
|
158 | - $this->dependency_map->registerDependencies( |
|
159 | - 'EventEspresso\core\domain\services\graphql\types\Venue', |
|
160 | - ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
161 | - ); |
|
162 | - $this->dependency_map->registerDependencies( |
|
163 | - 'EventEspresso\core\domain\services\graphql\types\State', |
|
164 | - ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
165 | - ); |
|
166 | - $this->dependency_map->registerDependencies( |
|
167 | - 'EventEspresso\core\domain\services\graphql\types\Country', |
|
168 | - ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
169 | - ); |
|
170 | - $this->dependency_map->registerDependencies( |
|
171 | - 'EventEspresso\core\domain\services\graphql\connections\EventDatetimesConnection', |
|
172 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
173 | - ); |
|
174 | - $this->dependency_map->registerDependencies( |
|
175 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryDatetimesConnection', |
|
176 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
177 | - ); |
|
178 | - $this->dependency_map->registerDependencies( |
|
179 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryAttendeesConnection', |
|
180 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
181 | - ); |
|
182 | - $this->dependency_map->registerDependencies( |
|
183 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormElementsConnection', |
|
184 | - ['EEM_Form_Element' => EE_Dependency_Map::load_from_cache] |
|
185 | - ); |
|
186 | - $this->dependency_map->registerDependencies( |
|
187 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormSectionsConnection', |
|
188 | - ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
189 | - ); |
|
190 | - $this->dependency_map->registerDependencies( |
|
191 | - 'EventEspresso\core\domain\services\graphql\connections\DatetimeTicketsConnection', |
|
192 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
193 | - ); |
|
194 | - $this->dependency_map->registerDependencies( |
|
195 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryTicketsConnection', |
|
196 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
197 | - ); |
|
198 | - $this->dependency_map->registerDependencies( |
|
199 | - 'EventEspresso\core\domain\services\graphql\connections\TicketPricesConnection', |
|
200 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
201 | - ); |
|
202 | - $this->dependency_map->registerDependencies( |
|
203 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryPricesConnection', |
|
204 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
205 | - ); |
|
206 | - $this->dependency_map->registerDependencies( |
|
207 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryPriceTypesConnection', |
|
208 | - ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
209 | - ); |
|
210 | - $this->dependency_map->registerDependencies( |
|
211 | - 'EventEspresso\core\domain\services\graphql\connections\TicketDatetimesConnection', |
|
212 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
213 | - ); |
|
214 | - $this->dependency_map->registerDependencies( |
|
215 | - 'EventEspresso\core\domain\services\graphql\connections\EventVenuesConnection', |
|
216 | - ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
217 | - ); |
|
218 | - } |
|
81 | + /** |
|
82 | + * @since $VID:$ |
|
83 | + */ |
|
84 | + protected function registerDependencies() |
|
85 | + { |
|
86 | + $this->dependency_map->registerDependencies( |
|
87 | + 'EventEspresso\core\services\graphql\GraphQLManager', |
|
88 | + [ |
|
89 | + 'EventEspresso\core\services\graphql\ConnectionsManager' => EE_Dependency_Map::load_from_cache, |
|
90 | + 'EventEspresso\core\services\graphql\DataLoaderManager' => EE_Dependency_Map::load_from_cache, |
|
91 | + 'EventEspresso\core\services\graphql\EnumsManager' => EE_Dependency_Map::load_from_cache, |
|
92 | + 'EventEspresso\core\services\graphql\InputsManager' => EE_Dependency_Map::load_from_cache, |
|
93 | + 'EventEspresso\core\services\graphql\TypesManager' => EE_Dependency_Map::load_from_cache, |
|
94 | + ] |
|
95 | + ); |
|
96 | + $this->dependency_map->registerDependencies( |
|
97 | + 'EventEspresso\core\services\graphql\TypesManager', |
|
98 | + [ |
|
99 | + 'EventEspresso\core\services\graphql\types\TypeCollection' => EE_Dependency_Map::load_from_cache, |
|
100 | + ] |
|
101 | + ); |
|
102 | + $this->dependency_map->registerDependencies( |
|
103 | + 'EventEspresso\core\services\graphql\InputsManager', |
|
104 | + [ |
|
105 | + 'EventEspresso\core\services\graphql\inputs\InputCollection' => EE_Dependency_Map::load_from_cache, |
|
106 | + ] |
|
107 | + ); |
|
108 | + $this->dependency_map->registerDependencies( |
|
109 | + 'EventEspresso\core\services\graphql\EnumsManager', |
|
110 | + [ |
|
111 | + 'EventEspresso\core\services\graphql\enums\EnumCollection' => EE_Dependency_Map::load_from_cache, |
|
112 | + ] |
|
113 | + ); |
|
114 | + $this->dependency_map->registerDependencies( |
|
115 | + 'EventEspresso\core\services\graphql\ConnectionsManager', |
|
116 | + [ |
|
117 | + 'EventEspresso\core\services\graphql\connections\ConnectionCollection' => EE_Dependency_Map::load_from_cache, |
|
118 | + ] |
|
119 | + ); |
|
120 | + $this->dependency_map->registerDependencies( |
|
121 | + 'EventEspresso\core\services\graphql\DataLoaderManager', |
|
122 | + [ |
|
123 | + 'EventEspresso\core\services\graphql\loaders\DataLoaderCollection' => EE_Dependency_Map::load_from_cache, |
|
124 | + ] |
|
125 | + ); |
|
126 | + $this->dependency_map->registerDependencies( |
|
127 | + 'EventEspresso\core\domain\services\graphql\types\Datetime', |
|
128 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
129 | + ); |
|
130 | + $this->dependency_map->registerDependencies( |
|
131 | + 'EventEspresso\core\domain\services\graphql\types\Attendee', |
|
132 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
133 | + ); |
|
134 | + $this->dependency_map->registerDependencies( |
|
135 | + 'EventEspresso\core\domain\services\graphql\types\Event', |
|
136 | + ['EEM_Event' => EE_Dependency_Map::load_from_cache] |
|
137 | + ); |
|
138 | + $this->dependency_map->registerDependencies( |
|
139 | + 'EventEspresso\core\domain\services\graphql\types\FormElement', |
|
140 | + ['EEM_Form_Element' => EE_Dependency_Map::load_from_cache] |
|
141 | + ); |
|
142 | + $this->dependency_map->registerDependencies( |
|
143 | + 'EventEspresso\core\domain\services\graphql\types\FormSection', |
|
144 | + ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
145 | + ); |
|
146 | + $this->dependency_map->registerDependencies( |
|
147 | + 'EventEspresso\core\domain\services\graphql\types\Ticket', |
|
148 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
149 | + ); |
|
150 | + $this->dependency_map->registerDependencies( |
|
151 | + 'EventEspresso\core\domain\services\graphql\types\Price', |
|
152 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
153 | + ); |
|
154 | + $this->dependency_map->registerDependencies( |
|
155 | + 'EventEspresso\core\domain\services\graphql\types\PriceType', |
|
156 | + ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
157 | + ); |
|
158 | + $this->dependency_map->registerDependencies( |
|
159 | + 'EventEspresso\core\domain\services\graphql\types\Venue', |
|
160 | + ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
161 | + ); |
|
162 | + $this->dependency_map->registerDependencies( |
|
163 | + 'EventEspresso\core\domain\services\graphql\types\State', |
|
164 | + ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
165 | + ); |
|
166 | + $this->dependency_map->registerDependencies( |
|
167 | + 'EventEspresso\core\domain\services\graphql\types\Country', |
|
168 | + ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
169 | + ); |
|
170 | + $this->dependency_map->registerDependencies( |
|
171 | + 'EventEspresso\core\domain\services\graphql\connections\EventDatetimesConnection', |
|
172 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
173 | + ); |
|
174 | + $this->dependency_map->registerDependencies( |
|
175 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryDatetimesConnection', |
|
176 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
177 | + ); |
|
178 | + $this->dependency_map->registerDependencies( |
|
179 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryAttendeesConnection', |
|
180 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
181 | + ); |
|
182 | + $this->dependency_map->registerDependencies( |
|
183 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormElementsConnection', |
|
184 | + ['EEM_Form_Element' => EE_Dependency_Map::load_from_cache] |
|
185 | + ); |
|
186 | + $this->dependency_map->registerDependencies( |
|
187 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormSectionsConnection', |
|
188 | + ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
189 | + ); |
|
190 | + $this->dependency_map->registerDependencies( |
|
191 | + 'EventEspresso\core\domain\services\graphql\connections\DatetimeTicketsConnection', |
|
192 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
193 | + ); |
|
194 | + $this->dependency_map->registerDependencies( |
|
195 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryTicketsConnection', |
|
196 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
197 | + ); |
|
198 | + $this->dependency_map->registerDependencies( |
|
199 | + 'EventEspresso\core\domain\services\graphql\connections\TicketPricesConnection', |
|
200 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
201 | + ); |
|
202 | + $this->dependency_map->registerDependencies( |
|
203 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryPricesConnection', |
|
204 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
205 | + ); |
|
206 | + $this->dependency_map->registerDependencies( |
|
207 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryPriceTypesConnection', |
|
208 | + ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
209 | + ); |
|
210 | + $this->dependency_map->registerDependencies( |
|
211 | + 'EventEspresso\core\domain\services\graphql\connections\TicketDatetimesConnection', |
|
212 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
213 | + ); |
|
214 | + $this->dependency_map->registerDependencies( |
|
215 | + 'EventEspresso\core\domain\services\graphql\connections\EventVenuesConnection', |
|
216 | + ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
217 | + ); |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | - /** |
|
222 | - * implements logic required to run during request |
|
223 | - * |
|
224 | - * @return bool |
|
225 | - * @since $VID:$ |
|
226 | - */ |
|
227 | - protected function requestHandler(): bool |
|
228 | - { |
|
229 | - if (! class_exists('WPGraphQL')) { |
|
230 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
231 | - } |
|
232 | - // load handler for EE GraphQL requests |
|
233 | - $graphQL_manager = $this->loader->getShared( |
|
234 | - 'EventEspresso\core\services\graphql\GraphQLManager' |
|
235 | - ); |
|
236 | - $graphQL_manager->init(); |
|
237 | - $manifest = $this->manifest_factory->createFromDomainObject(DomainFactory::getEventEspressoCoreDomain()); |
|
238 | - $manifest->initialize(); |
|
239 | - return true; |
|
240 | - } |
|
221 | + /** |
|
222 | + * implements logic required to run during request |
|
223 | + * |
|
224 | + * @return bool |
|
225 | + * @since $VID:$ |
|
226 | + */ |
|
227 | + protected function requestHandler(): bool |
|
228 | + { |
|
229 | + if (! class_exists('WPGraphQL')) { |
|
230 | + require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
231 | + } |
|
232 | + // load handler for EE GraphQL requests |
|
233 | + $graphQL_manager = $this->loader->getShared( |
|
234 | + 'EventEspresso\core\services\graphql\GraphQLManager' |
|
235 | + ); |
|
236 | + $graphQL_manager->init(); |
|
237 | + $manifest = $this->manifest_factory->createFromDomainObject(DomainFactory::getEventEspressoCoreDomain()); |
|
238 | + $manifest->initialize(); |
|
239 | + return true; |
|
240 | + } |
|
241 | 241 | } |
@@ -13,18 +13,18 @@ |
||
13 | 13 | class Utils |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Given a string, formats it as GraphQL ENUM value |
|
18 | - * |
|
19 | - * @param string $str The string to format |
|
20 | - * |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public static function formatEnumKey($str) |
|
24 | - { |
|
25 | - // Replace any non-alph-anumeric by underscore |
|
26 | - $str = preg_replace('/[^a-zA-Z0-9]/', '_', $str); |
|
27 | - // Convert to uppercase. |
|
28 | - return strtoupper($str); |
|
29 | - } |
|
16 | + /** |
|
17 | + * Given a string, formats it as GraphQL ENUM value |
|
18 | + * |
|
19 | + * @param string $str The string to format |
|
20 | + * |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public static function formatEnumKey($str) |
|
24 | + { |
|
25 | + // Replace any non-alph-anumeric by underscore |
|
26 | + $str = preg_replace('/[^a-zA-Z0-9]/', '_', $str); |
|
27 | + // Convert to uppercase. |
|
28 | + return strtoupper($str); |
|
29 | + } |
|
30 | 30 | } |
@@ -35,270 +35,270 @@ |
||
35 | 35 | abstract class TypeBase implements TypeInterface |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * @var string $namespace The graphql namespace/prefix. |
|
40 | - */ |
|
41 | - protected $namespace = 'Espresso'; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var EEM_Base $model |
|
45 | - */ |
|
46 | - protected $model; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string $name |
|
50 | - */ |
|
51 | - protected $name = ''; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string $description |
|
55 | - */ |
|
56 | - protected $description = ''; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var GraphQLFieldInterface[] $fields |
|
60 | - */ |
|
61 | - protected $fields = []; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var array $graphql_to_model_map |
|
65 | - */ |
|
66 | - protected $graphql_to_model_map = []; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var FieldResolver $field_resolver |
|
70 | - */ |
|
71 | - protected $field_resolver; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var bool $is_custom_post_type |
|
75 | - */ |
|
76 | - protected $is_custom_post_type = false; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * TypeBase constructor. |
|
81 | - * |
|
82 | - * @param EEM_Base|null $model |
|
83 | - */ |
|
84 | - public function __construct(EEM_Base $model = null) |
|
85 | - { |
|
86 | - $this->model = $model; |
|
87 | - $this->setFields($this->getFields()); |
|
88 | - $this->field_resolver = new FieldResolver( |
|
89 | - $this->model, |
|
90 | - $this->getFieldsForResolver() |
|
91 | - ); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @return GraphQLFieldInterface[] |
|
97 | - * @since $VID:$ |
|
98 | - */ |
|
99 | - abstract protected function getFields(): array; |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function name(): string |
|
106 | - { |
|
107 | - return $this->name; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param string $name |
|
113 | - */ |
|
114 | - protected function setName(string $name) |
|
115 | - { |
|
116 | - $this->name = $name; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function description(): string |
|
124 | - { |
|
125 | - return $this->description; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @param string $description |
|
131 | - */ |
|
132 | - protected function setDescription(string $description) |
|
133 | - { |
|
134 | - $this->description = $description; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return GraphQLFieldInterface[] |
|
140 | - * @since $VID:$ |
|
141 | - */ |
|
142 | - public function fields(): array |
|
143 | - { |
|
144 | - return (array) $this->fields; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @param GraphQLFieldInterface[] $fields |
|
150 | - */ |
|
151 | - protected function setFields(array $fields) |
|
152 | - { |
|
153 | - foreach ($fields as $field) { |
|
154 | - if ($field instanceof GraphQLField) { |
|
155 | - $this->fields[] = $field; |
|
156 | - } |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Creates a key map for internal resolver. |
|
163 | - * |
|
164 | - * @return array |
|
165 | - * @since $VID:$ |
|
166 | - */ |
|
167 | - public function getFieldsForResolver(): array |
|
168 | - { |
|
169 | - $fields = []; |
|
170 | - foreach ($this->fields() as $field) { |
|
171 | - if ($field->useForOutput()) { |
|
172 | - $fields[ $field->name() ] = $field; |
|
173 | - } |
|
174 | - } |
|
175 | - return $fields; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @return bool |
|
181 | - */ |
|
182 | - public function isCustomPostType(): bool |
|
183 | - { |
|
184 | - return $this->is_custom_post_type; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * @param bool $is_custom_post_type |
|
190 | - */ |
|
191 | - protected function setIsCustomPostType(bool $is_custom_post_type) |
|
192 | - { |
|
193 | - $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param int|float $value |
|
199 | - * @return int |
|
200 | - * @since $VID:$ |
|
201 | - */ |
|
202 | - public function parseInfiniteValue($value): int |
|
203 | - { |
|
204 | - $value = trim($value); |
|
205 | - return $value === null |
|
206 | - || $value === '' |
|
207 | - || $value === '∞' |
|
208 | - || $value === 'INF' |
|
209 | - || $value === INF |
|
210 | - || $value === EE_INF |
|
211 | - || is_infinite((float) $value) |
|
212 | - ? -1 |
|
213 | - : $value; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * @param mixed $source |
|
219 | - * @return EE_Base_Class|null |
|
220 | - * @throws EE_Error |
|
221 | - */ |
|
222 | - private function getModel($source): ?EE_Base_Class |
|
223 | - { |
|
224 | - // If it comes from a custom connection |
|
225 | - // where the $source is already instantiated. |
|
226 | - if ($source instanceof EE_Base_Class) { |
|
227 | - return $source; |
|
228 | - } |
|
229 | - return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
235 | - * @param array $args The inputArgs on the field |
|
236 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
237 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
238 | - * @return EE_Base_Class|Deferred|string|null |
|
239 | - * @throws EE_Error |
|
240 | - * @throws InvalidDataTypeException |
|
241 | - * @throws InvalidInterfaceException |
|
242 | - * @throws UnexpectedEntityException |
|
243 | - * @throws UserError |
|
244 | - * @throws InvalidArgumentException |
|
245 | - * @throws ReflectionException |
|
246 | - * @since $VID:$ |
|
247 | - */ |
|
248 | - public function resolveField($source, array $args, AppContext $context, ResolveInfo $info) |
|
249 | - { |
|
250 | - $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
251 | - |
|
252 | - return $this->field_resolver->resolve($source, $args, $context, $info); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @param mixed $payload The payload returned after mutation |
|
258 | - * @param array $args The inputArgs on the field |
|
259 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
260 | - * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null |
|
261 | - * @throws EE_Error |
|
262 | - */ |
|
263 | - public function resolveFromPayload($payload, array $args, AppContext $context) |
|
264 | - { |
|
265 | - if (empty($payload['id'])) { |
|
266 | - return null; |
|
267 | - } |
|
268 | - return $this->model->get_one_by_ID($payload['id']); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Prepares a datetime value in ISO8601/RFC3339 format. |
|
274 | - * It is assumed that the value of $datetime is in the format |
|
275 | - * returned by EE_Base_Class::get_format(). |
|
276 | - * |
|
277 | - * @param string $datetime The datetime value. |
|
278 | - * @param EE_Base_Class $source The source object. |
|
279 | - * @return string ISO8601/RFC3339 formatted datetime. |
|
280 | - */ |
|
281 | - public function formatDatetime(string $datetime, EE_Base_Class $source): string |
|
282 | - { |
|
283 | - $format = $source->get_format(); |
|
284 | - // create date object based on local timezone |
|
285 | - $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
286 | - // change the timezone to UTC |
|
287 | - $datetime->setTimezone(new DateTimeZone('UTC')); |
|
288 | - |
|
289 | - return $datetime->format(DateTime::RFC3339); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Converts an object to JSON. The object must have a "toJson" method. |
|
295 | - * |
|
296 | - * @param string $object The object/value. |
|
297 | - * @param EE_Base_Class $source The source object. |
|
298 | - * @return string JSON representation of the object. |
|
299 | - */ |
|
300 | - public function toJson(JsonableInterface $object, EE_Base_Class $source): string |
|
301 | - { |
|
302 | - return $object->toJson(); |
|
303 | - } |
|
38 | + /** |
|
39 | + * @var string $namespace The graphql namespace/prefix. |
|
40 | + */ |
|
41 | + protected $namespace = 'Espresso'; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var EEM_Base $model |
|
45 | + */ |
|
46 | + protected $model; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string $name |
|
50 | + */ |
|
51 | + protected $name = ''; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string $description |
|
55 | + */ |
|
56 | + protected $description = ''; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var GraphQLFieldInterface[] $fields |
|
60 | + */ |
|
61 | + protected $fields = []; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var array $graphql_to_model_map |
|
65 | + */ |
|
66 | + protected $graphql_to_model_map = []; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var FieldResolver $field_resolver |
|
70 | + */ |
|
71 | + protected $field_resolver; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var bool $is_custom_post_type |
|
75 | + */ |
|
76 | + protected $is_custom_post_type = false; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * TypeBase constructor. |
|
81 | + * |
|
82 | + * @param EEM_Base|null $model |
|
83 | + */ |
|
84 | + public function __construct(EEM_Base $model = null) |
|
85 | + { |
|
86 | + $this->model = $model; |
|
87 | + $this->setFields($this->getFields()); |
|
88 | + $this->field_resolver = new FieldResolver( |
|
89 | + $this->model, |
|
90 | + $this->getFieldsForResolver() |
|
91 | + ); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @return GraphQLFieldInterface[] |
|
97 | + * @since $VID:$ |
|
98 | + */ |
|
99 | + abstract protected function getFields(): array; |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function name(): string |
|
106 | + { |
|
107 | + return $this->name; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param string $name |
|
113 | + */ |
|
114 | + protected function setName(string $name) |
|
115 | + { |
|
116 | + $this->name = $name; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function description(): string |
|
124 | + { |
|
125 | + return $this->description; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @param string $description |
|
131 | + */ |
|
132 | + protected function setDescription(string $description) |
|
133 | + { |
|
134 | + $this->description = $description; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return GraphQLFieldInterface[] |
|
140 | + * @since $VID:$ |
|
141 | + */ |
|
142 | + public function fields(): array |
|
143 | + { |
|
144 | + return (array) $this->fields; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param GraphQLFieldInterface[] $fields |
|
150 | + */ |
|
151 | + protected function setFields(array $fields) |
|
152 | + { |
|
153 | + foreach ($fields as $field) { |
|
154 | + if ($field instanceof GraphQLField) { |
|
155 | + $this->fields[] = $field; |
|
156 | + } |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Creates a key map for internal resolver. |
|
163 | + * |
|
164 | + * @return array |
|
165 | + * @since $VID:$ |
|
166 | + */ |
|
167 | + public function getFieldsForResolver(): array |
|
168 | + { |
|
169 | + $fields = []; |
|
170 | + foreach ($this->fields() as $field) { |
|
171 | + if ($field->useForOutput()) { |
|
172 | + $fields[ $field->name() ] = $field; |
|
173 | + } |
|
174 | + } |
|
175 | + return $fields; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @return bool |
|
181 | + */ |
|
182 | + public function isCustomPostType(): bool |
|
183 | + { |
|
184 | + return $this->is_custom_post_type; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * @param bool $is_custom_post_type |
|
190 | + */ |
|
191 | + protected function setIsCustomPostType(bool $is_custom_post_type) |
|
192 | + { |
|
193 | + $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param int|float $value |
|
199 | + * @return int |
|
200 | + * @since $VID:$ |
|
201 | + */ |
|
202 | + public function parseInfiniteValue($value): int |
|
203 | + { |
|
204 | + $value = trim($value); |
|
205 | + return $value === null |
|
206 | + || $value === '' |
|
207 | + || $value === '∞' |
|
208 | + || $value === 'INF' |
|
209 | + || $value === INF |
|
210 | + || $value === EE_INF |
|
211 | + || is_infinite((float) $value) |
|
212 | + ? -1 |
|
213 | + : $value; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * @param mixed $source |
|
219 | + * @return EE_Base_Class|null |
|
220 | + * @throws EE_Error |
|
221 | + */ |
|
222 | + private function getModel($source): ?EE_Base_Class |
|
223 | + { |
|
224 | + // If it comes from a custom connection |
|
225 | + // where the $source is already instantiated. |
|
226 | + if ($source instanceof EE_Base_Class) { |
|
227 | + return $source; |
|
228 | + } |
|
229 | + return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
235 | + * @param array $args The inputArgs on the field |
|
236 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
237 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
238 | + * @return EE_Base_Class|Deferred|string|null |
|
239 | + * @throws EE_Error |
|
240 | + * @throws InvalidDataTypeException |
|
241 | + * @throws InvalidInterfaceException |
|
242 | + * @throws UnexpectedEntityException |
|
243 | + * @throws UserError |
|
244 | + * @throws InvalidArgumentException |
|
245 | + * @throws ReflectionException |
|
246 | + * @since $VID:$ |
|
247 | + */ |
|
248 | + public function resolveField($source, array $args, AppContext $context, ResolveInfo $info) |
|
249 | + { |
|
250 | + $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
251 | + |
|
252 | + return $this->field_resolver->resolve($source, $args, $context, $info); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @param mixed $payload The payload returned after mutation |
|
258 | + * @param array $args The inputArgs on the field |
|
259 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
260 | + * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null |
|
261 | + * @throws EE_Error |
|
262 | + */ |
|
263 | + public function resolveFromPayload($payload, array $args, AppContext $context) |
|
264 | + { |
|
265 | + if (empty($payload['id'])) { |
|
266 | + return null; |
|
267 | + } |
|
268 | + return $this->model->get_one_by_ID($payload['id']); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Prepares a datetime value in ISO8601/RFC3339 format. |
|
274 | + * It is assumed that the value of $datetime is in the format |
|
275 | + * returned by EE_Base_Class::get_format(). |
|
276 | + * |
|
277 | + * @param string $datetime The datetime value. |
|
278 | + * @param EE_Base_Class $source The source object. |
|
279 | + * @return string ISO8601/RFC3339 formatted datetime. |
|
280 | + */ |
|
281 | + public function formatDatetime(string $datetime, EE_Base_Class $source): string |
|
282 | + { |
|
283 | + $format = $source->get_format(); |
|
284 | + // create date object based on local timezone |
|
285 | + $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
286 | + // change the timezone to UTC |
|
287 | + $datetime->setTimezone(new DateTimeZone('UTC')); |
|
288 | + |
|
289 | + return $datetime->format(DateTime::RFC3339); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Converts an object to JSON. The object must have a "toJson" method. |
|
295 | + * |
|
296 | + * @param string $object The object/value. |
|
297 | + * @param EE_Base_Class $source The source object. |
|
298 | + * @return string JSON representation of the object. |
|
299 | + */ |
|
300 | + public function toJson(JsonableInterface $object, EE_Base_Class $source): string |
|
301 | + { |
|
302 | + return $object->toJson(); |
|
303 | + } |
|
304 | 304 | } |