Submit
Path:
~
/
/
usr
/
local
/
sitepad
/
editor
/
site-data
/
plugins
/
kkart-pro
/
packages
/
kkart-blocks
/
src
/
StoreApi
/
Routes
/
File Content:
AbstractRoute.php
<?php namespace Automattic\Kkart\Blocks\StoreApi\Routes; use Automattic\Kkart\Blocks\StoreApi\Schemas\AbstractSchema; /** * AbstractRoute class. * * @internal This API is used internally by Blocks--it is still in flux and may be subject to revisions. */ abstract class AbstractRoute implements RouteInterface { /** * Schema class instance. * * @var AbstractSchema */ protected $schema; /** * Constructor. * * @param AbstractSchema $schema Schema class for this route. */ public function __construct( AbstractSchema $schema ) { $this->schema = $schema; } /** * Get the namespace for this route. * * @return string */ public function get_namespace() { return 'kkart/store'; } /** * Get item schema properties. * * @return array */ public function get_item_schema() { return $this->schema->get_item_schema(); } /** * Get the route response based on the type of request. * * @param \WP_REST_Request $request Request object. * @return \WP_Error|\WP_REST_Response */ public function get_response( \WP_REST_Request $request ) { $response = null; try { if ( 'GET' !== $request->get_method() ) { $this->check_nonce( $request ); } switch ( $request->get_method() ) { case 'POST': $response = $this->get_route_post_response( $request ); break; case 'PUT': case 'PATCH': $response = $this->get_route_update_response( $request ); break; case 'DELETE': $response = $this->get_route_delete_response( $request ); break; default: $response = $this->get_route_response( $request ); break; } if ( 'GET' !== $request->get_method() && ! is_wp_error( $response ) ) { $response->header( 'X-KKART-Store-API-Nonce', wp_create_nonce( 'kkart_store_api' ) ); } } catch ( RouteException $error ) { $response = $this->get_route_error_response( $error->getErrorCode(), $error->getMessage(), $error->getCode(), $error->getAdditionalData() ); } catch ( \Exception $error ) { $response = $this->get_route_error_response( 'unknown_server_error', $error->getMessage(), 500 ); } return $response; } /** * For non-GET endpoints, require and validate a nonce to prevent CSRF attacks. * * Nonces will mismatch if the logged in session cookie is different! If using a client to test, set this cookie * to match the logged in cookie in your browser. * * @throws RouteException On error. * * @param \WP_REST_Request $request Request object. */ protected function check_nonce( \WP_REST_Request $request ) { $nonce = $request->get_header( 'X-KKART-Store-API-Nonce' ); if ( apply_filters( 'kkart_store_api_disable_nonce_check', false ) ) { return; } if ( null === $nonce ) { throw new RouteException( 'kkart_rest_missing_nonce', __( 'Missing the X-KKART-Store-API-Nonce header. This endpoint requires a valid nonce.', 'kkart' ), 401 ); } $valid_nonce = wp_verify_nonce( $nonce, 'kkart_store_api' ); if ( ! $valid_nonce ) { throw new RouteException( 'kkart_rest_invalid_nonce', __( 'X-KKART-Store-API-Nonce is invalid.', 'kkart' ), 403 ); } } /** * Get route response for GET requests. * * When implemented, should return a \WP_REST_Response. * * @throws RouteException On error. * @param \WP_REST_Request $request Request object. */ protected function get_route_response( \WP_REST_Request $request ) { throw new RouteException( 'kkart_rest_invalid_endpoint', __( 'Method not implemented', 'kkart' ), 404 ); } /** * Get route response for POST requests. * * When implemented, should return a \WP_REST_Response. * * @throws RouteException On error. * @param \WP_REST_Request $request Request object. */ protected function get_route_post_response( \WP_REST_Request $request ) { throw new RouteException( 'kkart_rest_invalid_endpoint', __( 'Method not implemented', 'kkart' ), 404 ); } /** * Get route response for PUT requests. * * When implemented, should return a \WP_REST_Response. * * @throws RouteException On error. * @param \WP_REST_Request $request Request object. */ protected function get_route_update_response( \WP_REST_Request $request ) { throw new RouteException( 'kkart_rest_invalid_endpoint', __( 'Method not implemented', 'kkart' ), 404 ); } /** * Get route response for DELETE requests. * * When implemented, should return a \WP_REST_Response. * * @throws RouteException On error. * @param \WP_REST_Request $request Request object. */ protected function get_route_delete_response( \WP_REST_Request $request ) { throw new RouteException( 'kkart_rest_invalid_endpoint', __( 'Method not implemented', 'kkart' ), 404 ); } /** * Get route response when something went wrong. * * @param string $error_code String based error code. * @param string $error_message User facing error message. * @param int $http_status_code HTTP status. Defaults to 500. * @param array $additional_data Extra data (key value pairs) to expose in the error response. * @return \WP_Error WP Error object. */ protected function get_route_error_response( $error_code, $error_message, $http_status_code = 500, $additional_data = [] ) { return new \WP_Error( $error_code, $error_message, array_merge( $additional_data, [ 'status' => $http_status_code ] ) ); } /** * Prepare a single item for response. * * @param mixed $item Item to format to schema. * @param \WP_REST_Request $request Request object. * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, \WP_REST_Request $request ) { $response = rest_ensure_response( $this->schema->get_item_response( $item ) ); $response->add_links( $this->prepare_links( $item, $request ) ); return $response; } /** * Retrieves the context param. * * Ensures consistent descriptions between endpoints, and populates enum from schema. * * @param array $args Optional. Additional arguments for context parameter. Default empty array. * @return array Context parameter details. */ protected function get_context_param( $args = array() ) { $param_details = array( 'description' => __( 'Scope under which the request is made; determines fields present in response.', 'kkart' ), 'type' => 'string', 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg', ); $schema = $this->get_item_schema(); if ( empty( $schema['properties'] ) ) { return array_merge( $param_details, $args ); } $contexts = array(); foreach ( $schema['properties'] as $attributes ) { if ( ! empty( $attributes['context'] ) ) { $contexts = array_merge( $contexts, $attributes['context'] ); } } if ( ! empty( $contexts ) ) { $param_details['enum'] = array_unique( $contexts ); rsort( $param_details['enum'] ); } return array_merge( $param_details, $args ); } /** * Prepares a response for insertion into a collection. * * @param \WP_REST_Response $response Response object. * @return array|mixed Response data, ready for insertion into collection data. */ protected function prepare_response_for_collection( \WP_REST_Response $response ) { $data = (array) $response->get_data(); $server = rest_get_server(); $links = $server::get_compact_response_links( $response ); if ( ! empty( $links ) ) { $data['_links'] = $links; } return $data; } /** * Prepare links for the request. * * @param mixed $item Item to prepare. * @param \WP_REST_Request $request Request object. * @return array */ protected function prepare_links( $item, $request ) { return []; } /** * Retrieves the query params for the collections. * * @return array Query parameters for the collection. */ public function get_collection_params() { return array( 'context' => $this->get_context_param(), ); } /** * Makes the cart and sessions available to a route by loading them from core. */ protected function maybe_load_cart() { if ( ! did_action( 'kkart_load_cart_from_session' ) && function_exists( 'kkart_load_cart' ) ) { include_once KKART_ABSPATH . 'includes/kkart-cart-functions.php'; include_once KKART_ABSPATH . 'includes/kkart-notice-functions.php'; kkart_load_cart(); } } }
Edit
Rename
Chmod
Delete
FILE
FOLDER
Name
Size
Permission
Action
AbstractCartRoute.php
2379 bytes
0644
AbstractRoute.php
8333 bytes
0644
AbstractTermsRoute.php
4776 bytes
0644
Cart.php
1347 bytes
0644
CartAddItem.php
2948 bytes
0644
CartApplyCoupon.php
1882 bytes
0644
CartCoupons.php
3823 bytes
0644
CartCouponsByCode.php
2469 bytes
0644
CartItems.php
3699 bytes
0644
CartItemsByKey.php
3903 bytes
0644
CartRemoveCoupon.php
2261 bytes
0644
CartRemoveItem.php
1721 bytes
0644
CartSelectShippingRate.php
2487 bytes
0644
CartUpdateItem.php
1739 bytes
0644
CartUpdateShipping.php
7330 bytes
0644
Checkout.php
17224 bytes
0644
ProductAttributeTerms.php
1607 bytes
0644
ProductAttributes.php
1390 bytes
0644
ProductAttributesById.php
1679 bytes
0644
ProductCategories.php
1136 bytes
0644
ProductCategoriesById.php
1651 bytes
0644
ProductCollectionData.php
5548 bytes
0644
ProductReviews.php
6618 bytes
0644
ProductTags.php
1118 bytes
0644
Products.php
12968 bytes
0644
ProductsById.php
1593 bytes
0644
RouteException.php
1393 bytes
0644
RouteInterface.php
551 bytes
0644
N4ST4R_ID | Naxtarrr