Skip to content

Commit

Permalink
Merge pull request #107 from kidunot89/release-v0.2.0-cleanup
Browse files Browse the repository at this point in the history
Release v0.2.0 code cleanup
  • Loading branch information
kidunot89 committed Jul 11, 2019
2 parents 6406e41 + 158e7ff commit ead3970
Show file tree
Hide file tree
Showing 33 changed files with 223 additions and 308 deletions.
185 changes: 0 additions & 185 deletions includes/class-actions.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
/**
* Filters
*
* Filter callbacks for executing filters on the GraphQL Schema
* Adds filters that modify core schema.
*
* @package \WPGraphQL\Extensions\WooCommerce
* @since 0.0.1
Expand All @@ -12,15 +10,13 @@

use WPGraphQL\Extensions\WooCommerce\Data\Connection\Post_Connection_Resolver;
use WPGraphQL\Extensions\WooCommerce\Data\Connection\WC_Terms_Connection_Resolver;
use WPGraphQL\Extensions\WooCommerce\Data\Factory;
use WPGraphQL\Extensions\WooCommerce\Data\Loader\WC_Customer_Loader;
use WPGraphQL\Extensions\WooCommerce\Data\Loader\WC_Post_Crud_Loader;
use WPGraphQL\Extensions\WooCommerce\Utils\QL_Session_Handler;

/**
* Class Filters
* Class Core_Schema_Filters
*/
class Filters {
class Core_Schema_Filters {
/**
* Stores instance WC_Customer_Loader
*
Expand All @@ -35,24 +31,17 @@ class Filters {
*/
private static $post_crud_loader;

/**
* Stores instance session header name.
*
* @var string
*/
private static $session_header;

/**
* Register filters
*/
public static function load() {
public static function add_filters() {
// Registers WooCommerce taxonomies.
add_filter( 'register_taxonomy_args', array( __CLASS__, 'register_taxonomy_args' ), 10, 2 );

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

// Filter core connection resolutions.
// Adds connection resolutions for WooGraphQL type to WPGraphQL type connections.
add_filter(
'graphql_post_object_connection_query_args',
array( __CLASS__, 'graphql_post_object_connection_query_args' ),
Expand All @@ -65,15 +54,6 @@ public static function load() {
10,
5
);

// Setup QL session handler.
if ( ! defined( 'NO_QL_SESSION_HANDLER' ) ) {
self::$session_header = apply_filters( 'woocommerce_session_header_name', 'woocommerce-session' );
add_filter( 'woocommerce_cookie', array( __CLASS__, 'woocommerce_cookie' ) );
add_filter( 'woocommerce_session_handler', array( __CLASS__, 'init_ql_session_handler' ) );
add_filter( 'graphql_response_headers_to_send', array( __CLASS__, 'add_session_header_to_expose_headers' ) );
add_filter( 'graphql_access_control_allow_headers', array( __CLASS__, 'add_session_header_to_allow_headers' ) );
}
}

/**
Expand Down Expand Up @@ -204,55 +184,4 @@ public static function graphql_post_object_connection_query_args( $query_args, $
public static function graphql_term_object_connection_query_args( $query_args, $source, $args, $context, $info ) {
return WC_Terms_Connection_Resolver::get_query_args( $query_args, $source, $args, $context, $info );
}

/**
* Filters WooCommerce cookie key to be used as a HTTP Header on GraphQL HTTP requests
*
* @param string $cookie WooCommerce cookie key.
*
* @return string
*/
public static function woocommerce_cookie( $cookie ) {
return self::$session_header;
}

/**
* Filters WooCommerce session handler class on GraphQL HTTP requests
*
* @param string $session_class Classname of the current session handler class.
*
* @return string
*/
public static function init_ql_session_handler( $session_class ) {
return QL_Session_Handler::class;
}

/**
* Append session header to the exposed headers in GraphQL responses
*
* @param array $headers GraphQL responser headers.
*
* @return array
*/
public static function add_session_header_to_expose_headers( $headers ) {
if ( empty( $headers['Access-Control-Expose-Headers'] ) ) {
$headers['Access-Control-Expose-Headers'] = apply_filters( 'woocommerce_cookie', self::$session_header );
} else {
$headers['Access-Control-Expose-Headers'] .= ', ' . apply_filters( 'woocommerce_cookie', self::$session_header );
}

return $headers;
}

/**
* Append the session header to the allowed headers in GraphQL responses
*
* @param array $allowed_headers The existing allowed headers.
*
* @return array
*/
public static function add_session_header_to_allow_headers( array $allowed_headers ) {
$allowed_headers[] = self::$session_header;
return $allowed_headers;
}
}
Loading

0 comments on commit ead3970

Please sign in to comment.