Skip to content

Commit 74bb15f

Browse files
committed
"Actions" and "Filters" classes renamed and refactored.
1 parent 6406e41 commit 74bb15f

File tree

6 files changed

+110
-97
lines changed

6 files changed

+110
-97
lines changed

includes/class-filters.php renamed to includes/class-core-schema-filters.php

Lines changed: 5 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
/**
3-
* Filters
4-
*
5-
* Filter callbacks for executing filters on the GraphQL Schema
3+
* Adds filters that modify core schema.
64
*
75
* @package \WPGraphQL\Extensions\WooCommerce
86
* @since 0.0.1
@@ -15,12 +13,11 @@
1513
use WPGraphQL\Extensions\WooCommerce\Data\Factory;
1614
use WPGraphQL\Extensions\WooCommerce\Data\Loader\WC_Customer_Loader;
1715
use WPGraphQL\Extensions\WooCommerce\Data\Loader\WC_Post_Crud_Loader;
18-
use WPGraphQL\Extensions\WooCommerce\Utils\QL_Session_Handler;
1916

2017
/**
21-
* Class Filters
18+
* Class Core_Schema_Filters
2219
*/
23-
class Filters {
20+
class Core_Schema_Filters {
2421
/**
2522
* Stores instance WC_Customer_Loader
2623
*
@@ -35,24 +32,17 @@ class Filters {
3532
*/
3633
private static $post_crud_loader;
3734

38-
/**
39-
* Stores instance session header name.
40-
*
41-
* @var string
42-
*/
43-
private static $session_header;
44-
4535
/**
4636
* Register filters
4737
*/
48-
public static function load() {
38+
public static function add_filters() {
4939
// Registers WooCommerce taxonomies.
5040
add_filter( 'register_taxonomy_args', array( __CLASS__, 'register_taxonomy_args' ), 10, 2 );
5141

5242
// Add data-loaders to AppContext.
5343
add_filter( 'graphql_data_loaders', array( __CLASS__, 'graphql_data_loaders' ), 10, 2 );
5444

55-
// Filter core connection resolutions.
45+
// Adds connection resolutions for WooGraphQL type to WPGraphQL type connections.
5646
add_filter(
5747
'graphql_post_object_connection_query_args',
5848
array( __CLASS__, 'graphql_post_object_connection_query_args' ),
@@ -65,15 +55,6 @@ public static function load() {
6555
10,
6656
5
6757
);
68-
69-
// Setup QL session handler.
70-
if ( ! defined( 'NO_QL_SESSION_HANDLER' ) ) {
71-
self::$session_header = apply_filters( 'woocommerce_session_header_name', 'woocommerce-session' );
72-
add_filter( 'woocommerce_cookie', array( __CLASS__, 'woocommerce_cookie' ) );
73-
add_filter( 'woocommerce_session_handler', array( __CLASS__, 'init_ql_session_handler' ) );
74-
add_filter( 'graphql_response_headers_to_send', array( __CLASS__, 'add_session_header_to_expose_headers' ) );
75-
add_filter( 'graphql_access_control_allow_headers', array( __CLASS__, 'add_session_header_to_allow_headers' ) );
76-
}
7758
}
7859

7960
/**
@@ -204,55 +185,4 @@ public static function graphql_post_object_connection_query_args( $query_args, $
204185
public static function graphql_term_object_connection_query_args( $query_args, $source, $args, $context, $info ) {
205186
return WC_Terms_Connection_Resolver::get_query_args( $query_args, $source, $args, $context, $info );
206187
}
207-
208-
/**
209-
* Filters WooCommerce cookie key to be used as a HTTP Header on GraphQL HTTP requests
210-
*
211-
* @param string $cookie WooCommerce cookie key.
212-
*
213-
* @return string
214-
*/
215-
public static function woocommerce_cookie( $cookie ) {
216-
return self::$session_header;
217-
}
218-
219-
/**
220-
* Filters WooCommerce session handler class on GraphQL HTTP requests
221-
*
222-
* @param string $session_class Classname of the current session handler class.
223-
*
224-
* @return string
225-
*/
226-
public static function init_ql_session_handler( $session_class ) {
227-
return QL_Session_Handler::class;
228-
}
229-
230-
/**
231-
* Append session header to the exposed headers in GraphQL responses
232-
*
233-
* @param array $headers GraphQL responser headers.
234-
*
235-
* @return array
236-
*/
237-
public static function add_session_header_to_expose_headers( $headers ) {
238-
if ( empty( $headers['Access-Control-Expose-Headers'] ) ) {
239-
$headers['Access-Control-Expose-Headers'] = apply_filters( 'woocommerce_cookie', self::$session_header );
240-
} else {
241-
$headers['Access-Control-Expose-Headers'] .= ', ' . apply_filters( 'woocommerce_cookie', self::$session_header );
242-
}
243-
244-
return $headers;
245-
}
246-
247-
/**
248-
* Append the session header to the allowed headers in GraphQL responses
249-
*
250-
* @param array $allowed_headers The existing allowed headers.
251-
*
252-
* @return array
253-
*/
254-
public static function add_session_header_to_allow_headers( array $allowed_headers ) {
255-
$allowed_headers[] = self::$session_header;
256-
return $allowed_headers;
257-
}
258188
}

includes/class-actions.php renamed to includes/class-type-registry.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
/**
3-
* Actions
4-
*
5-
* Action callbacks for executing actions on the GraphQL Schema
3+
* Registers WooGraphQL types to the schema.
64
*
75
* @package \WPGraphQL\Extensions\WooCommerce
86
* @since 0.0.1
@@ -82,25 +80,19 @@
8280
use WPGraphQL\Extensions\WooCommerce\Mutation\Checkout;
8381

8482
/**
85-
* Class Actions
83+
* Class Type_Registry
8684
*/
87-
class Actions {
85+
class Type_Registry {
8886
/**
89-
* Loads plugin actions
87+
* Registers actions related to type registry.
9088
*/
91-
public static function load() {
92-
add_action(
93-
'graphql_register_types',
94-
array(
95-
'\WPGraphQL\Extensions\WooCommerce\Actions',
96-
'graphql_register_types',
97-
),
98-
10
99-
);
89+
public static function add_actions() {
90+
// Register types.
91+
add_action( 'graphql_register_types', array( __CLASS__, 'graphql_register_types' ), 10 );
10092
}
10193

10294
/**
103-
* Registers WooCommerce types and type_fields to GraphQL schema
95+
* Registers WooGraphQL types, connection, and mutations to GraphQL schema
10496
*/
10597
public static function graphql_register_types() {
10698
// Enumerations.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Adds filters that modify woocommerce functionality on GraphQL requests.
4+
*
5+
* @package \WPGraphQL\Extensions\WooCommerce
6+
* @since 0.2.0
7+
*/
8+
9+
namespace WPGraphQL\Extensions\WooCommerce;
10+
11+
use WPGraphQL\Extensions\WooCommerce\Utils\QL_Session_Handler;
12+
13+
/**
14+
* Class WooCommerce_Filters
15+
*/
16+
class WooCommerce_Filters {
17+
/**
18+
* Stores instance session header name.
19+
*
20+
* @var string
21+
*/
22+
private static $session_header;
23+
24+
/**
25+
* Register filters
26+
*/
27+
public static function add_filters() {
28+
// Setup QL session handler.
29+
if ( ! defined( 'NO_QL_SESSION_HANDLER' ) ) {
30+
self::$session_header = apply_filters( 'woocommerce_graphql_session_header_name', 'woocommerce-session' );
31+
add_filter( 'woocommerce_graphql_cookie', array( __CLASS__, 'woocommerce_cookie' ) );
32+
add_filter( 'woocommerce_graphql_session_handler', array( __CLASS__, 'init_ql_session_handler' ) );
33+
add_filter( 'graphql_response_headers_to_send', array( __CLASS__, 'add_session_header_to_expose_headers' ) );
34+
add_filter( 'graphql_access_control_allow_headers', array( __CLASS__, 'add_session_header_to_allow_headers' ) );
35+
}
36+
}
37+
38+
/**
39+
* Filters WooCommerce cookie key to be used as a HTTP Header on GraphQL HTTP requests
40+
*
41+
* @param string $cookie WooCommerce cookie key.
42+
*
43+
* @return string
44+
*/
45+
public static function woocommerce_cookie( $cookie ) {
46+
return self::$session_header;
47+
}
48+
49+
/**
50+
* Filters WooCommerce session handler class on GraphQL HTTP requests
51+
*
52+
* @param string $session_class Classname of the current session handler class.
53+
*
54+
* @return string
55+
*/
56+
public static function init_ql_session_handler( $session_class ) {
57+
return QL_Session_Handler::class;
58+
}
59+
60+
/**
61+
* Append session header to the exposed headers in GraphQL responses
62+
*
63+
* @param array $headers GraphQL responser headers.
64+
*
65+
* @return array
66+
*/
67+
public static function add_session_header_to_expose_headers( $headers ) {
68+
if ( empty( $headers['Access-Control-Expose-Headers'] ) ) {
69+
$headers['Access-Control-Expose-Headers'] = apply_filters( 'woocommerce_cookie', self::$session_header );
70+
} else {
71+
$headers['Access-Control-Expose-Headers'] .= ', ' . apply_filters( 'woocommerce_cookie', self::$session_header );
72+
}
73+
74+
return $headers;
75+
}
76+
77+
/**
78+
* Append the session header to the allowed headers in GraphQL responses
79+
*
80+
* @param array $allowed_headers The existing allowed headers.
81+
*
82+
* @return array
83+
*/
84+
public static function add_session_header_to_allow_headers( array $allowed_headers ) {
85+
$allowed_headers[] = self::$session_header;
86+
return $allowed_headers;
87+
}
88+
}

includes/class-wp-graphql-woocommerce.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function actions() {
147147
/**
148148
* Setup actions
149149
*/
150-
\WPGraphQL\Extensions\WooCommerce\Actions::load();
150+
\WPGraphQL\Extensions\WooCommerce\Type_Registry::add_actions();
151151
}
152152

153153
/**
@@ -157,7 +157,8 @@ private function filters() {
157157
/**
158158
* Setup filters
159159
*/
160-
\WPGraphQL\Extensions\WooCommerce\Filters::load();
160+
\WPGraphQL\Extensions\WooCommerce\Core_Schema_Filters::add_filters();
161+
\WPGraphQL\Extensions\WooCommerce\WooCommerce_Filters::add_filters();
161162
}
162163
}
163164
endif;

vendor/composer/autoload_classmap.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
$baseDir = dirname($vendorDir);
77

88
return array(
9-
'WPGraphQL\\Extensions\\WooCommerce\\Actions' => $baseDir . '/includes/class-actions.php',
109
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Cart_Items' => $baseDir . '/includes/connection/class-cart-items.php',
1110
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Coupons' => $baseDir . '/includes/connection/class-coupons.php',
1211
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Customers' => $baseDir . '/includes/connection/class-customers.php',
@@ -21,6 +20,7 @@
2120
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Variation_Attributes' => $baseDir . '/includes/connection/class-variation-attributes.php',
2221
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\WC_Connection' => $baseDir . '/includes/connection/class-wc-connection.php',
2322
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\WC_Terms' => $baseDir . '/includes/connection/class-wc-terms.php',
23+
'WPGraphQL\\Extensions\\WooCommerce\\Core_Schema_Filters' => $baseDir . '/includes/class-core-schema-filters.php',
2424
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Connection\\Cart_Item_Connection_Resolver' => $baseDir . '/includes/data/connection/class-cart-item-connection-resolver.php',
2525
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Connection\\Coupon_Connection_Resolver' => $baseDir . '/includes/data/connection/class-coupon-connection-resolver.php',
2626
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Connection\\Customer_Connection_Resolver' => $baseDir . '/includes/data/connection/class-customer-connection-resolver.php',
@@ -42,7 +42,6 @@
4242
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Mutation\\Checkout_Mutation' => $baseDir . '/includes/data/mutation/class-checkout-mutation.php',
4343
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Mutation\\Customer_Mutation' => $baseDir . '/includes/data/mutation/class-customer-mutation.php',
4444
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Mutation\\Order_Mutation' => $baseDir . '/includes/data/mutation/class-order-mutation.php',
45-
'WPGraphQL\\Extensions\\WooCommerce\\Filters' => $baseDir . '/includes/class-filters.php',
4645
'WPGraphQL\\Extensions\\WooCommerce\\Model\\Coupon' => $baseDir . '/includes/model/class-coupon.php',
4746
'WPGraphQL\\Extensions\\WooCommerce\\Model\\Crud_CPT' => $baseDir . '/includes/model/class-crud-cpt.php',
4847
'WPGraphQL\\Extensions\\WooCommerce\\Model\\Customer' => $baseDir . '/includes/model/class-customer.php',
@@ -108,6 +107,8 @@
108107
'WPGraphQL\\Extensions\\WooCommerce\\Type\\WPObject\\Shipping_Method_Type' => $baseDir . '/includes/type/object/class-shipping-method-type.php',
109108
'WPGraphQL\\Extensions\\WooCommerce\\Type\\WPObject\\Tax_Rate_Type' => $baseDir . '/includes/type/object/class-tax-rate-type.php',
110109
'WPGraphQL\\Extensions\\WooCommerce\\Type\\WPObject\\Variation_Attribute_Type' => $baseDir . '/includes/type/object/class-variation-attribute-type.php',
110+
'WPGraphQL\\Extensions\\WooCommerce\\Type_Registry' => $baseDir . '/includes/class-type-registry.php',
111111
'WPGraphQL\\Extensions\\WooCommerce\\Utils\\QL_Session_Handler' => $baseDir . '/includes/utils/class-ql-session-handler.php',
112+
'WPGraphQL\\Extensions\\WooCommerce\\WooCommerce_Filters' => $baseDir . '/includes/class-woocommerce-filters.php',
112113
'WP_GraphQL_WooCommerce' => $baseDir . '/includes/class-wp-graphql-woocommerce.php',
113114
);

vendor/composer/autoload_static.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class ComposerStaticInitee0d17af17b841ed3a93c4a0e5cc5e5f
2121
);
2222

2323
public static $classMap = array (
24-
'WPGraphQL\\Extensions\\WooCommerce\\Actions' => __DIR__ . '/../..' . '/includes/class-actions.php',
2524
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Cart_Items' => __DIR__ . '/../..' . '/includes/connection/class-cart-items.php',
2625
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Coupons' => __DIR__ . '/../..' . '/includes/connection/class-coupons.php',
2726
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Customers' => __DIR__ . '/../..' . '/includes/connection/class-customers.php',
@@ -36,6 +35,7 @@ class ComposerStaticInitee0d17af17b841ed3a93c4a0e5cc5e5f
3635
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Variation_Attributes' => __DIR__ . '/../..' . '/includes/connection/class-variation-attributes.php',
3736
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\WC_Connection' => __DIR__ . '/../..' . '/includes/connection/class-wc-connection.php',
3837
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\WC_Terms' => __DIR__ . '/../..' . '/includes/connection/class-wc-terms.php',
38+
'WPGraphQL\\Extensions\\WooCommerce\\Core_Schema_Filters' => __DIR__ . '/../..' . '/includes/class-core-schema-filters.php',
3939
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Connection\\Cart_Item_Connection_Resolver' => __DIR__ . '/../..' . '/includes/data/connection/class-cart-item-connection-resolver.php',
4040
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Connection\\Coupon_Connection_Resolver' => __DIR__ . '/../..' . '/includes/data/connection/class-coupon-connection-resolver.php',
4141
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Connection\\Customer_Connection_Resolver' => __DIR__ . '/../..' . '/includes/data/connection/class-customer-connection-resolver.php',
@@ -57,7 +57,6 @@ class ComposerStaticInitee0d17af17b841ed3a93c4a0e5cc5e5f
5757
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Mutation\\Checkout_Mutation' => __DIR__ . '/../..' . '/includes/data/mutation/class-checkout-mutation.php',
5858
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Mutation\\Customer_Mutation' => __DIR__ . '/../..' . '/includes/data/mutation/class-customer-mutation.php',
5959
'WPGraphQL\\Extensions\\WooCommerce\\Data\\Mutation\\Order_Mutation' => __DIR__ . '/../..' . '/includes/data/mutation/class-order-mutation.php',
60-
'WPGraphQL\\Extensions\\WooCommerce\\Filters' => __DIR__ . '/../..' . '/includes/class-filters.php',
6160
'WPGraphQL\\Extensions\\WooCommerce\\Model\\Coupon' => __DIR__ . '/../..' . '/includes/model/class-coupon.php',
6261
'WPGraphQL\\Extensions\\WooCommerce\\Model\\Crud_CPT' => __DIR__ . '/../..' . '/includes/model/class-crud-cpt.php',
6362
'WPGraphQL\\Extensions\\WooCommerce\\Model\\Customer' => __DIR__ . '/../..' . '/includes/model/class-customer.php',
@@ -123,7 +122,9 @@ class ComposerStaticInitee0d17af17b841ed3a93c4a0e5cc5e5f
123122
'WPGraphQL\\Extensions\\WooCommerce\\Type\\WPObject\\Shipping_Method_Type' => __DIR__ . '/../..' . '/includes/type/object/class-shipping-method-type.php',
124123
'WPGraphQL\\Extensions\\WooCommerce\\Type\\WPObject\\Tax_Rate_Type' => __DIR__ . '/../..' . '/includes/type/object/class-tax-rate-type.php',
125124
'WPGraphQL\\Extensions\\WooCommerce\\Type\\WPObject\\Variation_Attribute_Type' => __DIR__ . '/../..' . '/includes/type/object/class-variation-attribute-type.php',
125+
'WPGraphQL\\Extensions\\WooCommerce\\Type_Registry' => __DIR__ . '/../..' . '/includes/class-type-registry.php',
126126
'WPGraphQL\\Extensions\\WooCommerce\\Utils\\QL_Session_Handler' => __DIR__ . '/../..' . '/includes/utils/class-ql-session-handler.php',
127+
'WPGraphQL\\Extensions\\WooCommerce\\WooCommerce_Filters' => __DIR__ . '/../..' . '/includes/class-woocommerce-filters.php',
127128
'WP_GraphQL_WooCommerce' => __DIR__ . '/../..' . '/includes/class-wp-graphql-woocommerce.php',
128129
);
129130

0 commit comments

Comments
 (0)