From 7cdcb01de7ec2a36cee562e8b16cf1f736adb649 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Fri, 6 Mar 2020 16:12:30 +0000 Subject: [PATCH 01/29] Move shopify resource classes into own folder. --- lib/{ => ShopifyResource}/AbandonedCheckout.php | 0 lib/{ => ShopifyResource}/ApplicationCharge.php | 0 lib/{ => ShopifyResource}/Article.php | 0 lib/{ => ShopifyResource}/Asset.php | 0 lib/{ => ShopifyResource}/Blog.php | 0 lib/{ => ShopifyResource}/CarrierService.php | 0 lib/{ => ShopifyResource}/Collect.php | 0 lib/{ => ShopifyResource}/Comment.php | 0 lib/{ => ShopifyResource}/Country.php | 0 lib/{ => ShopifyResource}/Currency.php | 0 lib/{ => ShopifyResource}/CustomCollection.php | 0 lib/{ => ShopifyResource}/Customer.php | 0 lib/{ => ShopifyResource}/CustomerAddress.php | 0 lib/{ => ShopifyResource}/CustomerSavedSearch.php | 0 lib/{ => ShopifyResource}/Discount.php | 0 lib/{ => ShopifyResource}/DiscountCode.php | 0 lib/{ => ShopifyResource}/DraftOrder.php | 0 lib/{ => ShopifyResource}/Event.php | 0 lib/{ => ShopifyResource}/Fulfillment.php | 0 lib/{ => ShopifyResource}/FulfillmentEvent.php | 0 lib/{ => ShopifyResource}/FulfillmentService.php | 0 lib/{ => ShopifyResource}/GiftCard.php | 0 lib/{ => ShopifyResource}/GraphQL.php | 0 lib/{ => ShopifyResource}/InventoryItem.php | 0 lib/{ => ShopifyResource}/InventoryLevel.php | 0 lib/{ => ShopifyResource}/Location.php | 0 lib/{ => ShopifyResource}/Metafield.php | 0 lib/{ => ShopifyResource}/Multipass.php | 0 lib/{ => ShopifyResource}/Order.php | 0 lib/{ => ShopifyResource}/OrderRisk.php | 0 lib/{ => ShopifyResource}/Page.php | 0 lib/{ => ShopifyResource}/Policy.php | 0 lib/{ => ShopifyResource}/PriceRule.php | 0 lib/{ => ShopifyResource}/Product.php | 0 lib/{ => ShopifyResource}/ProductImage.php | 0 lib/{ => ShopifyResource}/ProductListing.php | 0 lib/{ => ShopifyResource}/ProductVariant.php | 0 lib/{ => ShopifyResource}/Province.php | 0 lib/{ => ShopifyResource}/RecurringApplicationCharge.php | 0 lib/{ => ShopifyResource}/Redirect.php | 0 lib/{ => ShopifyResource}/Refund.php | 0 lib/{ => ShopifyResource}/Report.php | 0 lib/{ => ShopifyResource}/ScriptTag.php | 0 lib/{ => ShopifyResource}/ShippingZone.php | 0 lib/{ => ShopifyResource}/Shop.php | 0 lib/{ => ShopifyResource}/SmartCollection.php | 0 lib/{ => ShopifyResource}/Theme.php | 0 lib/{ => ShopifyResource}/Transaction.php | 0 lib/{ => ShopifyResource}/UsageCharge.php | 0 lib/{ => ShopifyResource}/User.php | 0 lib/{ => ShopifyResource}/Webhook.php | 0 51 files changed, 0 insertions(+), 0 deletions(-) rename lib/{ => ShopifyResource}/AbandonedCheckout.php (100%) rename lib/{ => ShopifyResource}/ApplicationCharge.php (100%) rename lib/{ => ShopifyResource}/Article.php (100%) rename lib/{ => ShopifyResource}/Asset.php (100%) rename lib/{ => ShopifyResource}/Blog.php (100%) rename lib/{ => ShopifyResource}/CarrierService.php (100%) rename lib/{ => ShopifyResource}/Collect.php (100%) rename lib/{ => ShopifyResource}/Comment.php (100%) rename lib/{ => ShopifyResource}/Country.php (100%) rename lib/{ => ShopifyResource}/Currency.php (100%) rename lib/{ => ShopifyResource}/CustomCollection.php (100%) rename lib/{ => ShopifyResource}/Customer.php (100%) rename lib/{ => ShopifyResource}/CustomerAddress.php (100%) rename lib/{ => ShopifyResource}/CustomerSavedSearch.php (100%) rename lib/{ => ShopifyResource}/Discount.php (100%) rename lib/{ => ShopifyResource}/DiscountCode.php (100%) rename lib/{ => ShopifyResource}/DraftOrder.php (100%) rename lib/{ => ShopifyResource}/Event.php (100%) rename lib/{ => ShopifyResource}/Fulfillment.php (100%) rename lib/{ => ShopifyResource}/FulfillmentEvent.php (100%) rename lib/{ => ShopifyResource}/FulfillmentService.php (100%) rename lib/{ => ShopifyResource}/GiftCard.php (100%) rename lib/{ => ShopifyResource}/GraphQL.php (100%) rename lib/{ => ShopifyResource}/InventoryItem.php (100%) rename lib/{ => ShopifyResource}/InventoryLevel.php (100%) rename lib/{ => ShopifyResource}/Location.php (100%) rename lib/{ => ShopifyResource}/Metafield.php (100%) rename lib/{ => ShopifyResource}/Multipass.php (100%) rename lib/{ => ShopifyResource}/Order.php (100%) rename lib/{ => ShopifyResource}/OrderRisk.php (100%) rename lib/{ => ShopifyResource}/Page.php (100%) rename lib/{ => ShopifyResource}/Policy.php (100%) rename lib/{ => ShopifyResource}/PriceRule.php (100%) rename lib/{ => ShopifyResource}/Product.php (100%) rename lib/{ => ShopifyResource}/ProductImage.php (100%) rename lib/{ => ShopifyResource}/ProductListing.php (100%) rename lib/{ => ShopifyResource}/ProductVariant.php (100%) rename lib/{ => ShopifyResource}/Province.php (100%) rename lib/{ => ShopifyResource}/RecurringApplicationCharge.php (100%) rename lib/{ => ShopifyResource}/Redirect.php (100%) rename lib/{ => ShopifyResource}/Refund.php (100%) rename lib/{ => ShopifyResource}/Report.php (100%) rename lib/{ => ShopifyResource}/ScriptTag.php (100%) rename lib/{ => ShopifyResource}/ShippingZone.php (100%) rename lib/{ => ShopifyResource}/Shop.php (100%) rename lib/{ => ShopifyResource}/SmartCollection.php (100%) rename lib/{ => ShopifyResource}/Theme.php (100%) rename lib/{ => ShopifyResource}/Transaction.php (100%) rename lib/{ => ShopifyResource}/UsageCharge.php (100%) rename lib/{ => ShopifyResource}/User.php (100%) rename lib/{ => ShopifyResource}/Webhook.php (100%) diff --git a/lib/AbandonedCheckout.php b/lib/ShopifyResource/AbandonedCheckout.php similarity index 100% rename from lib/AbandonedCheckout.php rename to lib/ShopifyResource/AbandonedCheckout.php diff --git a/lib/ApplicationCharge.php b/lib/ShopifyResource/ApplicationCharge.php similarity index 100% rename from lib/ApplicationCharge.php rename to lib/ShopifyResource/ApplicationCharge.php diff --git a/lib/Article.php b/lib/ShopifyResource/Article.php similarity index 100% rename from lib/Article.php rename to lib/ShopifyResource/Article.php diff --git a/lib/Asset.php b/lib/ShopifyResource/Asset.php similarity index 100% rename from lib/Asset.php rename to lib/ShopifyResource/Asset.php diff --git a/lib/Blog.php b/lib/ShopifyResource/Blog.php similarity index 100% rename from lib/Blog.php rename to lib/ShopifyResource/Blog.php diff --git a/lib/CarrierService.php b/lib/ShopifyResource/CarrierService.php similarity index 100% rename from lib/CarrierService.php rename to lib/ShopifyResource/CarrierService.php diff --git a/lib/Collect.php b/lib/ShopifyResource/Collect.php similarity index 100% rename from lib/Collect.php rename to lib/ShopifyResource/Collect.php diff --git a/lib/Comment.php b/lib/ShopifyResource/Comment.php similarity index 100% rename from lib/Comment.php rename to lib/ShopifyResource/Comment.php diff --git a/lib/Country.php b/lib/ShopifyResource/Country.php similarity index 100% rename from lib/Country.php rename to lib/ShopifyResource/Country.php diff --git a/lib/Currency.php b/lib/ShopifyResource/Currency.php similarity index 100% rename from lib/Currency.php rename to lib/ShopifyResource/Currency.php diff --git a/lib/CustomCollection.php b/lib/ShopifyResource/CustomCollection.php similarity index 100% rename from lib/CustomCollection.php rename to lib/ShopifyResource/CustomCollection.php diff --git a/lib/Customer.php b/lib/ShopifyResource/Customer.php similarity index 100% rename from lib/Customer.php rename to lib/ShopifyResource/Customer.php diff --git a/lib/CustomerAddress.php b/lib/ShopifyResource/CustomerAddress.php similarity index 100% rename from lib/CustomerAddress.php rename to lib/ShopifyResource/CustomerAddress.php diff --git a/lib/CustomerSavedSearch.php b/lib/ShopifyResource/CustomerSavedSearch.php similarity index 100% rename from lib/CustomerSavedSearch.php rename to lib/ShopifyResource/CustomerSavedSearch.php diff --git a/lib/Discount.php b/lib/ShopifyResource/Discount.php similarity index 100% rename from lib/Discount.php rename to lib/ShopifyResource/Discount.php diff --git a/lib/DiscountCode.php b/lib/ShopifyResource/DiscountCode.php similarity index 100% rename from lib/DiscountCode.php rename to lib/ShopifyResource/DiscountCode.php diff --git a/lib/DraftOrder.php b/lib/ShopifyResource/DraftOrder.php similarity index 100% rename from lib/DraftOrder.php rename to lib/ShopifyResource/DraftOrder.php diff --git a/lib/Event.php b/lib/ShopifyResource/Event.php similarity index 100% rename from lib/Event.php rename to lib/ShopifyResource/Event.php diff --git a/lib/Fulfillment.php b/lib/ShopifyResource/Fulfillment.php similarity index 100% rename from lib/Fulfillment.php rename to lib/ShopifyResource/Fulfillment.php diff --git a/lib/FulfillmentEvent.php b/lib/ShopifyResource/FulfillmentEvent.php similarity index 100% rename from lib/FulfillmentEvent.php rename to lib/ShopifyResource/FulfillmentEvent.php diff --git a/lib/FulfillmentService.php b/lib/ShopifyResource/FulfillmentService.php similarity index 100% rename from lib/FulfillmentService.php rename to lib/ShopifyResource/FulfillmentService.php diff --git a/lib/GiftCard.php b/lib/ShopifyResource/GiftCard.php similarity index 100% rename from lib/GiftCard.php rename to lib/ShopifyResource/GiftCard.php diff --git a/lib/GraphQL.php b/lib/ShopifyResource/GraphQL.php similarity index 100% rename from lib/GraphQL.php rename to lib/ShopifyResource/GraphQL.php diff --git a/lib/InventoryItem.php b/lib/ShopifyResource/InventoryItem.php similarity index 100% rename from lib/InventoryItem.php rename to lib/ShopifyResource/InventoryItem.php diff --git a/lib/InventoryLevel.php b/lib/ShopifyResource/InventoryLevel.php similarity index 100% rename from lib/InventoryLevel.php rename to lib/ShopifyResource/InventoryLevel.php diff --git a/lib/Location.php b/lib/ShopifyResource/Location.php similarity index 100% rename from lib/Location.php rename to lib/ShopifyResource/Location.php diff --git a/lib/Metafield.php b/lib/ShopifyResource/Metafield.php similarity index 100% rename from lib/Metafield.php rename to lib/ShopifyResource/Metafield.php diff --git a/lib/Multipass.php b/lib/ShopifyResource/Multipass.php similarity index 100% rename from lib/Multipass.php rename to lib/ShopifyResource/Multipass.php diff --git a/lib/Order.php b/lib/ShopifyResource/Order.php similarity index 100% rename from lib/Order.php rename to lib/ShopifyResource/Order.php diff --git a/lib/OrderRisk.php b/lib/ShopifyResource/OrderRisk.php similarity index 100% rename from lib/OrderRisk.php rename to lib/ShopifyResource/OrderRisk.php diff --git a/lib/Page.php b/lib/ShopifyResource/Page.php similarity index 100% rename from lib/Page.php rename to lib/ShopifyResource/Page.php diff --git a/lib/Policy.php b/lib/ShopifyResource/Policy.php similarity index 100% rename from lib/Policy.php rename to lib/ShopifyResource/Policy.php diff --git a/lib/PriceRule.php b/lib/ShopifyResource/PriceRule.php similarity index 100% rename from lib/PriceRule.php rename to lib/ShopifyResource/PriceRule.php diff --git a/lib/Product.php b/lib/ShopifyResource/Product.php similarity index 100% rename from lib/Product.php rename to lib/ShopifyResource/Product.php diff --git a/lib/ProductImage.php b/lib/ShopifyResource/ProductImage.php similarity index 100% rename from lib/ProductImage.php rename to lib/ShopifyResource/ProductImage.php diff --git a/lib/ProductListing.php b/lib/ShopifyResource/ProductListing.php similarity index 100% rename from lib/ProductListing.php rename to lib/ShopifyResource/ProductListing.php diff --git a/lib/ProductVariant.php b/lib/ShopifyResource/ProductVariant.php similarity index 100% rename from lib/ProductVariant.php rename to lib/ShopifyResource/ProductVariant.php diff --git a/lib/Province.php b/lib/ShopifyResource/Province.php similarity index 100% rename from lib/Province.php rename to lib/ShopifyResource/Province.php diff --git a/lib/RecurringApplicationCharge.php b/lib/ShopifyResource/RecurringApplicationCharge.php similarity index 100% rename from lib/RecurringApplicationCharge.php rename to lib/ShopifyResource/RecurringApplicationCharge.php diff --git a/lib/Redirect.php b/lib/ShopifyResource/Redirect.php similarity index 100% rename from lib/Redirect.php rename to lib/ShopifyResource/Redirect.php diff --git a/lib/Refund.php b/lib/ShopifyResource/Refund.php similarity index 100% rename from lib/Refund.php rename to lib/ShopifyResource/Refund.php diff --git a/lib/Report.php b/lib/ShopifyResource/Report.php similarity index 100% rename from lib/Report.php rename to lib/ShopifyResource/Report.php diff --git a/lib/ScriptTag.php b/lib/ShopifyResource/ScriptTag.php similarity index 100% rename from lib/ScriptTag.php rename to lib/ShopifyResource/ScriptTag.php diff --git a/lib/ShippingZone.php b/lib/ShopifyResource/ShippingZone.php similarity index 100% rename from lib/ShippingZone.php rename to lib/ShopifyResource/ShippingZone.php diff --git a/lib/Shop.php b/lib/ShopifyResource/Shop.php similarity index 100% rename from lib/Shop.php rename to lib/ShopifyResource/Shop.php diff --git a/lib/SmartCollection.php b/lib/ShopifyResource/SmartCollection.php similarity index 100% rename from lib/SmartCollection.php rename to lib/ShopifyResource/SmartCollection.php diff --git a/lib/Theme.php b/lib/ShopifyResource/Theme.php similarity index 100% rename from lib/Theme.php rename to lib/ShopifyResource/Theme.php diff --git a/lib/Transaction.php b/lib/ShopifyResource/Transaction.php similarity index 100% rename from lib/Transaction.php rename to lib/ShopifyResource/Transaction.php diff --git a/lib/UsageCharge.php b/lib/ShopifyResource/UsageCharge.php similarity index 100% rename from lib/UsageCharge.php rename to lib/ShopifyResource/UsageCharge.php diff --git a/lib/User.php b/lib/ShopifyResource/User.php similarity index 100% rename from lib/User.php rename to lib/ShopifyResource/User.php diff --git a/lib/Webhook.php b/lib/ShopifyResource/Webhook.php similarity index 100% rename from lib/Webhook.php rename to lib/ShopifyResource/Webhook.php From 47101335e397001fd17a98c630b7001e56908ccb Mon Sep 17 00:00:00 2001 From: joeyhub Date: Fri, 6 Mar 2020 16:19:07 +0000 Subject: [PATCH 02/29] Update namespace / use for new location and clean up some excessive whitespace. --- lib/ShopifyResource/AbandonedCheckout.php | 3 ++- lib/ShopifyResource/ApplicationCharge.php | 3 ++- lib/ShopifyResource/Article.php | 3 ++- lib/ShopifyResource/Asset.php | 3 ++- lib/ShopifyResource/Blog.php | 4 +++- lib/ShopifyResource/CarrierService.php | 3 ++- lib/ShopifyResource/Collect.php | 3 ++- lib/ShopifyResource/Comment.php | 3 ++- lib/ShopifyResource/Country.php | 3 ++- lib/ShopifyResource/Currency.php | 3 ++- lib/ShopifyResource/CustomCollection.php | 3 ++- lib/ShopifyResource/Customer.php | 3 ++- lib/ShopifyResource/CustomerAddress.php | 3 ++- lib/ShopifyResource/CustomerSavedSearch.php | 3 ++- lib/ShopifyResource/Discount.php | 3 ++- lib/ShopifyResource/DiscountCode.php | 3 ++- lib/ShopifyResource/DraftOrder.php | 4 ++-- lib/ShopifyResource/Event.php | 3 ++- lib/ShopifyResource/Fulfillment.php | 3 ++- lib/ShopifyResource/FulfillmentEvent.php | 3 ++- lib/ShopifyResource/FulfillmentService.php | 3 ++- lib/ShopifyResource/GiftCard.php | 3 ++- lib/ShopifyResource/GraphQL.php | 5 ++--- lib/ShopifyResource/InventoryItem.php | 4 +++- lib/ShopifyResource/InventoryLevel.php | 4 +++- lib/ShopifyResource/Location.php | 3 ++- lib/ShopifyResource/Metafield.php | 3 ++- lib/ShopifyResource/Multipass.php | 4 ++-- lib/ShopifyResource/Order.php | 4 ++-- lib/ShopifyResource/OrderRisk.php | 3 ++- lib/ShopifyResource/Page.php | 3 ++- lib/ShopifyResource/Policy.php | 3 ++- lib/ShopifyResource/PriceRule.php | 3 ++- lib/ShopifyResource/Product.php | 3 ++- lib/ShopifyResource/ProductImage.php | 3 ++- lib/ShopifyResource/ProductListing.php | 3 ++- lib/ShopifyResource/ProductVariant.php | 4 +++- lib/ShopifyResource/Province.php | 3 ++- lib/ShopifyResource/RecurringApplicationCharge.php | 3 ++- lib/ShopifyResource/Redirect.php | 3 ++- lib/ShopifyResource/Refund.php | 3 ++- lib/ShopifyResource/Report.php | 4 +++- lib/ShopifyResource/ScriptTag.php | 3 ++- lib/ShopifyResource/ShippingZone.php | 3 ++- lib/ShopifyResource/Shop.php | 3 ++- lib/ShopifyResource/SmartCollection.php | 3 ++- lib/ShopifyResource/Theme.php | 3 ++- lib/ShopifyResource/Transaction.php | 3 ++- lib/ShopifyResource/UsageCharge.php | 3 ++- lib/ShopifyResource/User.php | 3 ++- lib/ShopifyResource/Webhook.php | 3 ++- 51 files changed, 107 insertions(+), 56 deletions(-) diff --git a/lib/ShopifyResource/AbandonedCheckout.php b/lib/ShopifyResource/AbandonedCheckout.php index 15686cc..f40c6dc 100644 --- a/lib/ShopifyResource/AbandonedCheckout.php +++ b/lib/ShopifyResource/AbandonedCheckout.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/abandoned_checkouts Shopify API Reference for Abandoned checkouts */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class AbandonedCheckout extends ShopifyResource { diff --git a/lib/ShopifyResource/ApplicationCharge.php b/lib/ShopifyResource/ApplicationCharge.php index b557911..7fc6695 100644 --- a/lib/ShopifyResource/ApplicationCharge.php +++ b/lib/ShopifyResource/ApplicationCharge.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/applicationcharge Shopify API Reference for ApplicationCharge */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class ApplicationCharge extends ShopifyResource { diff --git a/lib/ShopifyResource/Article.php b/lib/ShopifyResource/Article.php index e1fb53c..b56b066 100644 --- a/lib/ShopifyResource/Article.php +++ b/lib/ShopifyResource/Article.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/article Shopify API Reference for Article */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/Asset.php b/lib/ShopifyResource/Asset.php index 56a1007..9189773 100644 --- a/lib/ShopifyResource/Asset.php +++ b/lib/ShopifyResource/Asset.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/asset Shopify API Reference for Asset */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class Asset extends ShopifyResource { diff --git a/lib/ShopifyResource/Blog.php b/lib/ShopifyResource/Blog.php index 83d0370..a6b288e 100644 --- a/lib/ShopifyResource/Blog.php +++ b/lib/ShopifyResource/Blog.php @@ -7,7 +7,9 @@ * @see https://help.shopify.com/api/reference/blog Shopify API Reference for Blog */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; + +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/CarrierService.php b/lib/ShopifyResource/CarrierService.php index edb5e29..0e0caa3 100644 --- a/lib/ShopifyResource/CarrierService.php +++ b/lib/ShopifyResource/CarrierService.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/carrierservice Shopify API Reference for CarrierService */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class CarrierService extends ShopifyResource { diff --git a/lib/ShopifyResource/Collect.php b/lib/ShopifyResource/Collect.php index 99e8c13..29c8865 100644 --- a/lib/ShopifyResource/Collect.php +++ b/lib/ShopifyResource/Collect.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/collect Shopify API Reference for Collect */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class Collect extends ShopifyResource { diff --git a/lib/ShopifyResource/Comment.php b/lib/ShopifyResource/Comment.php index ca749bc..cff0fac 100644 --- a/lib/ShopifyResource/Comment.php +++ b/lib/ShopifyResource/Comment.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/comment Shopify API Reference for Comment */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * diff --git a/lib/ShopifyResource/Country.php b/lib/ShopifyResource/Country.php index 158fd5d..1a42c45 100644 --- a/lib/ShopifyResource/Country.php +++ b/lib/ShopifyResource/Country.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/country Shopify API Reference for Country */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/Currency.php b/lib/ShopifyResource/Currency.php index a93a68b..ac84e8b 100644 --- a/lib/ShopifyResource/Currency.php +++ b/lib/ShopifyResource/Currency.php @@ -8,8 +8,9 @@ * @see https://help.shopify.com/en/api/reference/store-properties/currency Shopify API Reference for Currency */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class Currency extends ShopifyResource { diff --git a/lib/ShopifyResource/CustomCollection.php b/lib/ShopifyResource/CustomCollection.php index 22fb555..8fda0c6 100644 --- a/lib/ShopifyResource/CustomCollection.php +++ b/lib/ShopifyResource/CustomCollection.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/customcollection Shopify API Reference for CustomCollection */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/Customer.php b/lib/ShopifyResource/Customer.php index a058624..ee203f1 100644 --- a/lib/ShopifyResource/Customer.php +++ b/lib/ShopifyResource/Customer.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/customer Shopify API Reference for Customer */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/CustomerAddress.php b/lib/ShopifyResource/CustomerAddress.php index 32c60c1..e4016c3 100644 --- a/lib/ShopifyResource/CustomerAddress.php +++ b/lib/ShopifyResource/CustomerAddress.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/customeraddress Shopify API Reference for CustomerAddress */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/CustomerSavedSearch.php b/lib/ShopifyResource/CustomerSavedSearch.php index 3cec785..5769128 100644 --- a/lib/ShopifyResource/CustomerSavedSearch.php +++ b/lib/ShopifyResource/CustomerSavedSearch.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/customersavedsearch Shopify API Reference for CustomerSavedSearch */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/Discount.php b/lib/ShopifyResource/Discount.php index f2779aa..69b659e 100644 --- a/lib/ShopifyResource/Discount.php +++ b/lib/ShopifyResource/Discount.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/discount Shopify API Reference for Discount */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/DiscountCode.php b/lib/ShopifyResource/DiscountCode.php index e13889e..c42538b 100644 --- a/lib/ShopifyResource/DiscountCode.php +++ b/lib/ShopifyResource/DiscountCode.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/discounts/discountcode Shopify API Reference for PriceRule */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/DraftOrder.php b/lib/ShopifyResource/DraftOrder.php index 902cee5..1b3f66d 100644 --- a/lib/ShopifyResource/DraftOrder.php +++ b/lib/ShopifyResource/DraftOrder.php @@ -7,9 +7,9 @@ * @see https://help.shopify.com/api/reference/draftorder Shopify API Reference for DraftOrder */ -namespace PHPShopify; - +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/Event.php b/lib/ShopifyResource/Event.php index 830c540..619bd46 100644 --- a/lib/ShopifyResource/Event.php +++ b/lib/ShopifyResource/Event.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/event/ Shopify API Reference for Event */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class Event extends ShopifyResource { diff --git a/lib/ShopifyResource/Fulfillment.php b/lib/ShopifyResource/Fulfillment.php index 18138d2..1fe9037 100644 --- a/lib/ShopifyResource/Fulfillment.php +++ b/lib/ShopifyResource/Fulfillment.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/fulfillment Shopify API Reference for Fulfillment */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/FulfillmentEvent.php b/lib/ShopifyResource/FulfillmentEvent.php index cc44f83..bdc4e8d 100644 --- a/lib/ShopifyResource/FulfillmentEvent.php +++ b/lib/ShopifyResource/FulfillmentEvent.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/fulfillmentevent Shopify API Reference for FulfillmentEvent */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class FulfillmentEvent extends ShopifyResource { diff --git a/lib/ShopifyResource/FulfillmentService.php b/lib/ShopifyResource/FulfillmentService.php index a4b1612..b6cb8f5 100644 --- a/lib/ShopifyResource/FulfillmentService.php +++ b/lib/ShopifyResource/FulfillmentService.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/fulfillmentservice Shopify API Reference for FulfillmentService */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class FulfillmentService extends ShopifyResource { diff --git a/lib/ShopifyResource/GiftCard.php b/lib/ShopifyResource/GiftCard.php index 2391064..3491d42 100644 --- a/lib/ShopifyResource/GiftCard.php +++ b/lib/ShopifyResource/GiftCard.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/gift_card Shopify API Reference for GiftCard */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/GraphQL.php b/lib/ShopifyResource/GraphQL.php index 185593b..05acd50 100644 --- a/lib/ShopifyResource/GraphQL.php +++ b/lib/ShopifyResource/GraphQL.php @@ -8,16 +8,15 @@ * @see https://help.shopify.com/en/api/graphql-admin-api GraphQL Admin API */ -namespace PHPShopify; - +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; use PHPShopify\Exception\ApiException; use PHPShopify\Exception\CurlException; use PHPShopify\Exception\SdkException; class GraphQL extends ShopifyResource { - /** * @inheritdoc */ diff --git a/lib/ShopifyResource/InventoryItem.php b/lib/ShopifyResource/InventoryItem.php index 7f55df9..414293f 100644 --- a/lib/ShopifyResource/InventoryItem.php +++ b/lib/ShopifyResource/InventoryItem.php @@ -6,7 +6,9 @@ * @see https://help.shopify.com/api/reference/inventoryitem */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; + +use PHPShopify\ShopifyResource; class InventoryItem extends ShopifyResource { diff --git a/lib/ShopifyResource/InventoryLevel.php b/lib/ShopifyResource/InventoryLevel.php index 682a43f..537eec8 100644 --- a/lib/ShopifyResource/InventoryLevel.php +++ b/lib/ShopifyResource/InventoryLevel.php @@ -6,7 +6,9 @@ * @see https://help.shopify.com/api/reference/inventorylevel */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; + +use PHPShopify\ShopifyResource; /** * Class InventoryLevel diff --git a/lib/ShopifyResource/Location.php b/lib/ShopifyResource/Location.php index f4a589a..69606c1 100644 --- a/lib/ShopifyResource/Location.php +++ b/lib/ShopifyResource/Location.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/location Shopify API Reference for Location */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class Location extends ShopifyResource { diff --git a/lib/ShopifyResource/Metafield.php b/lib/ShopifyResource/Metafield.php index 95d0853..998f39e 100644 --- a/lib/ShopifyResource/Metafield.php +++ b/lib/ShopifyResource/Metafield.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/metafield Shopify API Reference for Metafield */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class Metafield extends ShopifyResource { diff --git a/lib/ShopifyResource/Multipass.php b/lib/ShopifyResource/Multipass.php index 51e542d..b21d913 100644 --- a/lib/ShopifyResource/Multipass.php +++ b/lib/ShopifyResource/Multipass.php @@ -7,9 +7,9 @@ * @see https://help.shopify.com/api/reference/multipass Shopify API Reference for Multipass */ -namespace PHPShopify; - +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; use PHPShopify\Exception\ApiException; class Multipass extends ShopifyResource diff --git a/lib/ShopifyResource/Order.php b/lib/ShopifyResource/Order.php index 98efd2a..bea2b53 100644 --- a/lib/ShopifyResource/Order.php +++ b/lib/ShopifyResource/Order.php @@ -7,9 +7,9 @@ * @see https://help.shopify.com/api/reference/order Shopify API Reference for Order */ -namespace PHPShopify; - +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/OrderRisk.php b/lib/ShopifyResource/OrderRisk.php index 9281b7b..281a96d 100644 --- a/lib/ShopifyResource/OrderRisk.php +++ b/lib/ShopifyResource/OrderRisk.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/order_risks Shopify API Reference for Order Risks */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class OrderRisk extends ShopifyResource { diff --git a/lib/ShopifyResource/Page.php b/lib/ShopifyResource/Page.php index 7b01ca0..2d2e466 100644 --- a/lib/ShopifyResource/Page.php +++ b/lib/ShopifyResource/Page.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/page Shopify API Reference for Page */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/Policy.php b/lib/ShopifyResource/Policy.php index 53598c8..a43bfda 100644 --- a/lib/ShopifyResource/Policy.php +++ b/lib/ShopifyResource/Policy.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/policy Shopify API Reference for Policy */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class Policy extends ShopifyResource { diff --git a/lib/ShopifyResource/PriceRule.php b/lib/ShopifyResource/PriceRule.php index de08014..0101864 100644 --- a/lib/ShopifyResource/PriceRule.php +++ b/lib/ShopifyResource/PriceRule.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/discounts/pricerule Shopify API Reference for PriceRule */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/Product.php b/lib/ShopifyResource/Product.php index f866d32..371c7c6 100644 --- a/lib/ShopifyResource/Product.php +++ b/lib/ShopifyResource/Product.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/product Shopify API Reference for Product */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/ProductImage.php b/lib/ShopifyResource/ProductImage.php index 5ba26cd..dd6d9bc 100644 --- a/lib/ShopifyResource/ProductImage.php +++ b/lib/ShopifyResource/ProductImage.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/product_image Shopify API Reference for Product Image */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class ProductImage extends ShopifyResource { diff --git a/lib/ShopifyResource/ProductListing.php b/lib/ShopifyResource/ProductListing.php index 912a25f..399ea3a 100644 --- a/lib/ShopifyResource/ProductListing.php +++ b/lib/ShopifyResource/ProductListing.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/sales_channels/productlisting Shopify API Reference for Shipping Zone */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class ProductListing extends ShopifyResource { diff --git a/lib/ShopifyResource/ProductVariant.php b/lib/ShopifyResource/ProductVariant.php index fd34066..e19256b 100644 --- a/lib/ShopifyResource/ProductVariant.php +++ b/lib/ShopifyResource/ProductVariant.php @@ -7,7 +7,9 @@ * @see https://help.shopify.com/api/reference/product_variant Shopify API Reference for Product Variant */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; + +use PHPShopify\ShopifyResource; /** diff --git a/lib/ShopifyResource/Province.php b/lib/ShopifyResource/Province.php index efc0cf2..d0e3588 100644 --- a/lib/ShopifyResource/Province.php +++ b/lib/ShopifyResource/Province.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/province Shopify API Reference for Province */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class Province extends ShopifyResource { diff --git a/lib/ShopifyResource/RecurringApplicationCharge.php b/lib/ShopifyResource/RecurringApplicationCharge.php index 4ec74a9..b581078 100644 --- a/lib/ShopifyResource/RecurringApplicationCharge.php +++ b/lib/ShopifyResource/RecurringApplicationCharge.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/recurringapplicationcharge Shopify API Reference for RecurringApplicationCharge */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/Redirect.php b/lib/ShopifyResource/Redirect.php index 85cc643..aac26d5 100644 --- a/lib/ShopifyResource/Redirect.php +++ b/lib/ShopifyResource/Redirect.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/redirect Shopify API Reference for Redirect */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; class Redirect extends ShopifyResource { diff --git a/lib/ShopifyResource/Refund.php b/lib/ShopifyResource/Refund.php index c91edbe..00dd11b 100644 --- a/lib/ShopifyResource/Refund.php +++ b/lib/ShopifyResource/Refund.php @@ -7,8 +7,9 @@ * @see https://help.shopify.com/api/reference/refund Shopify API Reference for Refund */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\ShopifyResource; /** * -------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/Report.php b/lib/ShopifyResource/Report.php index 8a646cc..8e34ff3 100644 --- a/lib/ShopifyResource/Report.php +++ b/lib/ShopifyResource/Report.php @@ -1,6 +1,8 @@ Date: Fri, 6 Mar 2020 16:20:28 +0000 Subject: [PATCH 03/29] Remove whitespace from other classes. --- lib/AuthHelper.php | 1 - lib/CurlRequest.php | 1 - lib/Exception/CurlException.php | 1 - lib/Exception/SdkException.php | 1 - lib/HttpRequestGraphQL.php | 1 - lib/ShopifySDK.php | 1 - 6 files changed, 6 deletions(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index e879964..eb18f2b 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -7,7 +7,6 @@ namespace PHPShopify; - use PHPShopify\Exception\SdkException; class AuthHelper diff --git a/lib/CurlRequest.php b/lib/CurlRequest.php index 73567e1..ee2da1c 100644 --- a/lib/CurlRequest.php +++ b/lib/CurlRequest.php @@ -7,7 +7,6 @@ namespace PHPShopify; - use PHPShopify\Exception\CurlException; use PHPShopify\Exception\ResourceRateLimitException; diff --git a/lib/Exception/CurlException.php b/lib/Exception/CurlException.php index 21f2b40..fe00e8f 100644 --- a/lib/Exception/CurlException.php +++ b/lib/Exception/CurlException.php @@ -7,7 +7,6 @@ namespace PHPShopify\Exception; - class CurlException extends \Exception { diff --git a/lib/Exception/SdkException.php b/lib/Exception/SdkException.php index b0cdf93..343ca46 100644 --- a/lib/Exception/SdkException.php +++ b/lib/Exception/SdkException.php @@ -7,7 +7,6 @@ namespace PHPShopify\Exception; - class SdkException extends \Exception { diff --git a/lib/HttpRequestGraphQL.php b/lib/HttpRequestGraphQL.php index 8aef907..ab437af 100644 --- a/lib/HttpRequestGraphQL.php +++ b/lib/HttpRequestGraphQL.php @@ -8,7 +8,6 @@ namespace PHPShopify; - use PHPShopify\Exception\SdkException; class HttpRequestGraphQL extends HttpRequestJson diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 7fab8c2..ec58cae 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -9,7 +9,6 @@ namespace PHPShopify; - /* |-------------------------------------------------------------------------- | Shopify API SDK Client Class From 943951e6480b183022b6d22a0f0835c3bb992630 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Fri, 6 Mar 2020 16:38:18 +0000 Subject: [PATCH 04/29] Switch shopify resource to use new namespace (bit ugly, this should be extensible). Clean up curl request hacks. --- lib/CurlRequest.php | 27 ++++++--------------------- lib/ShopifyResource.php | 12 +++++++++++- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/lib/CurlRequest.php b/lib/CurlRequest.php index ee2da1c..dcb61d0 100644 --- a/lib/CurlRequest.php +++ b/lib/CurlRequest.php @@ -10,14 +10,6 @@ use PHPShopify\Exception\CurlException; use PHPShopify\Exception\ResourceRateLimitException; -/* -|-------------------------------------------------------------------------- -| CurlRequest -|-------------------------------------------------------------------------- -| -| This class handles get, post, put, delete HTTP requests -| -*/ class CurlRequest { /** @@ -73,11 +65,10 @@ protected static function init($url, $httpHeaders = array()) * @param string $url * @param array $httpHeaders * - * @return string + * @return CurlResponse */ public static function get($url, $httpHeaders = array()) { - //Initialize the Curl resource $ch = self::init($url, $httpHeaders); return self::processRequest($ch); @@ -90,12 +81,11 @@ public static function get($url, $httpHeaders = array()) * @param array $data * @param array $httpHeaders * - * @return string + * @return CurlResponse */ public static function post($url, $data, $httpHeaders = array()) { $ch = self::init($url, $httpHeaders); - //Set the request type curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); @@ -109,12 +99,11 @@ public static function post($url, $data, $httpHeaders = array()) * @param array $data * @param array $httpHeaders * - * @return string + * @return CurlResponse */ public static function put($url, $data, $httpHeaders = array()) { $ch = self::init($url, $httpHeaders); - //set the request type curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); @@ -127,12 +116,11 @@ public static function put($url, $data, $httpHeaders = array()) * @param string $url * @param array $httpHeaders * - * @return string + * @return CurlResponse */ public static function delete($url, $httpHeaders = array()) { $ch = self::init($url, $httpHeaders); - //set the request type curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); return self::processRequest($ch); @@ -145,7 +133,7 @@ public static function delete($url, $httpHeaders = array()) * * @throws CurlException if curl request is failed with error * - * @return string + * @return CurlResponse */ protected static function processRequest($ch) { @@ -175,9 +163,6 @@ protected static function processRequest($ch) // close curl resource to free up system resources curl_close($ch); - self::$lastHttpResponseHeaders = $response->getHeaders(); - - return $response->getBody(); + return $response; } - } diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 1b021d6..a321bcd 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -198,7 +198,7 @@ public function __call($name, $arguments) //otherwise the childname will be the class name $childClassName = !is_numeric($childKey) ? $childKey : $name; - $childClass = __NAMESPACE__ . "\\" . $childClassName; + $childClass = self::class . "\\" . $childClassName; //If first argument is provided, it will be considered as the ID of the resource. $resourceID = !empty($arguments) ? $arguments[0] : null; @@ -339,7 +339,17 @@ public function get($urlParams = array(), $url = null, $dataKey = null) if (!$dataKey) $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey(); return $this->processResponse($response, $dataKey); + } + + public function get($urlParams = array(), $url = null, $dataKey = null) + { + if (!$url) $url = $this->generateUrl($urlParams); + $response = HttpRequestJson::get($url, $this->httpHeaders); + + if (!$dataKey) $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey(); + + return $this->processResponse($response, $dataKey); } /** From f4bf8448a7b5dbec3cf1b5c25ac3ab1e4422ec31 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Fri, 6 Mar 2020 20:40:38 +0000 Subject: [PATCH 05/29] Pre beer. --- composer.json | 2 +- lib/AuthHelper.php | 93 +++++------ lib/CurlRequest.php | 189 ++++++++++------------ lib/CurlResponse.php | 53 ++---- lib/HttpRequestGraphQL.php | 74 --------- lib/HttpRequestJson.php | 133 ++------------- lib/ShopifyResource.php | 144 ++++++----------- lib/ShopifyResource/AbandonedCheckout.php | 5 +- lib/ShopifyResource/ApplicationCharge.php | 11 +- lib/ShopifyResource/Article.php | 13 +- lib/ShopifyResource/Asset.php | 5 +- lib/ShopifyResource/Blog.php | 2 +- lib/ShopifyResource/CarrierService.php | 2 +- lib/ShopifyResource/Collect.php | 2 +- lib/ShopifyResource/Comment.php | 2 +- lib/ShopifyResource/Country.php | 2 +- lib/ShopifyResource/GraphQL.php | 26 ++- lib/ShopifyResource/Transaction.php | 9 +- lib/ShopifyResource/UsageCharge.php | 9 +- lib/ShopifyResource/User.php | 23 +-- lib/ShopifyResource/Webhook.php | 9 +- lib/ShopifySDK.php | 166 ++++++++++--------- 22 files changed, 316 insertions(+), 658 deletions(-) delete mode 100644 lib/HttpRequestGraphQL.php diff --git a/composer.json b/composer.json index 6fdced1..564ef1e 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "homepage": "https://github.com/phpclassic/php-shopify", "type": "library", "require": { - "php": ">=5.6", + "php": ">=7.3", "ext-curl": "*", "ext-json": "*" }, diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index eb18f2b..bfb9253 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -1,9 +1,4 @@ - * Created at: 8/27/16 10:58 AM UTC+06:00 - */ namespace PHPShopify; @@ -11,51 +6,44 @@ class AuthHelper { - /** - * Get the url of the current page - * - * @return string - */ - public static function getCurrentUrl() + public static function getCurrentUrl(): string { - if (isset($_SERVER['HTTPS']) && - ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || - isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && - $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { + if ( + in_array($_SERVER['HTTPS'] ?? null, ['on', 1]) + && + ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? null) === 'https' + ) { $protocol = 'https'; - } - else { + } else { $protocol = 'http'; } - return "$protocol://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + return "{$protocol}://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; } /** * Build a query string from a data array + * Note: Strings should be URL encoded though? * This is a replacement for http_build_query because that returns an url-encoded string. - * - * @param array $data Data array - * - * @return array */ - public static function buildQueryString($data) + public static function buildQueryString(array $data): string { $paramStrings = []; + foreach ($data as $key => $value) { $paramStrings[] = "$key=$value"; } - return join('&', $paramStrings); + + return implode('&', $paramStrings); } /** * Verify if the request is made from shopify using hmac hash value * + * @inheritDoc * @throws SdkException if SharedSecret is not provided or hmac is not found in the url parameters - * - * @return bool */ - public static function verifyShopifyRequest() + public static function verifyShopifyRequest(): bool { $data = $_GET; @@ -65,46 +53,37 @@ public static function verifyShopifyRequest() $sharedSecret = ShopifySDK::$config['SharedSecret']; - //Get the hmac and remove it from array if (isset($data['hmac'])) { $hmac = $data['hmac']; unset($data['hmac']); } else { throw new SdkException("HMAC value not found in url parameters."); } - //signature validation is deprecated + + // signature validation is deprecated if (isset($data['signature'])) { unset($data['signature']); } - //Create data string for the remaining url parameters + $dataString = self::buildQueryString($data); $realHmac = hash_hmac('sha256', $dataString, $sharedSecret); - //hash the values before comparing (to prevent time attack) - if(md5($realHmac) === md5($hmac)) { - return true; - } else { - return false; - } + return md5($realHmac) === md5($hmac); } /** * Redirect the user to the authorization page to allow the app access to the shop * * @see https://help.shopify.com/api/guides/authentication/oauth#scopes For allowed scopes - * + * @inheritDoc * @param string|string[] $scopes Scopes required by app - * @param string $redirectUrl - * @param string $state * @param string[] $options - * @param bool $return If true, will return the authentical url instead of auto-redirecting to the page. * @throws SdkException if required configuration is not provided in $config - * - * @return void|string */ - public static function createAuthRequest($scopes, $redirectUrl = null, $state = null, $options = null, $return = false) + public static function createAuthRequest($scopes, ?string $redirectUrl = null, ?string $state = null, ?array $options = null, bool $return = false): ?string { + assert(is_string($scopes) || is_array($scopes)); $config = ShopifySDK::$config; if(!isset($config['ShopUrl']) || !isset($config['ApiKey'])) { @@ -127,49 +106,53 @@ public static function createAuthRequest($scopes, $redirectUrl = null, $state = if (is_array($scopes)) { $scopes = join(',', $scopes); } - if(!empty($state)) { + + if(!is_string($state)) { $state = '&state=' . $state; } - if(!empty($options)) { - $options = '&grant_options[]=' . join(',', $options); + + if(!is_array($options)) { + $options = '&grant_options[]=' . implode(',', $options); } + // Official call structure // https://{shop}.myshopify.com/admin/oauth/authorize?client_id={api_key}&scope={scopes}&redirect_uri={redirect_uri}&state={nonce}&grant_options[]={option} - $authUrl = $config['AdminUrl'] . 'oauth/authorize?client_id=' . $config['ApiKey'] . '&redirect_uri=' . $redirectUrl . "&scope=$scopes" . $state . $options; + $authUrl = "{$config['AdminUrl']}oauth/authorize?client_id={$config['ApiKey']}&redirect_uri={$redirectUrl}&scope={$scopes}{$state}{$options}"; if ($return) { return $authUrl; } header("Location: $authUrl"); + + return null; } /** * Get Access token for the API * Call this when being redirected from shopify page ( to the $redirectUrl) after authentication * + * @inheritDoc * @throws SdkException if SharedSecret or ApiKey is missing in SDK configuration or request is not valid - * - * @return string */ - public static function getAccessToken() + public static function getAccessToken(?array $config): string { - $config = ShopifySDK::$config; + $config = $config ?? ShopifySDK::$config; if(!isset($config['SharedSecret']) || !isset($config['ApiKey'])) { throw new SdkException("SharedSecret and ApiKey are required for getting access token. Please check SDK configuration!"); } if(self::verifyShopifyRequest()) { - $data = array( + $data = [ 'client_id' => $config['ApiKey'], 'client_secret' => $config['SharedSecret'], 'code' => $_GET['code'], - ); + ]; - $response = HttpRequestJson::post($config['AdminUrl'] . 'oauth/access_token', $data); + $response = HttpRequestJson::post("{$config['AdminUrl']}oauth/access_token", $data); - return isset($response['access_token']) ? $response['access_token'] : null; + return $response['access_token'] ?? null; } else { throw new SdkException("This request is not initiated from a valid shopify shop!"); } diff --git a/lib/CurlRequest.php b/lib/CurlRequest.php index dcb61d0..8ec6fdd 100644 --- a/lib/CurlRequest.php +++ b/lib/CurlRequest.php @@ -1,9 +1,4 @@ - * Created at 8/17/16 2:50 PM UTC+06:00 - */ namespace PHPShopify; @@ -13,137 +8,108 @@ class CurlRequest { /** - * HTTP Code of the last executed request - * - * @var integer + * The time wait before retrying when the request was rate limited in microseconds. */ - public static $lastHttpCode; + const RATE_LIMIT_RETRY_DELAY = 500000; /** - * HTTP response headers of last executed request - * - * @var array + * This allows use of keepalive. + * @var resource */ - public static $lastHttpResponseHeaders = array(); + private static $ch; /** - * Initialize the curl resource - * - * @param string $url - * @param array $httpHeaders - * + * @inheritDoc + * @param string|string[]|null $data * @return resource */ - protected static function init($url, $httpHeaders = array()) + protected static function init(string $method, string $url, array $httpHeaders = [], $data = null) { - // Create Curl resource - $ch = curl_init(); + if (self::$ch === null) { + self::$ch = curl_init(); - // Set URL - curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt(self::$ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt(self::$ch, CURLOPT_HEADER, true); + curl_setopt(self::$ch, CURLOPT_USERAGENT, 'PHPClassic/PHPShopify'); + } + + curl_setopt(self::$ch, CURLOPT_CUSTOMREQUEST, $method); + curl_setopt(self::$ch, CURLOPT_URL, $url); - //Return the transfer as a string - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if ($data !== null) { + $headers['Content-Length'] = strlen($data); + curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $data); + } else { + curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $data); + } - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_USERAGENT, 'PHPClassic/PHPShopify'); + $headers = []; - $headers = array(); foreach ($httpHeaders as $key => $value) { - $headers[] = "$key: $value"; + $headers[] = "{$key}: {$value}"; } - //Set HTTP Headers - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - return $ch; + curl_setopt(self::$ch, CURLOPT_HTTPHEADER, $headers); + return self::$ch; } - /** - * Implement a GET request and return output - * - * @param string $url - * @param array $httpHeaders - * - * @return CurlResponse - */ - public static function get($url, $httpHeaders = array()) + public static function destroy(): void { - $ch = self::init($url, $httpHeaders); - - return self::processRequest($ch); + if (self::$ch !== null) { + $ch = self::$ch; + self::$ch = null; + curl_close($ch); + } } - /** - * Implement a POST request and return output - * - * @param string $url - * @param array $data - * @param array $httpHeaders - * - * @return CurlResponse - */ - public static function post($url, $data, $httpHeaders = array()) + public static function get(string $url, array $httpHeaders = []): CurlResponse { - $ch = self::init($url, $httpHeaders); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); - - return self::processRequest($ch); + return self::processRequest(self::init('GET', $url, $httpHeaders)); } /** - * Implement a PUT request and return output - * - * @param string $url - * @param array $data - * @param array $httpHeaders - * - * @return CurlResponse + * @inheritDoc + * @param string|array $data */ - public static function put($url, $data, $httpHeaders = array()) + public static function post(string $url, $data, array $httpHeaders = []): CurlResponse { - $ch = self::init($url, $httpHeaders); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); - - return self::processRequest($ch); + return self::processRequest(self::init('POST', $url, $httpHeaders, $data)); } - /** - * Implement a DELETE request and return output - * - * @param string $url - * @param array $httpHeaders - * - * @return CurlResponse - */ - public static function delete($url, $httpHeaders = array()) + public static function put($url, $data, array $httpHeaders = []): CurlResponse { - $ch = self::init($url, $httpHeaders); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + return self::processRequest(self::init('PUT', $url, $httpHeaders, $data)); + } - return self::processRequest($ch); + public static function delete(string $url, array $httpHeaders = []): CurlResponse + { + return self::processRequest(self::init('DELETE', $url, $httpHeaders)); } /** - * Execute a request, release the resource and return output - * + * @inheritDoc * @param resource $ch - * * @throws CurlException if curl request is failed with error - * - * @return CurlResponse */ - protected static function processRequest($ch) + protected static function processRequest($ch): CurlResponse { # Check for 429 leaky bucket error - while (1) { - $output = curl_exec($ch); - $response = new CurlResponse($output); + while (true) { + $output = curl_exec($ch); - self::$lastHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if (self::$lastHttpCode != 429) { + if (curl_errno($ch)) { + throw new CurlException(curl_errno($ch) . ' : ' . curl_error($ch)); + } + + assert(is_string($output)); + + $parsedResponse = self::parseResponse($output); + // Note: Missing error handling here. + $status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); + $response = new CurlResponse($status, $parsedResponse['headers'], $parsedResponse['body']); + + if ($response->getStatus() != 429) { break; } @@ -153,16 +119,37 @@ protected static function processRequest($ch) throw new ResourceRateLimitException($response->getBody()); } - usleep(500000); + usleep(self::RATE_LIMIT_RETRY_DELAY); } - if (curl_errno($ch)) { - throw new Exception\CurlException(curl_errno($ch) . ' : ' . curl_error($ch)); + return $response; + } + + private static function parseResponse(string $response): array + { + $response = explode("\r\n\r\n", $response, 2); + $headers = []; + + assert(count($response) === 2); + [$headers, $body] = $response; + + foreach (explode("\r\n", $headers) as $header) { + $pair = explode(': ', $header, 2); + + if (isset($pair[1])) { + $headerKey = strtolower($pair[0]); + $headers[$headerKey] = $pair[1]; + } } - // close curl resource to free up system resources - curl_close($ch); + // Gimme yur body. + $body = self::parseBody($body); - return $response; + return compact('headers', 'body'); + } + + protected static function parseBody(string $body) + { + return $body; } } diff --git a/lib/CurlResponse.php b/lib/CurlResponse.php index 02a9eec..75c845e 100644 --- a/lib/CurlResponse.php +++ b/lib/CurlResponse.php @@ -4,64 +4,33 @@ class CurlResponse { + /** @var int */ + private $status; /** @var array */ private $headers = []; /** @var string */ private $body; - public function __construct($response) + public function __construct(int $status, array $headers, $body) { - $this->parse($response); - } - - /** - * @param string $response - */ - private function parse($response) - { - $response = \explode("\r\n\r\n", $response); - if (\count($response) > 1) { - // We want the last two parts - $response = \array_slice($response, -2, 2); - list($headers, $body) = $response; - foreach (\explode("\r\n", $headers) as $header) { - $pair = \explode(': ', $header, 2); - if (isset($pair[1])) { - $headerKey = strtolower($pair[0]); - $this->headers[$headerKey] = $pair[1]; - } - } - } else { - $body = $response[0]; - } - + $this->status = $status; + $this->headers = $headers; $this->body = $body; } - /** - * @return array - */ - public function getHeaders() + public function getHeader(string $key): ?string { - return $this->headers; + return $this->headers[$key] ?? null; } - /** - * @param string $key - * - * @return string - */ - public function getHeader($key) + public function getBody() { - return isset($this->headers[$key]) ? $this->headers[$key] : null; + return $this->body; } - /** - * @return string - */ - public function getBody() + public function getStatus(): int { - return $this->body; + return $this->status; } public function __toString() diff --git a/lib/HttpRequestGraphQL.php b/lib/HttpRequestGraphQL.php deleted file mode 100644 index ab437af..0000000 --- a/lib/HttpRequestGraphQL.php +++ /dev/null @@ -1,74 +0,0 @@ - $data, 'variables' => $variables]); - self::$httpHeaders['Content-type'] = 'application/json'; - } else { - self::$httpHeaders['Content-type'] = 'application/graphql'; - } - } - - /** - * Implement a POST request and return json decoded output - * - * @param string $url - * @param mixed $data - * @param array $httpHeaders - * @param array|null $variables - * - * @return string - */ - public static function post($url, $data, $httpHeaders = array(), $variables = null) - { - self::prepareRequest($httpHeaders, $data, $variables); - - $response = CurlRequest::post($url, self::$postDataGraphQL, self::$httpHeaders); - - return self::processResponse($response); - } -} \ No newline at end of file diff --git a/lib/HttpRequestJson.php b/lib/HttpRequestJson.php index ceab78f..6a39069 100644 --- a/lib/HttpRequestJson.php +++ b/lib/HttpRequestJson.php @@ -7,136 +7,21 @@ namespace PHPShopify; -/** - * Class HttpRequestJson - * - * Prepare the data / headers for JSON requests, make the call and decode the response - * Accepts data in array format returns data in array format - * - * @uses CurlRequest - * - * @package PHPShopify - */ -class HttpRequestJson +class HttpRequestJson extends CurlRequest { - - /** - * HTTP request headers - * - * @var array - */ - protected static $httpHeaders; - - /** - * Prepared JSON string to be posted with request - * - * @var string - */ - private static $postDataJSON; - - - /** - * Prepare the data and request headers before making the call - * - * @param array $httpHeaders - * @param array $dataArray - * - * @return void - */ - protected static function prepareRequest($httpHeaders = array(), $dataArray = array()) + protected static function init(string $method, string $url, array $httpHeaders = [], $data = null) { - - self::$postDataJSON = json_encode($dataArray); - - self::$httpHeaders = $httpHeaders; - - if (!empty($dataArray)) { - self::$httpHeaders['Content-type'] = 'application/json'; - self::$httpHeaders['Content-Length'] = strlen(self::$postDataJSON); + // Note: Is null valid for any shopify calls? + if ($data !== null) { + $httpHeaders['Content-type'] = 'application/json'; + $data = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } - } - - /** - * Implement a GET request and return json decoded output - * - * @param string $url - * @param array $httpHeaders - * - * @return array - */ - public static function get($url, $httpHeaders = array()) - { - self::prepareRequest($httpHeaders); - - $response = CurlRequest::get($url, self::$httpHeaders); - - return self::processResponse($response); - } - /** - * Implement a POST request and return json decoded output - * - * @param string $url - * @param array $dataArray - * @param array $httpHeaders - * - * @return array - */ - public static function post($url, $dataArray, $httpHeaders = array()) - { - self::prepareRequest($httpHeaders, $dataArray); - - $response = CurlRequest::post($url, self::$postDataJSON, self::$httpHeaders); - - return self::processResponse($response); + return parent::init($method, $url, $httpHeaders, $data); } - /** - * Implement a PUT request and return json decoded output - * - * @param string $url - * @param array $dataArray - * @param array $httpHeaders - * - * @return array - */ - public static function put($url, $dataArray, $httpHeaders = array()) + protected static function parseBody(string $body) { - self::prepareRequest($httpHeaders, $dataArray); - - $response = CurlRequest::put($url, self::$postDataJSON, self::$httpHeaders); - - return self::processResponse($response); + return json_decode($body, true); } - - /** - * Implement a DELETE request and return json decoded output - * - * @param string $url - * @param array $httpHeaders - * - * @return array - */ - public static function delete($url, $httpHeaders = array()) - { - self::prepareRequest($httpHeaders); - - $response = CurlRequest::delete($url, self::$httpHeaders); - - return self::processResponse($response); - } - - /** - * Decode JSON response - * - * @param string $response - * - * @return array - */ - protected static function processResponse($response) - { - - return json_decode($response, true); - } - } \ No newline at end of file diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index a321bcd..a9e41fa 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -1,9 +1,5 @@ - * Created at 8/17/16 3:14 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference Shopify API Reference */ @@ -12,7 +8,6 @@ use PHPShopify\Exception\ApiException; use PHPShopify\Exception\SdkException; use PHPShopify\Exception\CurlException; -use Psr\Http\Message\ResponseInterface; /* |-------------------------------------------------------------------------- @@ -29,14 +24,7 @@ abstract class ShopifyResource * * @var array */ - protected $httpHeaders = array(); - - /** - * HTTP response headers of last executed request - * - * @var array - */ - public static $lastHttpResponseHeaders = array(); + protected $httpHeaders = []; /** * The base URL of the API Resource (excluding the '.json' extension). @@ -62,7 +50,7 @@ abstract class ShopifyResource * * @var array */ - protected $childResource = array(); + protected $childResource = []; /** * If search is enabled for the resource @@ -99,10 +87,10 @@ abstract class ShopifyResource * @var array $customPutActions * @var array $customDeleteActions */ - protected $customGetActions = array(); - protected $customPostActions = array(); - protected $customPutActions = array(); - protected $customDeleteActions = array(); + protected $customGetActions = []; + protected $customPostActions = []; + protected $customPutActions = []; + protected $customDeleteActions = []; /** * The ID of the resource @@ -341,15 +329,27 @@ public function get($urlParams = array(), $url = null, $dataKey = null) return $this->processResponse($response, $dataKey); } - public function get($urlParams = array(), $url = null, $dataKey = null) + public function getPages($urlParams = array(), $url = null, $dataKey = null): \Generator { - if (!$url) $url = $this->generateUrl($urlParams); + if (!$url) { + $url = $this->generateUrl($urlParams); + } - $response = HttpRequestJson::get($url, $this->httpHeaders); + while ($url !== null) { + $response = HttpRequestJson::get($url, $this->httpHeaders); - if (!$dataKey) $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey(); + if ($response === null || !count($response)) { + break; + } - return $this->processResponse($response, $dataKey); + if (!$dataKey) { + $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey(); + } + + yield $this->processResponse($response, $dataKey); + + $url = self::getLinks($response)['next'] ?? null; + } } /** @@ -526,98 +526,54 @@ protected function castString($array) * * @return array */ - public function processResponse($responseArray, $dataKey = null) + public function processResponse(CurlResponse $response, $dataKey = null) { - self::$lastHttpResponseHeaders = CurlRequest::$lastHttpResponseHeaders; - - if ($responseArray === null) { - //Something went wrong, Checking HTTP Codes - $httpOK = 200; //Request Successful, OK. - $httpCreated = 201; //Create Successful. + $body = $response->getBody(); - //should be null if any other library used for http calls - $httpCode = CurlRequest::$lastHttpCode; + if ($body === null) { + $httpOK = 200; + $httpCreated = 201; + $httpCode = $response->getStatus(); - if ($httpCode != null && $httpCode != $httpOK && $httpCode != $httpCreated) { + if ($httpCode !== $httpOK && $httpCode !== $httpCreated) { throw new Exception\CurlException("Request failed with HTTP Code $httpCode."); } } - $lastResponseHeaders = CurlRequest::$lastHttpResponseHeaders; - $this->getLinks($lastResponseHeaders); + if (isset($body['errors'])) { + $message = $this->castString($body['errors']); - if (isset($responseArray['errors'])) { - $message = $this->castString($responseArray['errors']); - - throw new ApiException($message, CurlRequest::$lastHttpCode); + throw new ApiException($message, $response->getStatus()); } - if ($dataKey && isset($responseArray[$dataKey])) { - return $responseArray[$dataKey]; - } else { - return $responseArray; + if ($dataKey !== null && isset($body[$dataKey])) { + return $body[$dataKey]; } - } - public function getLinks($responseHeaders){ - $this->nextLink = $this->getLink($responseHeaders,'next'); - $this->prevLink = $this->getLink($responseHeaders,'previous'); + return $body; } - public function getLink($responseHeaders, $type='next'){ + private static function getLinks(CurlResponse $response): ?array + { + $linkHeader = $response->getHeader('link'); - if(array_key_exists('x-shopify-api-version', $responseHeaders) - && $responseHeaders['x-shopify-api-version'] < '2019-07'){ + if($linkHeader === null) { return null; } - if(!empty($responseHeaders['link'])) { - if (stristr($responseHeaders['link'], '; rel="'.$type.'"') > -1) { - $headerLinks = explode(',', $responseHeaders['link']); - foreach ($headerLinks as $headerLink) { - if (stristr($headerLink, '; rel="'.$type.'"') === -1) { - continue; - } - - $pattern = '#<(.*?)>; rel="'.$type.'"#m'; - preg_match($pattern, $headerLink, $linkResponseHeaders); - if ($linkResponseHeaders) { - return $linkResponseHeaders[1]; - } - } - } - } - - return null; - } - - public function getPrevLink(){ - return $this->prevLink; - } + $links = []; - public function getNextLink(){ - return $this->nextLink; - } + foreach (explode(', ', $linkHeader) as $headerLink) { + if (preg_match('/^<(.*?)>; rel="([^"]+)"/D', $headerLink, $matches)) { + $type = $matches[2]; + assert(in_array($type, ['next', 'previous'], true)); + assert(!array_key_exists($type, $links[$type])); + $links[$type] = $matches[1]; + } - public function getUrlParams($url) { - if ($url) { - $parts = parse_url($url); - return $parts['query']; + assert(false); } - return ''; - } - - public function getNextPageParams(){ - $nextPageParams = []; - $nextPageLink = - - parse_str($this->getUrlParams($this->getNextLink()), $nextPageParams); - return $nextPageParams; - } - public function getPrevPageParams(){ - $nextPageParams = []; - parse_str($this->getUrlParams($this->getPrevLink()), $nextPageParams); - return $nextPageParams; + return count($links) ? $links : null; } } diff --git a/lib/ShopifyResource/AbandonedCheckout.php b/lib/ShopifyResource/AbandonedCheckout.php index f40c6dc..55db528 100644 --- a/lib/ShopifyResource/AbandonedCheckout.php +++ b/lib/ShopifyResource/AbandonedCheckout.php @@ -13,8 +13,5 @@ class AbandonedCheckout extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'checkout'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/ApplicationCharge.php b/lib/ShopifyResource/ApplicationCharge.php index 7fc6695..da3af5a 100644 --- a/lib/ShopifyResource/ApplicationCharge.php +++ b/lib/ShopifyResource/ApplicationCharge.php @@ -13,18 +13,11 @@ class ApplicationCharge extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'application_charge'; - - /** - * @inheritDoc - */ public $countEnabled = false; // To activate ApplicationCharge - protected $customPostActions = array( + protected $customPostActions = [ 'activate', - ); + ]; } diff --git a/lib/ShopifyResource/Article.php b/lib/ShopifyResource/Article.php index b56b066..60d1648 100644 --- a/lib/ShopifyResource/Article.php +++ b/lib/ShopifyResource/Article.php @@ -20,20 +20,13 @@ * * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) - * */ class Article extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'article'; - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'Event', 'Metafield', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/Asset.php b/lib/ShopifyResource/Asset.php index 9189773..145da03 100644 --- a/lib/ShopifyResource/Asset.php +++ b/lib/ShopifyResource/Asset.php @@ -13,8 +13,5 @@ class Asset extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'asset'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Blog.php b/lib/ShopifyResource/Blog.php index a6b288e..38eb9b4 100644 --- a/lib/ShopifyResource/Blog.php +++ b/lib/ShopifyResource/Blog.php @@ -39,4 +39,4 @@ class Blog extends ShopifyResource 'Event', 'Metafield', ); -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/CarrierService.php b/lib/ShopifyResource/CarrierService.php index 0e0caa3..8134d31 100644 --- a/lib/ShopifyResource/CarrierService.php +++ b/lib/ShopifyResource/CarrierService.php @@ -22,4 +22,4 @@ class CarrierService extends ShopifyResource * @inheritDoc */ public $countEnabled = false; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Collect.php b/lib/ShopifyResource/Collect.php index 29c8865..38f0f6b 100644 --- a/lib/ShopifyResource/Collect.php +++ b/lib/ShopifyResource/Collect.php @@ -17,4 +17,4 @@ class Collect extends ShopifyResource * @inheritDoc */ protected $resourceKey = 'collect'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Comment.php b/lib/ShopifyResource/Comment.php index cff0fac..cb06346 100644 --- a/lib/ShopifyResource/Comment.php +++ b/lib/ShopifyResource/Comment.php @@ -54,4 +54,4 @@ class Comment extends ShopifyResource 'remove', 'restore', ); -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Country.php b/lib/ShopifyResource/Country.php index 1a42c45..2720c9f 100644 --- a/lib/ShopifyResource/Country.php +++ b/lib/ShopifyResource/Country.php @@ -41,4 +41,4 @@ protected function pluralizeKey() { return 'countries'; } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/GraphQL.php b/lib/ShopifyResource/GraphQL.php index 05acd50..36092c2 100644 --- a/lib/ShopifyResource/GraphQL.php +++ b/lib/ShopifyResource/GraphQL.php @@ -10,6 +10,7 @@ namespace PHPShopify\ShopifyResource; +use PHPShopify\HttpRequestJson; use PHPShopify\ShopifyResource; use PHPShopify\Exception\ApiException; use PHPShopify\Exception\CurlException; @@ -30,22 +31,33 @@ protected function getResourcePath() * * @param string $graphQL A valid GraphQL String. @see https://help.shopify.com/en/api/graphql-admin-api/graphiql-builder GraphiQL builder - you can build your graphql string from here. * @param string $url - * @param bool $wrapData * @param array|null $variables - * - * @uses HttpRequestGraphQL::post() to send the HTTP request * @throws ApiException if the response has an error specified * @throws CurlException if response received with unexpected HTTP code. * * @return array */ - public function post($graphQL, $url = null, $wrapData = false, $variables = null) + public function query(string $graphQL, ?string $url = null, ?array $variables = null) { - if (!$url) $url = $this->generateUrl(); + if ($url === null) { + $url = $this->generateUrl(); + } + + $httpHeaders = $this->httpHeaders; + + if (!isset($httpHeaders['X-Shopify-Access-Token'])) { + throw new SdkException("The GraphQL Admin API requires an access token for making authenticated requests!"); + } - $response = HttpRequestGraphQL::post($url, $graphQL, $this->httpHeaders, $variables); + if (is_array($variables)) { + $httpHeaders['Content-type'] = 'application/json'; + $data = json_encode(['query' => $graphQL, 'variables' => $variables]); + } else { + $httpHeaders['Content-type'] = 'application/graphql'; + $data = $graphQL; + } - return $this->processResponse($response); + return $this->processResponse(HttpRequestJson::post($url, $data, $this->httpHeaders)); } /** diff --git a/lib/ShopifyResource/Transaction.php b/lib/ShopifyResource/Transaction.php index 17aa3ce..afaef85 100644 --- a/lib/ShopifyResource/Transaction.php +++ b/lib/ShopifyResource/Transaction.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 7:27 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/transaction Shopify API Reference for Transaction */ @@ -13,8 +9,5 @@ class Transaction extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'transaction'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/UsageCharge.php b/lib/ShopifyResource/UsageCharge.php index 9a31fca..31b2900 100644 --- a/lib/ShopifyResource/UsageCharge.php +++ b/lib/ShopifyResource/UsageCharge.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 7:49 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/usagecharge Shopify API Reference for UsageCharge */ @@ -13,8 +9,5 @@ class UsageCharge extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'usage_charge'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/User.php b/lib/ShopifyResource/User.php index 3372f78..25e94b9 100644 --- a/lib/ShopifyResource/User.php +++ b/lib/ShopifyResource/User.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 8:00 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/user Shopify API Reference for User */ @@ -16,24 +12,13 @@ * User -> Custom actions * -------------------------------------------------------------------------- * @method array current() Get the current logged-in user - * */ class User extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'user'; - - /** - * @inheritDoc - */ public $readOnly = true; - /** - * @inheritDoc - */ - protected $customGetActions = array ( - 'current' - ); -} \ No newline at end of file + protected $customGetActions = [ + 'current', + ]; +} diff --git a/lib/ShopifyResource/Webhook.php b/lib/ShopifyResource/Webhook.php index dd75105..05c1ec6 100644 --- a/lib/ShopifyResource/Webhook.php +++ b/lib/ShopifyResource/Webhook.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 8:07 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/webhook Shopify API Reference for Webhook */ @@ -13,8 +9,5 @@ class Webhook extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'webhook'; -} \ No newline at end of file +} diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index ec58cae..8845268 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -1,9 +1,5 @@ - * Created at 8/16/16 10:42 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/ Shopify API Reference */ @@ -66,83 +62,83 @@ use PHPShopify\Exception\SdkException; /** - * @property-read AbandonedCheckout $AbandonedCheckout - * @property-read Blog $Blog - * @property-read CarrierService $CarrierService - * @property-read Collect $Collect - * @property-read Comment $Comment - * @property-read Country $Country - * @property-read Currency $Currency - * @property-read CustomCollection $CustomCollection - * @property-read Customer $Customer - * @property-read CustomerSavedSearch $CustomerSavedSearch - * @property-read Discount $Discount - * @property-read DiscountCode $DiscountCode - * @property-read DraftOrder $DraftOrder - * @property-read PriceRule $PriceRule - * @property-read Event $Event - * @property-read FulfillmentService $FulfillmentService - * @property-read GiftCard $GiftCard - * @property-read InventoryItem $InventoryItem - * @property-read InventoryLevel $InventoryLevel - * @property-read Location $Location - * @property-read Metafield $Metafield - * @property-read Multipass $Multipass - * @property-read Order $Order - * @property-read Page $Page - * @property-read Policy $Policy - * @property-read Product $Product - * @property-read ProductListing $ProductListing - * @property-read ProductVariant $ProductVariant - * @property-read RecurringApplicationCharge $RecurringApplicationCharge - * @property-read Redirect $Redirect - * @property-read ScriptTag $ScriptTag - * @property-read ShippingZone $ShippingZone - * @property-read Shop $Shop - * @property-read SmartCollection $SmartCollection - * @property-read Theme $Theme - * @property-read User $User - * @property-read Webhook $Webhook - * @property-read GraphQL $GraphQL + * @property-read ShopifyResource\AbandonedCheckout $AbandonedCheckout + * @property-read ShopifyResource\Blog $Blog + * @property-read ShopifyResource\CarrierService $CarrierService + * @property-read ShopifyResource\Collect $Collect + * @property-read ShopifyResource\Comment $Comment + * @property-read ShopifyResource\Country $Country + * @property-read ShopifyResource\Currency $Currency + * @property-read ShopifyResource\CustomCollection $CustomCollection + * @property-read ShopifyResource\Customer $Customer + * @property-read ShopifyResource\CustomerSavedSearch $CustomerSavedSearch + * @property-read ShopifyResource\Discount $Discount + * @property-read ShopifyResource\DiscountCode $DiscountCode + * @property-read ShopifyResource\DraftOrder $DraftOrder + * @property-read ShopifyResource\PriceRule $PriceRule + * @property-read ShopifyResource\Event $Event + * @property-read ShopifyResource\FulfillmentService $FulfillmentService + * @property-read ShopifyResource\GiftCard $GiftCard + * @property-read ShopifyResource\InventoryItem $InventoryItem + * @property-read ShopifyResource\InventoryLevel $InventoryLevel + * @property-read ShopifyResource\Location $Location + * @property-read ShopifyResource\Metafield $Metafield + * @property-read ShopifyResource\Multipass $Multipass + * @property-read ShopifyResource\Order $Order + * @property-read ShopifyResource\Page $Page + * @property-read ShopifyResource\Policy $Policy + * @property-read ShopifyResource\Product $Product + * @property-read ShopifyResource\ProductListing $ProductListing + * @property-read ShopifyResource\ProductVariant $ProductVariant + * @property-read ShopifyResource\RecurringApplicationCharge $RecurringApplicationCharge + * @property-read ShopifyResource\Redirect $Redirect + * @property-read ShopifyResource\ScriptTag $ScriptTag + * @property-read ShopifyResource\ShippingZone $ShippingZone + * @property-read ShopifyResource\Shop $Shop + * @property-read ShopifyResource\SmartCollection $SmartCollection + * @property-read ShopifyResource\Theme $Theme + * @property-read ShopifyResource\User $User + * @property-read ShopifyResource\Webhook $Webhook + * @property-read ShopifyResource\GraphQL $GraphQL * - * @method AbandonedCheckout AbandonedCheckout(integer $id = null) - * @method Blog Blog(integer $id = null) - * @method CarrierService CarrierService(integer $id = null) - * @method Collect Collect(integer $id = null) - * @method Comment Comment(integer $id = null) - * @method Country Country(integer $id = null) - * @method Currency Currency(integer $id = null) - * @method CustomCollection CustomCollection(integer $id = null) - * @method Customer Customer(integer $id = null) - * @method CustomerSavedSearch CustomerSavedSearch(integer $id = null) - * @method Discount Discount(integer $id = null) - * @method DraftOrder DraftOrder(integer $id = null) - * @method DiscountCode DiscountCode(integer $id = null) - * @method PriceRule PriceRule(integer $id = null) - * @method Event Event(integer $id = null) - * @method FulfillmentService FulfillmentService(integer $id = null) - * @method GiftCard GiftCard(integer $id = null) - * @method InventoryItem InventoryItem(integer $id = null) - * @method InventoryLevel InventoryLevel(integer $id = null) - * @method Location Location(integer $id = null) - * @method Metafield Metafield(integer $id = null) - * @method Multipass Multipass(integer $id = null) - * @method Order Order(integer $id = null) - * @method Page Page(integer $id = null) - * @method Policy Policy(integer $id = null) - * @method Product Product(integer $id = null) - * @method ProductListing ProductListing(integer $id = null) - * @method ProductVariant ProductVariant(integer $id = null) - * @method RecurringApplicationCharge RecurringApplicationCharge(integer $id = null) - * @method Redirect Redirect(integer $id = null) - * @method ScriptTag ScriptTag(integer $id = null) - * @method ShippingZone ShippingZone(integer $id = null) - * @method Shop Shop(integer $id = null) - * @method SmartCollection SmartCollection(integer $id = null) - * @method Theme Theme(int $id = null) - * @method User User(integer $id = null) - * @method Webhook Webhook(integer $id = null) - * @method GraphQL GraphQL() + * @method ShopifyResource\AbandonedCheckout AbandonedCheckout(integer $id = null) + * @method ShopifyResource\Blog Blog(integer $id = null) + * @method ShopifyResource\CarrierService CarrierService(integer $id = null) + * @method ShopifyResource\Collect Collect(integer $id = null) + * @method ShopifyResource\Comment Comment(integer $id = null) + * @method ShopifyResource\Country Country(integer $id = null) + * @method ShopifyResource\Currency Currency(integer $id = null) + * @method ShopifyResource\CustomCollection CustomCollection(integer $id = null) + * @method ShopifyResource\Customer Customer(integer $id = null) + * @method ShopifyResource\CustomerSavedSearch CustomerSavedSearch(integer $id = null) + * @method ShopifyResource\Discount Discount(integer $id = null) + * @method ShopifyResource\DraftOrder DraftOrder(integer $id = null) + * @method ShopifyResource\DiscountCode DiscountCode(integer $id = null) + * @method ShopifyResource\PriceRule PriceRule(integer $id = null) + * @method ShopifyResource\Event Event(integer $id = null) + * @method ShopifyResource\FulfillmentService FulfillmentService(integer $id = null) + * @method ShopifyResource\GiftCard GiftCard(integer $id = null) + * @method ShopifyResource\InventoryItem InventoryItem(integer $id = null) + * @method ShopifyResource\InventoryLevel InventoryLevel(integer $id = null) + * @method ShopifyResource\Location Location(integer $id = null) + * @method ShopifyResource\Metafield Metafield(integer $id = null) + * @method ShopifyResource\Multipass Multipass(integer $id = null) + * @method ShopifyResource\Order Order(integer $id = null) + * @method ShopifyResource\Page Page(integer $id = null) + * @method ShopifyResource\Policy Policy(integer $id = null) + * @method ShopifyResource\Product Product(integer $id = null) + * @method ShopifyResource\ProductListing ProductListing(integer $id = null) + * @method ShopifyResource\ProductVariant ProductVariant(integer $id = null) + * @method ShopifyResource\RecurringApplicationCharge RecurringApplicationCharge(integer $id = null) + * @method ShopifyResource\Redirect Redirect(integer $id = null) + * @method ShopifyResource\ScriptTag ScriptTag(integer $id = null) + * @method ShopifyResource\ShippingZone ShippingZone(integer $id = null) + * @method ShopifyResource\Shop Shop(integer $id = null) + * @method ShopifyResource\SmartCollection SmartCollection(integer $id = null) + * @method ShopifyResource\Theme Theme(int $id = null) + * @method ShopifyResource\User User(integer $id = null) + * @method ShopifyResource\Webhook Webhook(integer $id = null) + * @method ShopifyResource\GraphQL GraphQL() */ class ShopifySDK { @@ -151,7 +147,7 @@ class ShopifySDK * * @var string[] */ - protected $resources = array( + protected $resources = [ 'AbandonedCheckout', 'ApplicationCharge', 'Blog', @@ -192,7 +188,7 @@ class ShopifySDK 'User', 'Webhook', 'GraphQL' - ); + ]; /** * @var float microtime of last api call @@ -222,7 +218,7 @@ class ShopifySDK * * @var array Array key is the child resource name and array value is the parent resource name */ - protected $childResources = array( + protected $childResources = [ 'Article' => 'Blog', 'Asset' => 'Theme', 'CustomerAddress' => 'Customer', @@ -236,7 +232,7 @@ class ShopifySDK 'Refund' => 'Order', 'Transaction' => 'Order', 'UsageCharge' => 'RecurringApplicationCharge', - ); + ]; /* * ShopifySDK constructor @@ -245,7 +241,7 @@ class ShopifySDK * * @return void */ - public function __construct($config = array()) + public function __construct($config = []) { if(!empty($config)) { ShopifySDK::config($config); From a0f0cf9d10e28f0a5dbb32ee726935cc278f210d Mon Sep 17 00:00:00 2001 From: joeyhub Date: Fri, 6 Mar 2020 21:21:11 +0000 Subject: [PATCH 06/29] Clean up shop resources. --- lib/ShopifyResource/AbandonedCheckout.php | 4 -- lib/ShopifyResource/ApplicationCharge.php | 6 --- lib/ShopifyResource/Article.php | 9 ---- lib/ShopifyResource/Asset.php | 4 -- lib/ShopifyResource/Blog.php | 20 +------- lib/ShopifyResource/CarrierService.php | 11 ---- lib/ShopifyResource/Collect.php | 7 --- lib/ShopifyResource/Comment.php | 42 ++++------------ lib/ShopifyResource/Country.php | 18 +------ lib/ShopifyResource/Currency.php | 21 +------- lib/ShopifyResource/CustomCollection.php | 22 ++------ lib/ShopifyResource/Customer.php | 43 +++------------- lib/ShopifyResource/CustomerAddress.php | 33 +++--------- lib/ShopifyResource/CustomerSavedSearch.php | 25 ++-------- lib/ShopifyResource/Discount.php | 21 ++------ lib/ShopifyResource/DiscountCode.php | 22 ++------ lib/ShopifyResource/DraftOrder.php | 29 ++--------- lib/ShopifyResource/Event.php | 9 +--- lib/ShopifyResource/Fulfillment.php | 34 ++----------- lib/ShopifyResource/FulfillmentEvent.php | 16 +----- lib/ShopifyResource/FulfillmentService.php | 13 +---- lib/ShopifyResource/GiftCard.php | 27 ++-------- lib/ShopifyResource/GraphQL.php | 19 ++----- lib/ShopifyResource/InventoryItem.php | 4 -- lib/ShopifyResource/InventoryLevel.php | 8 --- lib/ShopifyResource/Location.php | 25 ++-------- lib/ShopifyResource/Metafield.php | 9 +--- lib/ShopifyResource/Multipass.php | 14 ++---- lib/ShopifyResource/Order.php | 40 +++------------ lib/ShopifyResource/OrderRisk.php | 9 +--- lib/ShopifyResource/Page.php | 22 ++------ lib/ShopifyResource/Policy.php | 20 +------- lib/ShopifyResource/PriceRule.php | 28 ++--------- lib/ShopifyResource/Product.php | 24 ++------- lib/ShopifyResource/ProductImage.php | 9 +--- lib/ShopifyResource/ProductListing.php | 17 ++----- lib/ShopifyResource/ProductVariant.php | 26 ++-------- lib/ShopifyResource/Province.php | 9 +--- .../RecurringApplicationCharge.php | 50 +++---------------- lib/ShopifyResource/Redirect.php | 9 +--- lib/ShopifyResource/Refund.php | 21 ++------ lib/ShopifyResource/Report.php | 9 +--- lib/ShopifyResource/ScriptTag.php | 9 +--- lib/ShopifyResource/ShippingZone.php | 17 +------ lib/ShopifyResource/Shop.php | 23 +-------- lib/ShopifyResource/SmartCollection.php | 32 ++---------- lib/ShopifyResource/Theme.php | 28 ++--------- lib/ShopifyResource/User.php | 6 +-- 48 files changed, 123 insertions(+), 800 deletions(-) diff --git a/lib/ShopifyResource/AbandonedCheckout.php b/lib/ShopifyResource/AbandonedCheckout.php index 55db528..f8908d4 100644 --- a/lib/ShopifyResource/AbandonedCheckout.php +++ b/lib/ShopifyResource/AbandonedCheckout.php @@ -1,9 +1,5 @@ - * Created at 8/18/16 9:50 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/abandoned_checkouts Shopify API Reference for Abandoned checkouts */ diff --git a/lib/ShopifyResource/ApplicationCharge.php b/lib/ShopifyResource/ApplicationCharge.php index da3af5a..786741e 100644 --- a/lib/ShopifyResource/ApplicationCharge.php +++ b/lib/ShopifyResource/ApplicationCharge.php @@ -1,9 +1,5 @@ - * Created at 8/18/16 9:50 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/applicationcharge Shopify API Reference for ApplicationCharge */ @@ -15,8 +11,6 @@ class ApplicationCharge extends ShopifyResource { protected $resourceKey = 'application_charge'; public $countEnabled = false; - - // To activate ApplicationCharge protected $customPostActions = [ 'activate', ]; diff --git a/lib/ShopifyResource/Article.php b/lib/ShopifyResource/Article.php index 60d1648..d127861 100644 --- a/lib/ShopifyResource/Article.php +++ b/lib/ShopifyResource/Article.php @@ -1,9 +1,5 @@ - * Created at 8/18/16 3:18 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/article Shopify API Reference for Article */ @@ -12,19 +8,14 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Article -> Child Resources - * -------------------------------------------------------------------------- * @property-read Event $Event * @property-read Metafield $Metafield - * * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) */ class Article extends ShopifyResource { protected $resourceKey = 'article'; - protected $childResource = [ 'Event', 'Metafield', diff --git a/lib/ShopifyResource/Asset.php b/lib/ShopifyResource/Asset.php index 145da03..a0e9776 100644 --- a/lib/ShopifyResource/Asset.php +++ b/lib/ShopifyResource/Asset.php @@ -1,9 +1,5 @@ - * Created at 8/18/16 3:39 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/asset Shopify API Reference for Asset */ diff --git a/lib/ShopifyResource/Blog.php b/lib/ShopifyResource/Blog.php index 38eb9b4..e55e2b5 100644 --- a/lib/ShopifyResource/Blog.php +++ b/lib/ShopifyResource/Blog.php @@ -1,9 +1,5 @@ - * Created at 8/18/16 10:46 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/blog Shopify API Reference for Blog */ @@ -12,31 +8,19 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Blog -> Child Resources - * -------------------------------------------------------------------------- * @property-read Article $Article * @property-read Event $Event * @property-read Metafield $Metafield - * * @method Article Article(integer $id = null) * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) - * */ class Blog extends ShopifyResource { - /** - * @inheritDoc - */ public $resourceKey = 'blog'; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'Article', 'Event', 'Metafield', - ); + ]; } diff --git a/lib/ShopifyResource/CarrierService.php b/lib/ShopifyResource/CarrierService.php index 8134d31..0e6951f 100644 --- a/lib/ShopifyResource/CarrierService.php +++ b/lib/ShopifyResource/CarrierService.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 10:49 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/carrierservice Shopify API Reference for CarrierService */ @@ -13,13 +9,6 @@ class CarrierService extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'carrier_service'; - - /** - * @inheritDoc - */ public $countEnabled = false; } diff --git a/lib/ShopifyResource/Collect.php b/lib/ShopifyResource/Collect.php index 38f0f6b..6b855b5 100644 --- a/lib/ShopifyResource/Collect.php +++ b/lib/ShopifyResource/Collect.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 10:54 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/collect Shopify API Reference for Collect */ @@ -13,8 +9,5 @@ class Collect extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'collect'; } diff --git a/lib/ShopifyResource/Comment.php b/lib/ShopifyResource/Comment.php index cb06346..c907c6a 100644 --- a/lib/ShopifyResource/Comment.php +++ b/lib/ShopifyResource/Comment.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 10:58 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/comment Shopify API Reference for Comment */ @@ -12,46 +8,26 @@ use PHPShopify\ShopifyResource; /** - * - * -------------------------------------------------------------------------- - * Comment -> Child Resources - * -------------------------------------------------------------------------- * @property-read Event $Event - * * @method Event Event(integer $id = null) - * - * -------------------------------------------------------------------------- - * Comment -> Custom actions - * -------------------------------------------------------------------------- - * @method array markSpam() Mark a Comment as spam - * @method array markNotSpam() Mark a Comment as not spam - * @method array approve() Approve a Comment - * @method array remove() Remove a Comment - * @method array restore() Restore a Comment - * + * @method array markSpam() Mark a Comment as spam + * @method array markNotSpam() Mark a Comment as not spam + * @method array approve() Approve a Comment + * @method array remove() Remove a Comment + * @method array restore() Restore a Comment */ class Comment extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'comment'; - - /** - * @inheritDoc - */ - protected $childResource = array ( + protected $childResource = [ 'Event', - ); + ]; - /** - * @inheritDoc - */ - protected $customPostActions = array( + protected $customPostActions = [ 'spam' => 'markSpam', 'not_spam' => 'markNotSpam', 'approve', 'remove', 'restore', - ); + ]; } diff --git a/lib/ShopifyResource/Country.php b/lib/ShopifyResource/Country.php index 2720c9f..ab77ff2 100644 --- a/lib/ShopifyResource/Country.php +++ b/lib/ShopifyResource/Country.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 11:44 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/country Shopify API Reference for Country */ @@ -22,21 +18,11 @@ */ class Country extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'country'; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'Province', - ); + ]; - /** - * @inheritDoc - */ protected function pluralizeKey() { return 'countries'; diff --git a/lib/ShopifyResource/Currency.php b/lib/ShopifyResource/Currency.php index ac84e8b..34e9eeb 100644 --- a/lib/ShopifyResource/Currency.php +++ b/lib/ShopifyResource/Currency.php @@ -1,10 +1,5 @@ - * Created at 8/19/16 11:46 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/customcollection Shopify API Reference for CustomCollection */ @@ -12,28 +8,16 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * CustomCollection -> Child Resources - * -------------------------------------------------------------------------- * @property-read Event $Event * @property-read Metafield $Metafield - * * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) - * */ class CustomCollection extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'custom_collection'; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'Event', 'Metafield', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/Customer.php b/lib/ShopifyResource/Customer.php index ee203f1..5582fd8 100644 --- a/lib/ShopifyResource/Customer.php +++ b/lib/ShopifyResource/Customer.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 11:47 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/customer Shopify API Reference for Customer */ @@ -12,53 +8,28 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Customer -> Child Resources - * -------------------------------------------------------------------------- * @property-read CustomerAddress $Address * @property-read Metafield $Metafield - * * @method CustomerAddress Address(integer $id = null) * @method Metafield Metafield(integer $id = null) - * -------------------------------------------------------------------------- - * Customer -> Custom actions - * -------------------------------------------------------------------------- - * @method array search() Search for customers matching supplied query + * @method array search() Search for customers matching supplied query */ class Customer extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey ='customer'; - - /** - * @inheritDoc - */ public $searchEnabled = true; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'CustomerAddress' => 'Address', 'Metafield', - 'Order' - ); + 'Order', + ]; - /** - * Sends an account invite to a customer. - * - * @param array $customer_invite Customized invite data - * - * @return array - */ - public function send_invite($customer_invite = array()) + public function send_invite(array $customer_invite = []): array { if (empty ( $customer_invite ) ) $customer_invite = new \stdClass(); - $url = $this->generateUrl(array(), 'send_invite'); + $url = $this->generateUrl([], 'send_invite'); $dataArray = $this->wrapData($customer_invite, 'customer_invite'); return $this->post($dataArray, $url, false); } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/CustomerAddress.php b/lib/ShopifyResource/CustomerAddress.php index e4016c3..6ac816d 100644 --- a/lib/ShopifyResource/CustomerAddress.php +++ b/lib/ShopifyResource/CustomerAddress.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 12:07 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/customeraddress Shopify API Reference for CustomerAddress */ @@ -12,47 +8,30 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * CustomerAddress -> Custom actions - * -------------------------------------------------------------------------- * @method array makeDefault() Sets the address as default for the customer - * */ class CustomerAddress extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'address'; - - /** - * @inheritDoc - */ - protected $customPutActions = array( + protected $customPutActions = [ 'default' => 'makeDefault', - ); + ]; - /** - * @inheritDoc - */ protected function pluralizeKey() { return 'addresses'; } - /** * Perform bulk operations against a number of addresses - * + * Issue (Getting Error from API) : Internal server error * @param array $params - * * @return array */ - //TODO Issue (Getting Error from API) : Internal server error - public function set($params) + public function set(array $params): array { $url = $this->generateUrl($params, 'set'); - return $this->put(array(), $url); + return $this->put([], $url); } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/CustomerSavedSearch.php b/lib/ShopifyResource/CustomerSavedSearch.php index 5769128..1a84e40 100644 --- a/lib/ShopifyResource/CustomerSavedSearch.php +++ b/lib/ShopifyResource/CustomerSavedSearch.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 2:07 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/customersavedsearch Shopify API Reference for CustomerSavedSearch */ @@ -12,33 +8,18 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * CustomerSavedSearch -> Child Resources - * -------------------------------------------------------------------------- * @property-read Customer $Customer - * * @method Customer Customer(integer $id = null) - * */ class CustomerSavedSearch extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'customer_saved_search'; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'Customer', - ); + ]; - /** - * @inheritDoc - */ protected function pluralizeKey() { return 'customer_saved_searches'; } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Discount.php b/lib/ShopifyResource/Discount.php index 69b659e..d5c13ba 100644 --- a/lib/ShopifyResource/Discount.php +++ b/lib/ShopifyResource/Discount.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 2:28 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/discount Shopify API Reference for Discount */ @@ -12,25 +8,14 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Discount -> Custom actions - * -------------------------------------------------------------------------- * @method array enable() Enable a discount * @method array disable() Disable a discount - * */ class Discount extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'discount'; - - /** - * @inheritDoc - */ - protected $customPostActions = array( + protected $customPostActions = [ 'enable', 'disable', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/DiscountCode.php b/lib/ShopifyResource/DiscountCode.php index c42538b..6fb022a 100644 --- a/lib/ShopifyResource/DiscountCode.php +++ b/lib/ShopifyResource/DiscountCode.php @@ -1,9 +1,5 @@ - * Created at 5/06/19 2:09 AM UTC+03:00 - * * @see https://help.shopify.com/api/reference/discounts/discountcode Shopify API Reference for PriceRule */ @@ -12,24 +8,12 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * DiscountCode -> Custom actions - * -------------------------------------------------------------------------- * @method array lookup() Retrieves the location of a discount code. - * */ - class DiscountCode extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'discount_code'; - - /** - * @inheritDoc - */ - protected $customGetActions = array( + protected $customGetActions = [ 'lookup', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/DraftOrder.php b/lib/ShopifyResource/DraftOrder.php index 1b3f66d..4e2f777 100644 --- a/lib/ShopifyResource/DraftOrder.php +++ b/lib/ShopifyResource/DraftOrder.php @@ -1,9 +1,5 @@ - * Created at 8/14/19 18:28 PM UTC+02:00 - * * @see https://help.shopify.com/api/reference/draftorder Shopify API Reference for DraftOrder */ @@ -12,31 +8,16 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * DraftOrder -> Custom actions - * -------------------------------------------------------------------------- * @method array send_invoice() Send the invoice for a DraftOrder * @method array complete() Complete a DraftOrder - * */ class DraftOrder extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'draft_order'; - - /** - * @inheritDoc - */ - protected $customPostActions = array( + protected $customPostActions = [ 'send_invoice', - ); - - /** - * @inheritDoc - */ - protected $customPutActions = array( + ]; + protected $customPutActions = [ 'complete', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/Event.php b/lib/ShopifyResource/Event.php index 619bd46..c42bec9 100644 --- a/lib/ShopifyResource/Event.php +++ b/lib/ShopifyResource/Event.php @@ -1,9 +1,5 @@ - * Created at: 8/21/16 8:39 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/event/ Shopify API Reference for Event */ @@ -13,8 +9,5 @@ class Event extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'event'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Fulfillment.php b/lib/ShopifyResource/Fulfillment.php index 1fe9037..27b5ca1 100644 --- a/lib/ShopifyResource/Fulfillment.php +++ b/lib/ShopifyResource/Fulfillment.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 3:04 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/fulfillment Shopify API Reference for Fulfillment */ @@ -12,41 +8,21 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Fulfillment -> Child Resources - * -------------------------------------------------------------------------- * @property-read Event $Event - * * @method Event Event(integer $id = null) - * - * -------------------------------------------------------------------------- - * Fulfillment -> Custom actions - * -------------------------------------------------------------------------- * @method array complete() Complete a fulfillment * @method array open() Open a pending fulfillment * @method array cancel() Cancel a fulfillment - * */ class Fulfillment extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'fulfillment'; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'FulfillmentEvent' => 'Event', - ); - - /** - * @inheritDoc - */ - protected $customPostActions = array( + ]; + protected $customPostActions = [ 'complete', 'open', 'cancel', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/FulfillmentEvent.php b/lib/ShopifyResource/FulfillmentEvent.php index bdc4e8d..2a5a325 100644 --- a/lib/ShopifyResource/FulfillmentEvent.php +++ b/lib/ShopifyResource/FulfillmentEvent.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 4:49 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/fulfillmentevent Shopify API Reference for FulfillmentEvent */ @@ -13,24 +9,14 @@ class FulfillmentEvent extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'fulfillment_event'; - - /** - * @inheritDoc - */ public function getResourcePath() { return 'events'; } - /** - * @inheritDoc - */ public function getResourcePostKey() { return 'event'; } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/FulfillmentService.php b/lib/ShopifyResource/FulfillmentService.php index b6cb8f5..4a47251 100644 --- a/lib/ShopifyResource/FulfillmentService.php +++ b/lib/ShopifyResource/FulfillmentService.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 5:28 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/fulfillmentservice Shopify API Reference for FulfillmentService */ @@ -13,13 +9,6 @@ class FulfillmentService extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'fulfillment_service'; - - /** - * @inheritDoc - */ public $countEnabled = false; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/GiftCard.php b/lib/ShopifyResource/GiftCard.php index 3491d42..f65475c 100644 --- a/lib/ShopifyResource/GiftCard.php +++ b/lib/ShopifyResource/GiftCard.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 5:35 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/gift_card Shopify API Reference for GiftCard */ @@ -12,38 +8,25 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * GiftCard -> Custom actions - * -------------------------------------------------------------------------- * @method array search() Search for gift cards matching supplied query - * */ class GiftCard extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'gift_card'; - - /** - * @inheritDoc - */ public $searchEnabled = true; /** * Disable a gift card. * Disabling a gift card is permanent and cannot be undone. - * - * @return array */ - public function disable() + public function disable(): array { - $url = $this->generateUrl(array(), 'disable'); + $url = $this->generateUrl([], 'disable'); - $dataArray = array( + $dataArray = [ 'id' => $this->id, - ); + ]; return $this->post($dataArray, $url); } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/GraphQL.php b/lib/ShopifyResource/GraphQL.php index 36092c2..97cd869 100644 --- a/lib/ShopifyResource/GraphQL.php +++ b/lib/ShopifyResource/GraphQL.php @@ -1,10 +1,5 @@ generateUrl(); @@ -64,7 +55,7 @@ public function query(string $graphQL, ?string $url = null, ?array $variables = * @inheritdoc * @throws SdkException */ - public function get($urlParams = array(), $url = null, $dataKey = null) + public function get($urlParams = [], $url = null, $dataKey = null) { throw new SdkException("Only POST method is allowed for GraphQL!"); } @@ -82,8 +73,8 @@ public function put($dataArray, $url = null, $wrapData = true) * @inheritdoc * @throws SdkException */ - public function delete($urlParams = array(), $url = null) + public function delete($urlParams = [], $url = null) { throw new SdkException("Only POST method is allowed for GraphQL!"); } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/InventoryItem.php b/lib/ShopifyResource/InventoryItem.php index 414293f..4ade82a 100644 --- a/lib/ShopifyResource/InventoryItem.php +++ b/lib/ShopifyResource/InventoryItem.php @@ -1,8 +1,5 @@ - * Created at 04/15/18 02:25 PM UTC+03:00 - * * @see https://help.shopify.com/api/reference/inventoryitem */ @@ -12,6 +9,5 @@ class InventoryItem extends ShopifyResource { - /** @inheritDoc */ protected $resourceKey = 'inventory_item'; } diff --git a/lib/ShopifyResource/InventoryLevel.php b/lib/ShopifyResource/InventoryLevel.php index 537eec8..bd03c2c 100644 --- a/lib/ShopifyResource/InventoryLevel.php +++ b/lib/ShopifyResource/InventoryLevel.php @@ -1,8 +1,5 @@ - * Created at 04/15/18 02:31 PM UTC+03:00 - * * @see https://help.shopify.com/api/reference/inventorylevel */ @@ -11,18 +8,13 @@ use PHPShopify\ShopifyResource; /** - * Class InventoryLevel - * * @method array adjust($data) Adjust inventory level. * @method array connect($data) Connect an inventory item to a location. * @method array set($data) Sets an inventory level for a single inventory item within a location. */ class InventoryLevel extends ShopifyResource { - /** @inheritDoc */ protected $resourceKey = 'inventory_level'; - - /** @inheritDoc */ protected $customPostActions = [ 'adjust', 'connect', diff --git a/lib/ShopifyResource/Location.php b/lib/ShopifyResource/Location.php index 69606c1..bae5b88 100644 --- a/lib/ShopifyResource/Location.php +++ b/lib/ShopifyResource/Location.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 5:47 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/location Shopify API Reference for Location */ @@ -13,25 +9,10 @@ class Location extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'location'; - - /** - * @inheritDoc - */ public $countEnabled = false; - - /** - * @inheritDoc - */ public $readOnly = true; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'InventoryLevel', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/Metafield.php b/lib/ShopifyResource/Metafield.php index 998f39e..b1671a2 100644 --- a/lib/ShopifyResource/Metafield.php +++ b/lib/ShopifyResource/Metafield.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 5:51 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/metafield Shopify API Reference for Metafield */ @@ -13,8 +9,5 @@ class Metafield extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'metafield'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Multipass.php b/lib/ShopifyResource/Multipass.php index b21d913..454bc1e 100644 --- a/lib/ShopifyResource/Multipass.php +++ b/lib/ShopifyResource/Multipass.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 6:05 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/multipass Shopify API Reference for Multipass */ @@ -14,16 +10,12 @@ class Multipass extends ShopifyResource { - /** - * Multipass constructor. - * - * @param integer $id - * + * @inheritDoc * @throws ApiException */ - public function __construct($id = null) + public function __construct(int $id = null) { throw new ApiException("Multipass API is not available yet!"); } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Order.php b/lib/ShopifyResource/Order.php index bea2b53..b56905b 100644 --- a/lib/ShopifyResource/Order.php +++ b/lib/ShopifyResource/Order.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 2:59 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/order Shopify API Reference for Order */ @@ -12,56 +8,36 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Order -> Child Resources - * -------------------------------------------------------------------------- * @property-read Fulfillment $Fulfillment * @property-read OrderRisk $Risk * @property-read Refund $Refund * @property-read Transaction $Transaction * @property-read Event $Event * @property-read Metafield $Metafield - * * @method Fulfillment Fulfillment(integer $id = null) * @method OrderRisk Risk(integer $id = null) * @method Refund Refund(integer $id = null) * @method Transaction Transaction(integer $id = null) * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) - * - * -------------------------------------------------------------------------- - * Order -> Custom actions - * -------------------------------------------------------------------------- - * @method array close() Close an Order - * @method array open() Re-open a closed Order - * @method array cancel(array $data) Cancel an Order - * + * @method array close() + * @method array open() + * @method array cancel(array $data) */ class Order extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'order'; - - /** - * @inheritDoc - */ - protected $childResource = array ( + protected $childResource = [ 'Fulfillment', 'OrderRisk' => 'Risk', 'Refund', 'Transaction', 'Event', 'Metafield', - ); - - /** - * @inheritDoc - */ - protected $customPostActions = array( + ]; + protected $customPostActions = [ 'close', 'open', 'cancel', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/OrderRisk.php b/lib/ShopifyResource/OrderRisk.php index 281a96d..d287c42 100644 --- a/lib/ShopifyResource/OrderRisk.php +++ b/lib/ShopifyResource/OrderRisk.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 6:10 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/order_risks Shopify API Reference for Order Risks */ @@ -13,8 +9,5 @@ class OrderRisk extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'risk'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Page.php b/lib/ShopifyResource/Page.php index 2d2e466..c7c5026 100644 --- a/lib/ShopifyResource/Page.php +++ b/lib/ShopifyResource/Page.php @@ -1,9 +1,5 @@ - * Created at 8/17/16 10:39 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/page Shopify API Reference for Page */ @@ -12,28 +8,16 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Page -> Child Resources - * -------------------------------------------------------------------------- * @property-read Event $Event * @property-read Metafield $Metafield - * * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) - * */ class Page extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'page'; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'Event', 'Metafield', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/Policy.php b/lib/ShopifyResource/Policy.php index a43bfda..655cdf3 100644 --- a/lib/ShopifyResource/Policy.php +++ b/lib/ShopifyResource/Policy.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 6:22 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/policy Shopify API Reference for Policy */ @@ -13,26 +9,12 @@ class Policy extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'policy'; - - /** - * @inheritDoc - */ public $countEnabled = false; - - /** - * @inheritDoc - */ public $readOnly = true; - /** - * @inheritDoc - */ public function pluralizeKey() { return 'policies'; } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/PriceRule.php b/lib/ShopifyResource/PriceRule.php index 0101864..e39def9 100644 --- a/lib/ShopifyResource/PriceRule.php +++ b/lib/ShopifyResource/PriceRule.php @@ -1,9 +1,5 @@ - * Created at 5/06/19 2:06 AM UTC+03:00 - * * @see https://help.shopify.com/api/reference/discounts/pricerule Shopify API Reference for PriceRule */ @@ -12,30 +8,14 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * PriceRule -> Child Resources - * -------------------------------------------------------------------------- * @property-read ShopifyResource $DiscountCode - * * @method ShopifyResource DiscountCode(integer $id = null) - * */ class PriceRule extends ShopifyResource { - /** - * @inheritDoc - */ public $resourceKey = 'price_rule'; - - /** - * @inheritDoc - */ public $countEnabled = false; - - /** - * @inheritDoc - */ - protected $childResource = array( - 'DiscountCode' - ); -} \ No newline at end of file + protected $childResource = [ + 'DiscountCode', + ]; +} diff --git a/lib/ShopifyResource/Product.php b/lib/ShopifyResource/Product.php index 371c7c6..afb0415 100644 --- a/lib/ShopifyResource/Product.php +++ b/lib/ShopifyResource/Product.php @@ -1,9 +1,5 @@ - * Created at 8/18/16 10:46 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/product Shopify API Reference for Product */ @@ -12,34 +8,22 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Product -> Child Resources - * -------------------------------------------------------------------------- * @property-read ProductImage $Image * @property-read ProductVariant $Variant * @property-read Metafield $Metafield * @property-read Event $Event - * * @method ProductImage Image(integer $id = null) * @method ProductVariant Variant(integer $id = null) * @method Metafield Metafield(integer $id = null) * @method Event Event(integer $id = null) - * */ class Product extends ShopifyResource { - /** - * @inheritDoc - */ public $resourceKey = 'product'; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'ProductImage' => 'Image', 'ProductVariant' => 'Variant', 'Metafield', - 'Event' - ); -} \ No newline at end of file + 'Event', + ]; +} diff --git a/lib/ShopifyResource/ProductImage.php b/lib/ShopifyResource/ProductImage.php index dd6d9bc..07a6fdf 100644 --- a/lib/ShopifyResource/ProductImage.php +++ b/lib/ShopifyResource/ProductImage.php @@ -1,9 +1,5 @@ - * Created at 8/18/16 1:35 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/product_image Shopify API Reference for Product Image */ @@ -13,8 +9,5 @@ class ProductImage extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'image'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/ProductListing.php b/lib/ShopifyResource/ProductListing.php index 399ea3a..5cf08ad 100644 --- a/lib/ShopifyResource/ProductListing.php +++ b/lib/ShopifyResource/ProductListing.php @@ -1,9 +1,5 @@ - * Created at: 6/2/18 1:38 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/sales_channels/productlisting Shopify API Reference for Shipping Zone */ @@ -13,15 +9,8 @@ class ProductListing extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'product_listing'; - - /** - * @inheritDoc - */ - protected $customGetActions = array ( + protected $customGetActions = [ 'product_ids' => 'productIds', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/ProductVariant.php b/lib/ShopifyResource/ProductVariant.php index e19256b..e639d8a 100644 --- a/lib/ShopifyResource/ProductVariant.php +++ b/lib/ShopifyResource/ProductVariant.php @@ -1,9 +1,5 @@ - * Created at 8/18/16 1:50 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/product_variant Shopify API Reference for Product Variant */ @@ -13,30 +9,14 @@ /** - * -------------------------------------------------------------------------- - * ProductVariant -> Child Resources - * -------------------------------------------------------------------------- * @property-read Metafield $Metafield - * * @method Metafield Metafield(integer $id = null) - * */ class ProductVariant extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'variant'; - - /** - * @inheritDoc - */ public $searchEnabled = true; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'Metafield', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/Province.php b/lib/ShopifyResource/Province.php index d0e3588..66e198b 100644 --- a/lib/ShopifyResource/Province.php +++ b/lib/ShopifyResource/Province.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 6:25 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/province Shopify API Reference for Province */ @@ -13,8 +9,5 @@ class Province extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'province'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/RecurringApplicationCharge.php b/lib/ShopifyResource/RecurringApplicationCharge.php index b581078..26656c8 100644 --- a/lib/ShopifyResource/RecurringApplicationCharge.php +++ b/lib/ShopifyResource/RecurringApplicationCharge.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 6:30 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/recurringapplicationcharge Shopify API Reference for RecurringApplicationCharge */ @@ -12,59 +8,27 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * RecurringApplicationCharge -> Child Resources - * -------------------------------------------------------------------------- * @property-read UsageCharge $UsageCharge - * * @method UsageCharge UsageCharge(integer $id = null) - * - * -------------------------------------------------------------------------- - * RecurringApplicationCharge -> Custom actions - * -------------------------------------------------------------------------- * @method array activate() Activate a recurring application charge - * */ class RecurringApplicationCharge extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'recurring_application_charge'; - - /** - * @inheritDoc - */ public $countEnabled = false; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'UsageCharge', - ); - - /** - * @inheritDoc - */ - protected $customPostActions = array( + ]; + protected $customPostActions = [ 'activate', - ); + ]; - /* - * Customize a recurring application charge - * - * @param array $data - * - * @return array - * - */ - public function customize($dataArray) + public function customize(array $dataArray): array { $dataArray = $this->wrapData($dataArray); $url = $this->generateUrl($dataArray, 'customize'); - return $this->put(array(), $url); + return $this->put([], $url); } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Redirect.php b/lib/ShopifyResource/Redirect.php index aac26d5..1461b3d 100644 --- a/lib/ShopifyResource/Redirect.php +++ b/lib/ShopifyResource/Redirect.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 7:13 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/redirect Shopify API Reference for Redirect */ @@ -13,8 +9,5 @@ class Redirect extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'redirect'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Refund.php b/lib/ShopifyResource/Refund.php index 00dd11b..bfe1c40 100644 --- a/lib/ShopifyResource/Refund.php +++ b/lib/ShopifyResource/Refund.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 7:19 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/refund Shopify API Reference for Refund */ @@ -12,23 +8,12 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Refund -> Custom actions - * -------------------------------------------------------------------------- * @method array calculate() Calculate a Refund. - * */ class Refund extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'refund'; - - /** - * @inheritDoc - */ - protected $customPostActions = array ( + protected $customPostActions = [ 'calculate', - ); -} \ No newline at end of file + ]; +} diff --git a/lib/ShopifyResource/Report.php b/lib/ShopifyResource/Report.php index 8e34ff3..216ddd3 100644 --- a/lib/ShopifyResource/Report.php +++ b/lib/ShopifyResource/Report.php @@ -6,13 +6,6 @@ class Report extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'report'; - - /** - * @inheritDoc - */ public $countEnabled = false; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/ScriptTag.php b/lib/ShopifyResource/ScriptTag.php index 69eea05..09cccc2 100644 --- a/lib/ShopifyResource/ScriptTag.php +++ b/lib/ShopifyResource/ScriptTag.php @@ -1,9 +1,5 @@ - * Created at 8/17/16 4:46 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/scripttag Shopify API Reference for ScriptTag */ @@ -13,8 +9,5 @@ class ScriptTag extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'script_tag'; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/ShippingZone.php b/lib/ShopifyResource/ShippingZone.php index 19b6265..c80a10b 100644 --- a/lib/ShopifyResource/ShippingZone.php +++ b/lib/ShopifyResource/ShippingZone.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 7:36 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/shipping_zone Shopify API Reference for Shipping Zone */ @@ -13,18 +9,7 @@ class ShippingZone extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'shipping_zone'; - - /** - * @inheritDoc - */ public $countEnabled = false; - - /** - * @inheritDoc - */ public $readOnly = true; -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/Shop.php b/lib/ShopifyResource/Shop.php index e60fd5a..81d430b 100644 --- a/lib/ShopifyResource/Shop.php +++ b/lib/ShopifyResource/Shop.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 10:42 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/shop Shopify API Reference for Shop */ @@ -13,27 +9,12 @@ class Shop extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'shop'; - - /** - * @inheritDoc - */ public $countEnabled = false; - - /** - * @inheritDoc - */ public $readOnly = true; - /** - * @inheritDoc - */ - public function pluralizeKey() + public function pluralizeKey(): string { - //Only one shop object for each store. So no pluralize return 'shop'; } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource/SmartCollection.php b/lib/ShopifyResource/SmartCollection.php index b864d70..53e4b4b 100644 --- a/lib/ShopifyResource/SmartCollection.php +++ b/lib/ShopifyResource/SmartCollection.php @@ -1,9 +1,5 @@ - * Created at 8/19/16 7:40 PM UTC+06:00 - * * @see https://help.shopify.com/api/reference/smartcollection Shopify API Reference for SmartCollection */ @@ -12,44 +8,24 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * SmartCollection -> Child Resources - * -------------------------------------------------------------------------- * @property-read Event $Event - * * @method Event Event(integer $id = null) - * - * -------------------------------------------------------------------------- - * SmartCollection -> Custom actions - * -------------------------------------------------------------------------- - * */ class SmartCollection extends ShopifyResource { - /** - * @inheritDoc - */ protected $resourceKey = 'smart_collection'; - - /** - * @inheritDoc - */ - protected $childResource = array( + protected $childResource = [ 'Event', 'Metafield', - ); + ]; /** * Set the ordering type and/or the manual order of products in a smart collection - * - * @param array $params - * - * @return array */ - public function sortOrder($params) + public function sortOrder(array $params): array { $url = $this->generateUrl($params, 'order'); - return $this->put(array(), $url); + return $this->put([], $url); } } diff --git a/lib/ShopifyResource/Theme.php b/lib/ShopifyResource/Theme.php index 0bfe8f5..b95c913 100644 --- a/lib/ShopifyResource/Theme.php +++ b/lib/ShopifyResource/Theme.php @@ -1,9 +1,5 @@ - * Created at 8/18/16 10:46 AM UTC+06:00 - * * @see https://help.shopify.com/api/reference/theme Shopify API Reference for Theme */ @@ -12,30 +8,14 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Theme -> Child Resources - * -------------------------------------------------------------------------- * @property-read Asset $Asset - * * @method Asset Asset(integer $id = null) - * */ class Theme extends ShopifyResource { - /** - * @inheritDoc - */ public $resourceKey = 'theme'; - - /** - * @inheritDoc - */ public $countEnabled = false; - - /** - * @inheritDoc - */ - protected $childResource = array( - 'Asset' - ); -} \ No newline at end of file + protected $childResource = [ + 'Asset', + ]; +} diff --git a/lib/ShopifyResource/User.php b/lib/ShopifyResource/User.php index 25e94b9..bc316d4 100644 --- a/lib/ShopifyResource/User.php +++ b/lib/ShopifyResource/User.php @@ -8,16 +8,12 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * User -> Custom actions - * -------------------------------------------------------------------------- - * @method array current() Get the current logged-in user + * @method array current() Get the current logged-in user */ class User extends ShopifyResource { protected $resourceKey = 'user'; public $readOnly = true; - protected $customGetActions = [ 'current', ]; From 2840dc7b9625524954ce8cb91d975a415aec6192 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Fri, 6 Mar 2020 21:29:17 +0000 Subject: [PATCH 07/29] Move http libraries into own folder. Simplify shopify SDK lib. --- lib/{ => Http}/CurlRequest.php | 0 lib/{ => Http}/CurlResponse.php | 0 lib/{ => Http}/HttpRequestJson.php | 0 lib/ShopifySDK.php | 66 ++++++++---------------------- 4 files changed, 17 insertions(+), 49 deletions(-) rename lib/{ => Http}/CurlRequest.php (100%) rename lib/{ => Http}/CurlResponse.php (100%) rename lib/{ => Http}/HttpRequestJson.php (100%) diff --git a/lib/CurlRequest.php b/lib/Http/CurlRequest.php similarity index 100% rename from lib/CurlRequest.php rename to lib/Http/CurlRequest.php diff --git a/lib/CurlResponse.php b/lib/Http/CurlResponse.php similarity index 100% rename from lib/CurlResponse.php rename to lib/Http/CurlResponse.php diff --git a/lib/HttpRequestJson.php b/lib/Http/HttpRequestJson.php similarity index 100% rename from lib/HttpRequestJson.php rename to lib/Http/HttpRequestJson.php diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 8845268..a2b7f36 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -207,11 +207,9 @@ class ShopifySDK /** * Shop / API configurations - * * @var array */ - public static $config = array( - ); + private $config = []; /** * List of resources which are only available through a parent resource @@ -241,11 +239,21 @@ class ShopifySDK * * @return void */ - public function __construct($config = []) + public function __construct(array $config = []) { - if(!empty($config)) { - ShopifySDK::config($config); + $this->config = $config + ['ApiVersion' => self::$defaultApiVersion]; + + //Re-set the admin url if shop url is changed + if(isset($config['ShopUrl'])) { + self::setAdminUrl(); + } + + //If want to keep more wait time than .5 seconds for each call + if (isset($config['AllowedTimePerCall'])) { + static::$timeAllowedForEachApiCall = $config['AllowedTimePerCall']; } + + return new ShopifySDK; } /** @@ -254,7 +262,6 @@ public function __construct($config = []) * Called like an object properties (without parenthesis) * * @param string $resourceName - * * @return ShopifyResource */ public function __get($resourceName) @@ -303,30 +310,9 @@ public function __call($resourceName, $arguments) * * @return ShopifySDK */ - public static function config($config) + private function config(array $config) { - /** - * Reset config to it's initial values - */ - self::$config = array( - 'ApiVersion' => self::$defaultApiVersion - ); - - foreach ($config as $key => $value) { - self::$config[$key] = $value; - } - - //Re-set the admin url if shop url is changed - if(isset($config['ShopUrl'])) { - self::setAdminUrl(); - } - //If want to keep more wait time than .5 seconds for each call - if (isset($config['AllowedTimePerCall'])) { - static::$timeAllowedForEachApiCall = $config['AllowedTimePerCall']; - } - - return new ShopifySDK; } /** @@ -356,34 +342,16 @@ public static function setAdminUrl() return $adminUrl; } - /** - * Get the admin url of the configured shop - * - * @return string - */ - public static function getAdminUrl() { - return self::$config['AdminUrl']; - } - - /** - * Get the api url of the configured shop - * - * @return string - */ - public static function getApiUrl() { - return self::$config['ApiUrl']; - } - /** * Maintain maximum 2 calls per second to the API * * @see https://help.shopify.com/api/guides/api-call-limit - * * @param bool $firstCallWait Whether to maintain the wait time even if it is the first API call */ - public static function checkApiCallLimit($firstCallWait = false) + public static function checkApiCallLimit($firstCallWait = false): void { $timeToWait = 0; + if (static::$microtimeOfLastApiCall == null) { if ($firstCallWait) { $timeToWait = static::$timeAllowedForEachApiCall; From 0493d99ab2c8af7ce3be1cb29324bd6695813069 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Fri, 6 Mar 2020 21:33:37 +0000 Subject: [PATCH 08/29] Update namespace. --- lib/AuthHelper.php | 1 + lib/Http/CurlRequest.php | 2 +- lib/Http/CurlResponse.php | 2 +- lib/Http/HttpRequestJson.php | 9 ++------- lib/ShopifyResource.php | 2 ++ lib/ShopifyResource/GraphQL.php | 2 +- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index bfb9253..a5c1ac3 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -3,6 +3,7 @@ namespace PHPShopify; use PHPShopify\Exception\SdkException; +use PHPShopify\Http\HttpRequestJson; class AuthHelper { diff --git a/lib/Http/CurlRequest.php b/lib/Http/CurlRequest.php index 8ec6fdd..c3525ab 100644 --- a/lib/Http/CurlRequest.php +++ b/lib/Http/CurlRequest.php @@ -1,6 +1,6 @@ - * Created at: 8/24/16 9:03 AM UTC+06:00 - */ -namespace PHPShopify; +namespace PHPShopify\Http; class HttpRequestJson extends CurlRequest { @@ -24,4 +19,4 @@ protected static function parseBody(string $body) { return json_decode($body, true); } -} \ No newline at end of file +} diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index a9e41fa..0c9a5fa 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -8,6 +8,8 @@ use PHPShopify\Exception\ApiException; use PHPShopify\Exception\SdkException; use PHPShopify\Exception\CurlException; +use PHPShopify\Http\HttpRequestJson; +use PHPShopify\Http\CurlResponse; /* |-------------------------------------------------------------------------- diff --git a/lib/ShopifyResource/GraphQL.php b/lib/ShopifyResource/GraphQL.php index 97cd869..b1f09b8 100644 --- a/lib/ShopifyResource/GraphQL.php +++ b/lib/ShopifyResource/GraphQL.php @@ -5,7 +5,7 @@ namespace PHPShopify\ShopifyResource; -use PHPShopify\HttpRequestJson; +use PHPShopify\Http\HttpRequestJson; use PHPShopify\ShopifyResource; use PHPShopify\Exception\ApiException; use PHPShopify\Exception\CurlException; From 8f707a1cf1a7267e380dbb80b29eef2fd8590505 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Fri, 6 Mar 2020 21:46:06 +0000 Subject: [PATCH 09/29] Less excessive static. --- lib/AuthHelper.php | 21 +++++++----- lib/ShopifyResource.php | 18 ++++------ lib/ShopifySDK.php | 74 ++++++++++++----------------------------- 3 files changed, 39 insertions(+), 74 deletions(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index a5c1ac3..f5fe48a 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -44,15 +44,15 @@ public static function buildQueryString(array $data): string * @inheritDoc * @throws SdkException if SharedSecret is not provided or hmac is not found in the url parameters */ - public static function verifyShopifyRequest(): bool + public static function verifyShopifyRequest(array $config): bool { $data = $_GET; - if(!isset(ShopifySDK::$config['SharedSecret'])) { + if(!isset($config['SharedSecret'])) { throw new SdkException("Please provide SharedSecret while configuring the SDK client."); } - $sharedSecret = ShopifySDK::$config['SharedSecret']; + $sharedSecret = $config['SharedSecret']; if (isset($data['hmac'])) { $hmac = $data['hmac']; @@ -82,10 +82,15 @@ public static function verifyShopifyRequest(): bool * @param string[] $options * @throws SdkException if required configuration is not provided in $config */ - public static function createAuthRequest($scopes, ?string $redirectUrl = null, ?string $state = null, ?array $options = null, bool $return = false): ?string + public static function createAuthRequest( + array $config, $scopes, + ?string $redirectUrl = null, + ?string $state = null, + ?array $options = null, + bool $return = false + ): ?string { assert(is_string($scopes) || is_array($scopes)); - $config = ShopifySDK::$config; if(!isset($config['ShopUrl']) || !isset($config['ApiKey'])) { throw new SdkException("ShopUrl and ApiKey are required for authentication request. Please check SDK configuration!"); @@ -136,15 +141,13 @@ public static function createAuthRequest($scopes, ?string $redirectUrl = null, ? * @inheritDoc * @throws SdkException if SharedSecret or ApiKey is missing in SDK configuration or request is not valid */ - public static function getAccessToken(?array $config): string + public static function getAccessToken(array $config): string { - $config = $config ?? ShopifySDK::$config; - if(!isset($config['SharedSecret']) || !isset($config['ApiKey'])) { throw new SdkException("SharedSecret and ApiKey are required for getting access token. Please check SDK configuration!"); } - if(self::verifyShopifyRequest()) { + if(self::verifyShopifyRequest($config)) { $data = [ 'client_id' => $config['ApiKey'], 'client_secret' => $config['SharedSecret'], diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 0c9a5fa..b1035ca 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -11,14 +11,6 @@ use PHPShopify\Http\HttpRequestJson; use PHPShopify\Http\CurlResponse; -/* -|-------------------------------------------------------------------------- -| Shopify API SDK Base Class -|-------------------------------------------------------------------------- -| -| This class handles get, post, put, delete and any other custom actions for the API -| -*/ abstract class ShopifyResource { /** @@ -126,11 +118,13 @@ abstract class ShopifyResource */ private $prevLink = null; - public function __construct($id = null, $parentResourceUrl = '') + /** @var ShopifySDK */ + protected $sdk; + + public function __construct(ShopifySdk $sdk, $id = null, $parentResourceUrl = '') { $this->id = $id; - - $config = ShopifySDK::$config; + $this->sdk = $sdk; $this->resourceUrl = ($parentResourceUrl ? $parentResourceUrl . '/' : $config['ApiUrl']) . $this->getResourcePath() . ($this->id ? '/' . $this->id : ''); @@ -194,7 +188,7 @@ public function __call($name, $arguments) $resourceID = !empty($arguments) ? $arguments[0] : null; - $api = new $childClass($resourceID, $this->resourceUrl); + $api = new $childClass($this->sdk, $resourceID, $this->resourceUrl); return $api; } else { diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index a2b7f36..2ba25a2 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -232,28 +232,34 @@ class ShopifySDK 'UsageCharge' => 'RecurringApplicationCharge', ]; - /* - * ShopifySDK constructor - * - * @param array $config - * - * @return void - */ public function __construct(array $config = []) { - $this->config = $config + ['ApiVersion' => self::$defaultApiVersion]; + $config += ['ApiVersion' => self::$defaultApiVersion]; + + $shopUrl = $config['ShopUrl']; + $shopUrl = preg_replace('#^https?://|/$#', '', $shopUrl); + $apiVersion = $config['ApiVersion']; - //Re-set the admin url if shop url is changed - if(isset($config['ShopUrl'])) { - self::setAdminUrl(); + if (isset($config['ApiKey']) && isset($config['Password'])) { + $apiKey = $config['ApiKey']; + $apiPassword = $config['Password']; + $adminUrl = "https://{$apiKey}:{$apiPassword}@{$shopUrl}/admin/"; + } else { + $adminUrl = "https://{$shopUrl}/admin/"; } - //If want to keep more wait time than .5 seconds for each call + $config['AdminUrl'] = $adminUrl; + $config['ApiUrl'] = "{$adminUrl}api/{$apiVersion}/"; + $this->config = $config; + if (isset($config['AllowedTimePerCall'])) { static::$timeAllowedForEachApiCall = $config['AllowedTimePerCall']; } + } - return new ShopifySDK; + public function getConfig(): array + { + return $this->config; } /** @@ -289,6 +295,7 @@ public function __call($resourceName, $arguments) } else { $message = "Invalid resource name $resourceName. Pls check the API Reference to get the appropriate resource name."; } + throw new SdkException($message); } @@ -298,50 +305,11 @@ public function __call($resourceName, $arguments) $resourceID = !empty($arguments) ? $arguments[0] : null; //Initiate the resource object - $resource = new $resourceClassName($resourceID); + $resource = new $resourceClassName($this, $resourceID); return $resource; } - /** - * Configure the SDK client - * - * @param array $config - * - * @return ShopifySDK - */ - private function config(array $config) - { - - } - - /** - * Set the admin url, based on the configured shop url - * - * @return string - */ - public static function setAdminUrl() - { - $shopUrl = self::$config['ShopUrl']; - - //Remove https:// and trailing slash (if provided) - $shopUrl = preg_replace('#^https?://|/$#', '', $shopUrl); - $apiVersion = self::$config['ApiVersion']; - - if(isset(self::$config['ApiKey']) && isset(self::$config['Password'])) { - $apiKey = self::$config['ApiKey']; - $apiPassword = self::$config['Password']; - $adminUrl = "https://$apiKey:$apiPassword@$shopUrl/admin/"; - } else { - $adminUrl = "https://$shopUrl/admin/"; - } - - self::$config['AdminUrl'] = $adminUrl; - self::$config['ApiUrl'] = $adminUrl . "api/$apiVersion/"; - - return $adminUrl; - } - /** * Maintain maximum 2 calls per second to the API * From 10e2d11ee97a82a9e18680f5240b29f033672697 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Fri, 6 Mar 2020 23:59:47 +0000 Subject: [PATCH 10/29] Stop auth helper from embedding globals. --- lib/AuthHelper.php | 61 +++++++-------------------------------- lib/Http/CurlResponse.php | 1 - lib/ShopifyResource.php | 36 ++++++----------------- 3 files changed, 20 insertions(+), 78 deletions(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index f5fe48a..68aa1b0 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -44,14 +44,8 @@ public static function buildQueryString(array $data): string * @inheritDoc * @throws SdkException if SharedSecret is not provided or hmac is not found in the url parameters */ - public static function verifyShopifyRequest(array $config): bool + public static function verifyShopifyRequest(array $config, array $data): bool { - $data = $_GET; - - if(!isset($config['SharedSecret'])) { - throw new SdkException("Please provide SharedSecret while configuring the SDK client."); - } - $sharedSecret = $config['SharedSecret']; if (isset($data['hmac'])) { @@ -80,78 +74,45 @@ public static function verifyShopifyRequest(array $config): bool * @inheritDoc * @param string|string[] $scopes Scopes required by app * @param string[] $options - * @throws SdkException if required configuration is not provided in $config */ public static function createAuthRequest( - array $config, $scopes, - ?string $redirectUrl = null, + array $config, + ?array $scopes, + string $redirectUrl, ?string $state = null, - ?array $options = null, - bool $return = false + ?array $options = null ): ?string { assert(is_string($scopes) || is_array($scopes)); - if(!isset($config['ShopUrl']) || !isset($config['ApiKey'])) { - throw new SdkException("ShopUrl and ApiKey are required for authentication request. Please check SDK configuration!"); - } - - if (!$redirectUrl) { - if(!isset($config['SharedSecret'])) { - throw new SdkException("SharedSecret is required for getting access token. Please check SDK configuration!"); - } - - //If redirect url is the same as this url, then need to check for access token when redirected back from shopify - if(isset($_GET['code'])) { - return self::getAccessToken($config); - } else { - $redirectUrl = self::getCurrentUrl(); - } - } - - if (is_array($scopes)) { + if ($scopes !== null) { $scopes = join(',', $scopes); } - if(!is_string($state)) { + if ($state !== null) { $state = '&state=' . $state; } - if(!is_array($options)) { + if ($options !== null) { $options = '&grant_options[]=' . implode(',', $options); } // Official call structure // https://{shop}.myshopify.com/admin/oauth/authorize?client_id={api_key}&scope={scopes}&redirect_uri={redirect_uri}&state={nonce}&grant_options[]={option} - $authUrl = "{$config['AdminUrl']}oauth/authorize?client_id={$config['ApiKey']}&redirect_uri={$redirectUrl}&scope={$scopes}{$state}{$options}"; - - if ($return) { - return $authUrl; - } - - header("Location: $authUrl"); - - return null; + return "{$config['AdminUrl']}oauth/authorize?client_id={$config['ApiKey']}&redirect_uri={$redirectUrl}&scope={$scopes}{$state}{$options}"; } /** * Get Access token for the API * Call this when being redirected from shopify page ( to the $redirectUrl) after authentication - * - * @inheritDoc - * @throws SdkException if SharedSecret or ApiKey is missing in SDK configuration or request is not valid */ - public static function getAccessToken(array $config): string + public static function getAccessToken(array $config, array $data): string { - if(!isset($config['SharedSecret']) || !isset($config['ApiKey'])) { - throw new SdkException("SharedSecret and ApiKey are required for getting access token. Please check SDK configuration!"); - } - if(self::verifyShopifyRequest($config)) { $data = [ 'client_id' => $config['ApiKey'], 'client_secret' => $config['SharedSecret'], - 'code' => $_GET['code'], + 'code' => $data['code'], ]; $response = HttpRequestJson::post("{$config['AdminUrl']}oauth/access_token", $data); diff --git a/lib/Http/CurlResponse.php b/lib/Http/CurlResponse.php index 78f9c9d..2f02533 100644 --- a/lib/Http/CurlResponse.php +++ b/lib/Http/CurlResponse.php @@ -8,7 +8,6 @@ class CurlResponse private $status; /** @var array */ private $headers = []; - /** @var string */ private $body; public function __construct(int $status, array $headers, $body) diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index b1035ca..782458a 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -104,20 +104,6 @@ abstract class ShopifyResource * @throws SdkException if Either AccessToken or ApiKey+Password Combination is not found in configuration */ - /** - * Response Header Link, used for pagination - * @see: https://help.shopify.com/en/api/guides/paginated-rest-results?utm_source=exacttarget&utm_medium=email&utm_campaign=api_deprecation_notice_1908 - * @var string $nextLink - */ - private $nextLink = null; - - /** - * Response Header Link, used for pagination - * @see: https://help.shopify.com/en/api/guides/paginated-rest-results?utm_source=exacttarget&utm_medium=email&utm_campaign=api_deprecation_notice_1908 - * @var string $prevLink - */ - private $prevLink = null; - /** @var ShopifySDK */ protected $sdk; @@ -331,15 +317,17 @@ public function getPages($urlParams = array(), $url = null, $dataKey = null): \G $url = $this->generateUrl($urlParams); } + if (!$dataKey) { + $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey(); + } + while ($url !== null) { $response = HttpRequestJson::get($url, $this->httpHeaders); - if ($response === null || !count($response)) { - break; - } + $data = $response->getBody(); - if (!$dataKey) { - $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey(); + if ($data === null || !count($data)) { + break; } yield $this->processResponse($response, $dataKey); @@ -512,17 +500,11 @@ protected function castString($array) } /** - * Process the request response - * - * @param array $responseArray Request response in array format - * @param string $dataKey Keyname to fetch data from response array - * + * @inheritDoc * @throws ApiException if the response has an error specified * @throws CurlException if response received with unexpected HTTP code. - * - * @return array */ - public function processResponse(CurlResponse $response, $dataKey = null) + public function processResponse(CurlResponse $response, $dataKey = null): array { $body = $response->getBody(); From a9f11cc0225810592dc85b6cda4453fab3ba5454 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 10:53:25 +0000 Subject: [PATCH 11/29] Update syntax, strip noisy comments, refactor. --- lib/Http/HttpRequestJson.php | 7 +- lib/ShopifyResource.php | 263 +++++++++++------------------------ 2 files changed, 89 insertions(+), 181 deletions(-) diff --git a/lib/Http/HttpRequestJson.php b/lib/Http/HttpRequestJson.php index 4aa2dde..6a11ba5 100644 --- a/lib/Http/HttpRequestJson.php +++ b/lib/Http/HttpRequestJson.php @@ -9,7 +9,7 @@ protected static function init(string $method, string $url, array $httpHeaders = // Note: Is null valid for any shopify calls? if ($data !== null) { $httpHeaders['Content-type'] = 'application/json'; - $data = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + $data = self::encode($data); } return parent::init($method, $url, $httpHeaders, $data); @@ -19,4 +19,9 @@ protected static function parseBody(string $body) { return json_decode($body, true); } + + public static function encode($data): string + { + return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + } } diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 782458a..25dcfd6 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -154,62 +154,46 @@ public function __get($childName) */ public function __call($name, $arguments) { - //If the $name starts with an uppercase letter, it's considered as a child class - //Otherwise it's a custom action if (ctype_upper($name[0])) { - //Get the array key of the childResource in the childResource array - $childKey = array_search($name, $this->childResource); + $childKey = array_search($name, $this->childResource, true); if ($childKey === false) { throw new SdkException("Child Resource $name is not available for " . $this->getResourceName()); } - //If any associative key is given to the childname, then it will be considered as the class name, - //otherwise the childname will be the class name $childClassName = !is_numeric($childKey) ? $childKey : $name; - $childClass = self::class . "\\" . $childClassName; + $resourceId = !empty($arguments) ? $arguments[0] : null; + $api = new $childClass($this->sdk, $resourceId, $this->resourceUrl); - //If first argument is provided, it will be considered as the ID of the resource. - $resourceID = !empty($arguments) ? $arguments[0] : null; + return $api; + } else { + $actionMaps = [ + 'post' => $this->customPostActions, + 'put' => $this->customPutActions, + 'get' => $this->customGetActions, + 'delete'=> $this->customDeleteActions, + ]; + $actionKey = false; - $api = new $childClass($this->sdk, $resourceID, $this->resourceUrl); + foreach ($actionMaps as $httpMethod => $actions) { + $actionKey = array_search($name, $actions, true); - return $api; - } else { - $actionMaps = array( - 'post' => 'customPostActions', - 'put' => 'customPutActions', - 'get' => 'customGetActions', - 'delete'=> 'customDeleteActions', - ); - - //Get the array key for the action in the actions array - foreach ($actionMaps as $httpMethod => $actionArrayKey) { - $actionKey = array_search($name, $this->$actionArrayKey); - if ($actionKey !== false) break; + if ($actionKey !== false) { + break; + } } if ($actionKey === false) { throw new SdkException("No action named $name is defined for " . $this->getResourceName()); } - //If any associative key is given to the action, then it will be considered as the method name, - //otherwise the action name will be the method name $customAction = !is_numeric($actionKey) ? $actionKey : $name; + $methodArgument = !empty($arguments) ? $arguments[0] : []; + $urlParams = $dataArray = []; - //Get the first argument if provided with the method call - $methodArgument = !empty($arguments) ? $arguments[0] : array(); - - //Url parameters - $urlParams = array(); - //Data body - $dataArray = array(); - - //Consider the argument as url parameters for get and delete request - //and data array for post and put request if ($httpMethod == 'post' || $httpMethod == 'put') { $dataArray = $methodArgument; } else { @@ -220,18 +204,16 @@ public function __call($name, $arguments) if ($httpMethod == 'post' || $httpMethod == 'put') { return $this->$httpMethod($dataArray, $url, false); - } else { - return $this->$httpMethod($dataArray, $url); } + + return $this->$httpMethod($dataArray, $url); } } /** * Get the resource name (or the class name) - * - * @return string */ - public function getResourceName() + public function getResourceName(): string { return substr(get_called_class(), strrpos(get_called_class(), '\\') + 1); } @@ -240,10 +222,8 @@ public function getResourceName() * Get the resource key to be used for while sending data to the API * * Normally its the same as $resourceKey, when it's different, the specific resource class will override this function - * - * @return string */ - public function getResourcePostKey() + public function getResourcePostKey(): string { return $this->resourceKey; } @@ -252,10 +232,8 @@ public function getResourcePostKey() * Get the pluralized version of the resource key * * Normally its the same as $resourceKey appended with 's', when it's different, the specific resource class will override this function - * - * @return string */ - protected function pluralizeKey() + protected function pluralizeKey(): string { return $this->resourceKey . 's'; } @@ -265,53 +243,36 @@ protected function pluralizeKey() * * Normally its the same as the pluralized version of the resource key, * when it's different, the specific resource class will override this function - * - * @return string */ - protected function getResourcePath() + protected function getResourcePath(): string { return $this->pluralizeKey(); } /** * Generate the custom url for api request based on the params and custom action (if any) - * - * @param array $urlParams - * @param string $customAction - * - * @return string */ - public function generateUrl($urlParams = array(), $customAction = null) + public function generateUrl(array $urlParams = [], ?string $customAction = null): string { - return $this->resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''); + return $this->resourceUrl . ($customAction ? "/{$customAction}" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''); } - /** - * Generate a HTTP GET request and return results as an array - * - * @param array $urlParams Check Shopify API reference of the specific resource for the list of URL parameters - * @param string $url - * @param string $dataKey Keyname to fetch data from response array - * - * @uses HttpRequestJson::get() to send the HTTP request - * - * @throws ApiException if the response has an error specified - * @throws CurlException if response received with unexpected HTTP code. - * - * @return array - */ - public function get($urlParams = array(), $url = null, $dataKey = null) + public function get(array $urlParams = [], ?string $url = null, $dataKey = null) { - if (!$url) $url = $this->generateUrl($urlParams); + if (!$url) { + $url = $this->generateUrl($urlParams); + } $response = HttpRequestJson::get($url, $this->httpHeaders); - if (!$dataKey) $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey(); + if (!$dataKey) { + $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey(); + } return $this->processResponse($response, $dataKey); } - public function getPages($urlParams = array(), $url = null, $dataKey = null): \Generator + public function each(array $urlParams = [], ?string $url = null, $dataKey = null): \Generator { if (!$url) { $url = $this->generateUrl($urlParams); @@ -336,18 +297,7 @@ public function getPages($urlParams = array(), $url = null, $dataKey = null): \G } } - /** - * Get count for the number of resources available - * - * @param array $urlParams Check Shopify API reference of the specific resource for the list of URL parameters - * - * @throws SdkException - * @throws ApiException if the response has an error specified - * @throws CurlException if response received with unexpected HTTP code. - * - * @return integer - */ - public function count($urlParams = array()) + public function count($urlParams = []) { if (!$this->countEnabled) { throw new SdkException("Count is not available for " . $this->getResourceName()); @@ -355,145 +305,91 @@ public function count($urlParams = array()) $url = $this->generateUrl($urlParams, 'count'); - return $this->get(array(), $url, 'count'); + return $this->get([], $url, 'count'); } - /** - * Search within the resouce - * - * @param mixed $query - * - * @throws SdkException if search is not enabled for the resouce - * @throws ApiException if the response has an error specified - * @throws CurlException if response received with unexpected HTTP code. - * - * @return array - */ public function search($query) { if (!$this->searchEnabled) { throw new SdkException("Search is not available for " . $this->getResourceName()); } - if (!is_array($query)) $query = array('query' => $query); + if (!is_array($query)) { + $query = ['query' => $query]; + } $url = $this->generateUrl($query, 'search'); - return $this->get(array(), $url); + return $this->get([], $url); } - /** - * Call POST method to create a new resource - * - * @param array $dataArray Check Shopify API reference of the specific resource for the list of required and optional data elements to be provided - * @param string $url - * @param bool $wrapData - * - * @uses HttpRequestJson::post() to send the HTTP request - * - * @throws ApiException if the response has an error specified - * @throws CurlException if response received with unexpected HTTP code. - * - * @return array - */ - public function post($dataArray, $url = null, $wrapData = true) + public function post(?array $dataArray, ?string $url = null, bool $wrapData = true) { - if (!$url) $url = $this->generateUrl(); + if (!$url) { + $url = $this->generateUrl(); + } - if ($wrapData && !empty($dataArray)) $dataArray = $this->wrapData($dataArray); + if ($wrapData && $dataArray !== null) { + $dataArray = $this->wrapData($dataArray); + } $response = HttpRequestJson::post($url, $dataArray, $this->httpHeaders); return $this->processResponse($response, $this->resourceKey); } - /** - * Call PUT method to update an existing resource - * - * @param array $dataArray Check Shopify API reference of the specific resource for the list of required and optional data elements to be provided - * @param string $url - * @param bool $wrapData - * - * @uses HttpRequestJson::put() to send the HTTP request - * - * @throws ApiException if the response has an error specified - * @throws CurlException if response received with unexpected HTTP code. - * - * @return array - */ - public function put($dataArray, $url = null, $wrapData = true) + public function put(array $dataArray, ?string $url = null, bool $wrapData = true): array { + if (!$url) { + $url = $this->generateUrl(); + } - if (!$url) $url = $this->generateUrl(); - - if ($wrapData && !empty($dataArray)) $dataArray = $this->wrapData($dataArray); + if ($wrapData && !empty($dataArray)) { + $dataArray = $this->wrapData($dataArray); + } $response = HttpRequestJson::put($url, $dataArray, $this->httpHeaders); return $this->processResponse($response, $this->resourceKey); } - /** - * Call DELETE method to delete an existing resource - * - * @param array $urlParams Check Shopify API reference of the specific resource for the list of URL parameters - * @param string $url - * - * @uses HttpRequestJson::delete() to send the HTTP request - * - * @throws ApiException if the response has an error specified - * @throws CurlException if response received with unexpected HTTP code. - * - * @return array an empty array will be returned if the request is successfully completed - */ - public function delete($urlParams = array(), $url = null) + public function delete(array $urlParams = [], ?string $url = null): void { - if (!$url) $url = $this->generateUrl($urlParams); + if (!$url) { + $url = $this->generateUrl($urlParams); + } $response = HttpRequestJson::delete($url, $this->httpHeaders); + $response = $this->processResponse($response); - return $this->processResponse($response); + if (!is_array($response) || count($response) !== 0) { + throw new SdkException('Unexpected API response on delete: ' . HttpRequestJson::encode($response)); + } } - /** - * Wrap data array with resource key - * - * @param array $dataArray - * @param string $dataKey - * - * @return array - */ - protected function wrapData($dataArray, $dataKey = null) + protected function wrapData(array $dataArray, $dataKey = null): array { - if (!$dataKey) $dataKey = $this->getResourcePostKey(); + if (!$dataKey) { + $dataKey = $this->getResourcePostKey(); + } - return array($dataKey => $dataArray); + return [$dataKey => $dataArray]; } - /** - * Convert an array to string - * - * @param array $array - * - * @internal - * - * @return string - */ - protected function castString($array) + protected static function castString(array $array): string { - if ( ! is_array($array)) return (string) $array; + if (!is_array($array)) { + return (string) $array; + } $string = ''; $i = 0; + foreach ($array as $key => $val) { - //Add values separated by comma - //prepend the key string, if it's an associative key - //Check if the value itself is another array to be converted to string $string .= ($i === $key ? '' : "$key - ") . $this->castString($val) . ', '; $i++; } - //Remove trailing comma and space $string = rtrim($string, ', '); return $string; @@ -504,7 +400,7 @@ protected function castString($array) * @throws ApiException if the response has an error specified * @throws CurlException if response received with unexpected HTTP code. */ - public function processResponse(CurlResponse $response, $dataKey = null): array + protected static function validateResponse(CurlResponse $response, $dataKey = null) { $body = $response->getBody(); @@ -519,11 +415,18 @@ public function processResponse(CurlResponse $response, $dataKey = null): array } if (isset($body['errors'])) { - $message = $this->castString($body['errors']); + $message = self::castString($body['errors']); throw new ApiException($message, $response->getStatus()); } + return $body; + } + + protected function processResponse(CurlResponse $response, $dataKey = null) + { + $body = self::validateResponse($response); + if ($dataKey !== null && isset($body[$dataKey])) { return $body[$dataKey]; } @@ -531,7 +434,7 @@ public function processResponse(CurlResponse $response, $dataKey = null): array return $body; } - private static function getLinks(CurlResponse $response): ?array + protected static function getLinks(CurlResponse $response): ?array { $linkHeader = $response->getHeader('link'); From b64b177fdedfb761cbbfd0e7a1f4789c98323526 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 10:58:31 +0000 Subject: [PATCH 12/29] LOL: return md5() === md5(); --- lib/AuthHelper.php | 4 ++-- lib/ShopifySDK.php | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index 68aa1b0..8a5e000 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -32,7 +32,7 @@ public static function buildQueryString(array $data): string $paramStrings = []; foreach ($data as $key => $value) { - $paramStrings[] = "$key=$value"; + $paramStrings[] = "{$key}={$value}"; } return implode('&', $paramStrings); @@ -64,7 +64,7 @@ public static function verifyShopifyRequest(array $config, array $data): bool $realHmac = hash_hmac('sha256', $dataString, $sharedSecret); - return md5($realHmac) === md5($hmac); + return $realHmac === $hmac; } /** diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 2ba25a2..d1b4771 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -327,16 +327,14 @@ public static function checkApiCallLimit($firstCallWait = false): void } else { $now = microtime(true); $timeSinceLastCall = $now - static::$microtimeOfLastApiCall; - //Ensure 2 API calls per second + if($timeSinceLastCall < static::$timeAllowedForEachApiCall) { $timeToWait = static::$timeAllowedForEachApiCall - $timeSinceLastCall; } } if ($timeToWait) { - //convert time to microseconds $microSecondsToWait = $timeToWait * 1000000; - //Wait to maintain the API call difference of .5 seconds usleep($microSecondsToWait); } From 46c4a9fd3ca69f3187d4a134b35f95cbe9b3fb94 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 11:28:49 +0000 Subject: [PATCH 13/29] Pruine and clean up test formatting. --- tests/AbandonedCheckoutTest.php | 8 +----- tests/ApplicationChargeTest.php | 8 +----- tests/BlogTest.php | 17 ++++--------- tests/CarrierServiceTest.php | 15 +++-------- tests/CollectTest.php | 8 +----- tests/CommentTest.php | 9 +------ tests/CountryTest.php | 27 +++++--------------- tests/CurrencyTest.php | 10 +------- tests/CustomCollectionTest.php | 25 +++++------------- tests/CustomerSavedSearchTest.php | 23 ++++------------- tests/CustomerTest.php | 30 ++++++---------------- tests/FulfillmentServiceTest.php | 27 ++++++-------------- tests/LocationTest.php | 9 +------ tests/MetafieldTest.php | 22 ++++------------ tests/OrderTest.php | 9 +------ tests/PageTest.php | 25 +++++------------- tests/PolicyTest.php | 9 +------ tests/ProductListingTest.php | 10 +------- tests/ProductTest.php | 32 ++++++------------------ tests/RecurringApplicationChargeTest.php | 9 +------ tests/RedirectTest.php | 20 +++------------ tests/ReportTest.php | 16 ++++-------- tests/ScriptTagTest.php | 22 ++++------------ tests/ShippingZoneTest.php | 9 +------ tests/ShopTest.php | 9 +------ tests/SmartCollectionTest.php | 25 ++++++------------ tests/ThemeTest.php | 8 +----- tests/WebhookTest.php | 21 +++------------- 28 files changed, 97 insertions(+), 365 deletions(-) diff --git a/tests/AbandonedCheckoutTest.php b/tests/AbandonedCheckoutTest.php index 7df2ed0..8757a32 100644 --- a/tests/AbandonedCheckoutTest.php +++ b/tests/AbandonedCheckoutTest.php @@ -1,13 +1,7 @@ - * Created at: 9/9/16 7:41 PM UTC+06:00 - */ namespace PHPShopify; - class AbandonedCheckoutTest extends TestSimpleResource { -} \ No newline at end of file +} diff --git a/tests/ApplicationChargeTest.php b/tests/ApplicationChargeTest.php index 27bdcf1..789979c 100644 --- a/tests/ApplicationChargeTest.php +++ b/tests/ApplicationChargeTest.php @@ -1,13 +1,7 @@ - * Created at: 9/9/16 9:59 PM UTC+06:00 - */ namespace PHPShopify; - class ApplicationChargeTest extends TestSimpleResource { -} \ No newline at end of file +} diff --git a/tests/BlogTest.php b/tests/BlogTest.php index ffbd52b..c664ce6 100644 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -10,17 +10,10 @@ class BlogTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "title" => "PHPShopify Test Blog", - ); - - /** - * @inheritDoc - */ - public $putArray = array( + ]; + public $putArray = [ "title" => "PHPShopify Test Blog Modified", - ); -} \ No newline at end of file + ]; +} diff --git a/tests/CarrierServiceTest.php b/tests/CarrierServiceTest.php index a601cdb..b01add7 100644 --- a/tests/CarrierServiceTest.php +++ b/tests/CarrierServiceTest.php @@ -10,20 +10,13 @@ class CarrierServiceTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "name" => "Shipping Rate Provider", "callback_url" => "http://shippingrateprovider.com", "service_discovery" => true - ); - - /** - * @inheritDoc - */ - public $putArray = array( + ]; + public $putArray = [ "name" => "Updated Shipping Rate Provider", "active" => false, - ); + ]; } \ No newline at end of file diff --git a/tests/CollectTest.php b/tests/CollectTest.php index fc2d507..00fe200 100644 --- a/tests/CollectTest.php +++ b/tests/CollectTest.php @@ -1,14 +1,8 @@ - * Created at: 9/10/16 10:44 AM UTC+06:00 - */ namespace PHPShopify; class CollectTest extends TestSimpleResource { - -} \ No newline at end of file +} diff --git a/tests/CommentTest.php b/tests/CommentTest.php index c3cd9e7..4120ecf 100644 --- a/tests/CommentTest.php +++ b/tests/CommentTest.php @@ -1,14 +1,7 @@ - * Created at: 9/10/16 10:45 AM UTC+06:00 - */ namespace PHPShopify; - class CommentTest extends TestSimpleResource { - -} \ No newline at end of file +} diff --git a/tests/CountryTest.php b/tests/CountryTest.php index 1a0ddc2..31a9cf1 100644 --- a/tests/CountryTest.php +++ b/tests/CountryTest.php @@ -1,35 +1,20 @@ - * Created at: 9/10/16 10:45 AM UTC+06:00 - */ namespace PHPShopify; - class CountryTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "code" => "BD", "tax" => 0.25, - ); + ]; - /** - * @inheritDoc - */ - public $putArray = array( + public $putArray = [ "tax" => 0.01, - ); + ]; - /** - * @inheritDoc - * TODO: Shopify count and get result doesn't match, remove this function if that issue is fixed. - */ - public function testGet() { + public function testGet() + { $this->assertEquals(1, 1); } } \ No newline at end of file diff --git a/tests/CurrencyTest.php b/tests/CurrencyTest.php index 70ac526..b1733c2 100644 --- a/tests/CurrencyTest.php +++ b/tests/CurrencyTest.php @@ -1,15 +1,7 @@ - * Created at: 9/10/16 10:45 AM UTC+06:00 - */ namespace PHPShopify; - class CustomCollectionTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( - "title" => "Macbooks" - ); - - /** - * @inheritDoc - */ - public $putArray = array( + public $postArray = [ + "title" => "Macbooks", + ]; + public $putArray = [ "title" => "Updated - Macbooks", "body_html" => "

The best selling Macbooks ever

", - ); -} \ No newline at end of file + ]; +} diff --git a/tests/CustomerSavedSearchTest.php b/tests/CustomerSavedSearchTest.php index 106365f..a9ec1d6 100644 --- a/tests/CustomerSavedSearchTest.php +++ b/tests/CustomerSavedSearchTest.php @@ -1,27 +1,14 @@ - * Created at: 9/10/16 10:46 AM UTC+06:00 - */ namespace PHPShopify; - class CustomerSavedSearchTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "name" => "Spent more than $50 and after 2015", "query" => "total_spent:>50 order_date:>=2015-01-01", - ); - - /** - * @inheritDoc - */ - public $putArray = array( + ]; + public $putArray = [ "name" => "This Name Has Been Changed", - ); -} \ No newline at end of file + ]; +} diff --git a/tests/CustomerTest.php b/tests/CustomerTest.php index b9c0049..b758639 100644 --- a/tests/CustomerTest.php +++ b/tests/CustomerTest.php @@ -1,36 +1,20 @@ - * Created at: 9/10/16 10:45 AM UTC+06:00 - */ namespace PHPShopify; - class CustomerTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "first_name" => "Steve", "last_name" => "Lastnameson", "email" => "steve.lastnameson@example.com", - ); - - /** - * @inheritDoc - */ - public $putArray = array( + ]; + public $putArray = [ "verified_email" => true, - ); + ]; - /** - * @inheritDoc - * TODO: Shopify count and get result doesn't match, remove this function if that issue is fixed. - */ - public function testGet() { + public function testGet() + { $this->assertEquals(1, 1); } -} \ No newline at end of file +} diff --git a/tests/FulfillmentServiceTest.php b/tests/FulfillmentServiceTest.php index d898c29..b28fcf5 100644 --- a/tests/FulfillmentServiceTest.php +++ b/tests/FulfillmentServiceTest.php @@ -1,32 +1,19 @@ - * Created at: 9/10/16 10:47 AM UTC+06:00 - */ namespace PHPShopify; - class FulfillmentServiceTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "name" => "MarsFulfillment", "callback_url" => "http://google.com", "inventory_management" => true, "tracking_support" => true, "requires_shipping_method" => true, - "format" => "json" - ); - - /** - * @inheritDoc - */ - public $putArray = array( - "tracking_support" => false - ); + "format" => "json", + ]; -} \ No newline at end of file + public $putArray = [ + "tracking_support" => false, + ]; +} diff --git a/tests/LocationTest.php b/tests/LocationTest.php index 894e9ff..404ef04 100644 --- a/tests/LocationTest.php +++ b/tests/LocationTest.php @@ -1,14 +1,7 @@ - * Created at: 9/10/16 10:48 AM UTC+06:00 - */ namespace PHPShopify; - class LocationTest extends TestSimpleResource { - -} \ No newline at end of file +} diff --git a/tests/MetafieldTest.php b/tests/MetafieldTest.php index 5038381..95fbbb5 100644 --- a/tests/MetafieldTest.php +++ b/tests/MetafieldTest.php @@ -1,30 +1,18 @@ - * Created at: 9/10/16 10:48 AM UTC+06:00 - */ namespace PHPShopify; - class MetafieldTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "namespace" => "inventory", "key" => "warehouse", "value" => 25, "value_type" => "integer", - ); + ]; - /** - * @inheritDoc - */ - public $putArray = array( + public $putArray = [ "value" => "something new", "value_type" => "string", - ); -} \ No newline at end of file + ]; +} diff --git a/tests/OrderTest.php b/tests/OrderTest.php index e5e4fa6..56183e7 100644 --- a/tests/OrderTest.php +++ b/tests/OrderTest.php @@ -1,14 +1,7 @@ - * Created at: 9/10/16 10:48 AM UTC+06:00 - */ namespace PHPShopify; - class OrderTest extends TestSimpleResource { - -} \ No newline at end of file +} diff --git a/tests/PageTest.php b/tests/PageTest.php index ec135cd..212a0d3 100644 --- a/tests/PageTest.php +++ b/tests/PageTest.php @@ -1,27 +1,14 @@ - * Created at: 9/10/16 10:49 AM UTC+06:00 - */ namespace PHPShopify; - class PageTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "title" => "Warranty information", - "body_html" => "

Warranty<\/h1>\n

Forget it<\/strong>, we aint giving you nothing<\/p>", - ); - - /** - * @inheritDoc - */ - public $putArray = array( + "body_html" => "

Warranty

\n

Forget it, we ain't giving you nothing

", + ]; + public $putArray = [ "title" => "Updated Warranty information" - ); -} \ No newline at end of file + ]; +} diff --git a/tests/PolicyTest.php b/tests/PolicyTest.php index e533e93..bb8c3a8 100644 --- a/tests/PolicyTest.php +++ b/tests/PolicyTest.php @@ -1,14 +1,7 @@ - * Created at: 9/10/16 10:49 AM UTC+06:00 - */ namespace PHPShopify; - class PolicyTest extends TestSimpleResource { - -} \ No newline at end of file +} diff --git a/tests/ProductListingTest.php b/tests/ProductListingTest.php index 560650e..e490d0d 100644 --- a/tests/ProductListingTest.php +++ b/tests/ProductListingTest.php @@ -1,15 +1,7 @@ - * Created at: 9/9/16 12:44 PM UTC+06:00 - */ namespace PHPShopify; - class ProductTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "title" => "Burton Custom Freestlye 151", "body_html" => "Good snowboard!", "vendor" => "Burton", @@ -28,18 +19,9 @@ class ProductTest extends TestSimpleResource "option1" => "Second", "price" => "20.00", "sku" => "123" - ] - ] - ); - - /** - * @inheritDoc - * Posting without title, triggers an error - */ - public $errorPostArray = array("description" => "A mystery!"); - - /** - * @inheritDoc - */ - public $putArray = array("title" => "New product title"); -} \ No newline at end of file + ], + ], + ]; + public $errorPostArray = ["description" => "A mystery!"]; + public $putArray = ["title" => "New product title"]; +} diff --git a/tests/RecurringApplicationChargeTest.php b/tests/RecurringApplicationChargeTest.php index 7bf4129..32c0bb4 100644 --- a/tests/RecurringApplicationChargeTest.php +++ b/tests/RecurringApplicationChargeTest.php @@ -1,14 +1,7 @@ - * Created at: 9/10/16 10:49 AM UTC+06:00 - */ namespace PHPShopify; - class RecurringApplicationChargeTest extends TestSimpleResource { - -} \ No newline at end of file +} diff --git a/tests/RedirectTest.php b/tests/RedirectTest.php index cbbf316..a415e61 100644 --- a/tests/RedirectTest.php +++ b/tests/RedirectTest.php @@ -1,27 +1,15 @@ - * Created at: 9/10/16 10:49 AM UTC+06:00 - */ namespace PHPShopify; - class RedirectTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "path" => "http://www.apple.com/forums", "target" => "http://forums.apple.com", - ); + ]; - /** - * @inheritDoc - */ - public $putArray = array( + public $putArray = [ "path" => "/tiger", - ); + ]; } \ No newline at end of file diff --git a/tests/ReportTest.php b/tests/ReportTest.php index 8268489..bf2e037 100644 --- a/tests/ReportTest.php +++ b/tests/ReportTest.php @@ -4,18 +4,12 @@ class ReportTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "name" => "A new app report", "shopify_ql" => "SHOW total_sales BY country FROM order SINCE -1m UNTIL today ORDER BY total_sales", - ); + ]; - /** - * @inheritDoc - */ - public $putArray = array( + public $putArray = [ "name" => "A new app report - updated", - ); -} \ No newline at end of file + ]; +} diff --git a/tests/ScriptTagTest.php b/tests/ScriptTagTest.php index 4f14923..411fbe3 100644 --- a/tests/ScriptTagTest.php +++ b/tests/ScriptTagTest.php @@ -1,27 +1,15 @@ - * Created at: 9/10/16 10:50 AM UTC+06:00 - */ namespace PHPShopify; - class ScriptTagTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "event" => "onload", "src" => "https://djavaskripped.org/fancy.js", - ); + ]; - /** - * @inheritDoc - */ - public $putArray = array( + public $putArray = [ "src" => "https://somewhere-else.com/another.js", - ); -} \ No newline at end of file + ]; +} diff --git a/tests/ShippingZoneTest.php b/tests/ShippingZoneTest.php index c71b36d..0a69a9c 100644 --- a/tests/ShippingZoneTest.php +++ b/tests/ShippingZoneTest.php @@ -1,14 +1,7 @@ - * Created at: 9/10/16 10:50 AM UTC+06:00 - */ namespace PHPShopify; - class ShippingZoneTest extends TestSimpleResource { - -} \ No newline at end of file +} diff --git a/tests/ShopTest.php b/tests/ShopTest.php index 949737d..9fe32c7 100644 --- a/tests/ShopTest.php +++ b/tests/ShopTest.php @@ -1,14 +1,7 @@ - * Created at: 9/10/16 10:50 AM UTC+06:00 - */ namespace PHPShopify; - class ShopTest extends TestSimpleResource { - -} \ No newline at end of file +} diff --git a/tests/SmartCollectionTest.php b/tests/SmartCollectionTest.php index ddb52b3..f7dd2c7 100644 --- a/tests/SmartCollectionTest.php +++ b/tests/SmartCollectionTest.php @@ -1,34 +1,25 @@ - * Created at: 9/10/16 10:52 AM UTC+06:00 - */ namespace PHPShopify; - class SmartCollectionTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( - "title" => "Macbooks", + public $postArray = [ + "title" => "McBooks", "published" => false, "rules"=> [ [ "column" => "vendor", "relation" => "equals", - "condition" => "Apple" + "condition" => "Coconut", ] ], - ); + ]; /** * @inheritDoc */ - public $putArray = array( - "body_html" => "

The best selling Macbooks ever

", - ); -} \ No newline at end of file + public $putArray = [ + "body_html" => "

The most expensive McBook ever.

", + ]; +} diff --git a/tests/ThemeTest.php b/tests/ThemeTest.php index 7901d1a..a48de98 100644 --- a/tests/ThemeTest.php +++ b/tests/ThemeTest.php @@ -1,13 +1,7 @@ - * Created at: 9/10/16 10:52 AM UTC+06:00 - */ namespace PHPShopify; - class ThemeTest extends TestSimpleResource { -} \ No newline at end of file +} diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index 390f074..6608a05 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -1,28 +1,15 @@ - * Created at: 9/10/16 10:52 AM UTC+06:00 - */ namespace PHPShopify; - class WebhookTest extends TestSimpleResource { - /** - * @inheritDoc - */ - public $postArray = array( + public $postArray = [ "topic" => "orders/create", "address" => "https://whatever.phpclassic.com/", "format" => "json" - ); - - /** - * @inheritDoc - */ - public $putArray = array( + ]; + public $putArray = [ "address" => "https://whatsoever.phpclassic.com/", - ); + ]; } From 81bd17006fb67d14200a6ae4ca84cb25e0e29e8d Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 11:29:23 +0000 Subject: [PATCH 14/29] Move tests to ShopifyResource folder. --- tests/{ => ShopifyResource}/AbandonedCheckoutTest.php | 0 tests/{ => ShopifyResource}/ApplicationChargeTest.php | 0 tests/{ => ShopifyResource}/BlogTest.php | 0 tests/{ => ShopifyResource}/CarrierServiceTest.php | 0 tests/{ => ShopifyResource}/CollectTest.php | 0 tests/{ => ShopifyResource}/CommentTest.php | 0 tests/{ => ShopifyResource}/CountryTest.php | 0 tests/{ => ShopifyResource}/CurrencyTest.php | 0 tests/{ => ShopifyResource}/CustomCollectionTest.php | 0 tests/{ => ShopifyResource}/CustomerSavedSearchTest.php | 0 tests/{ => ShopifyResource}/CustomerTest.php | 0 tests/{ => ShopifyResource}/FulfillmentServiceTest.php | 0 tests/{ => ShopifyResource}/LocationTest.php | 0 tests/{ => ShopifyResource}/MetafieldTest.php | 0 tests/{ => ShopifyResource}/OrderTest.php | 0 tests/{ => ShopifyResource}/PageTest.php | 0 tests/{ => ShopifyResource}/PolicyTest.php | 0 tests/{ => ShopifyResource}/ProductListingTest.php | 0 tests/{ => ShopifyResource}/ProductTest.php | 0 tests/{ => ShopifyResource}/RecurringApplicationChargeTest.php | 0 tests/{ => ShopifyResource}/RedirectTest.php | 0 tests/{ => ShopifyResource}/ReportTest.php | 0 tests/{ => ShopifyResource}/ScriptTagTest.php | 0 tests/{ => ShopifyResource}/ShippingZoneTest.php | 0 tests/{ => ShopifyResource}/ShopTest.php | 0 tests/{ => ShopifyResource}/SmartCollectionTest.php | 0 tests/{ => ShopifyResource}/ThemeTest.php | 0 tests/{ => ShopifyResource}/WebhookTest.php | 0 28 files changed, 0 insertions(+), 0 deletions(-) rename tests/{ => ShopifyResource}/AbandonedCheckoutTest.php (100%) rename tests/{ => ShopifyResource}/ApplicationChargeTest.php (100%) rename tests/{ => ShopifyResource}/BlogTest.php (100%) rename tests/{ => ShopifyResource}/CarrierServiceTest.php (100%) rename tests/{ => ShopifyResource}/CollectTest.php (100%) rename tests/{ => ShopifyResource}/CommentTest.php (100%) rename tests/{ => ShopifyResource}/CountryTest.php (100%) rename tests/{ => ShopifyResource}/CurrencyTest.php (100%) rename tests/{ => ShopifyResource}/CustomCollectionTest.php (100%) rename tests/{ => ShopifyResource}/CustomerSavedSearchTest.php (100%) rename tests/{ => ShopifyResource}/CustomerTest.php (100%) rename tests/{ => ShopifyResource}/FulfillmentServiceTest.php (100%) rename tests/{ => ShopifyResource}/LocationTest.php (100%) rename tests/{ => ShopifyResource}/MetafieldTest.php (100%) rename tests/{ => ShopifyResource}/OrderTest.php (100%) rename tests/{ => ShopifyResource}/PageTest.php (100%) rename tests/{ => ShopifyResource}/PolicyTest.php (100%) rename tests/{ => ShopifyResource}/ProductListingTest.php (100%) rename tests/{ => ShopifyResource}/ProductTest.php (100%) rename tests/{ => ShopifyResource}/RecurringApplicationChargeTest.php (100%) rename tests/{ => ShopifyResource}/RedirectTest.php (100%) rename tests/{ => ShopifyResource}/ReportTest.php (100%) rename tests/{ => ShopifyResource}/ScriptTagTest.php (100%) rename tests/{ => ShopifyResource}/ShippingZoneTest.php (100%) rename tests/{ => ShopifyResource}/ShopTest.php (100%) rename tests/{ => ShopifyResource}/SmartCollectionTest.php (100%) rename tests/{ => ShopifyResource}/ThemeTest.php (100%) rename tests/{ => ShopifyResource}/WebhookTest.php (100%) diff --git a/tests/AbandonedCheckoutTest.php b/tests/ShopifyResource/AbandonedCheckoutTest.php similarity index 100% rename from tests/AbandonedCheckoutTest.php rename to tests/ShopifyResource/AbandonedCheckoutTest.php diff --git a/tests/ApplicationChargeTest.php b/tests/ShopifyResource/ApplicationChargeTest.php similarity index 100% rename from tests/ApplicationChargeTest.php rename to tests/ShopifyResource/ApplicationChargeTest.php diff --git a/tests/BlogTest.php b/tests/ShopifyResource/BlogTest.php similarity index 100% rename from tests/BlogTest.php rename to tests/ShopifyResource/BlogTest.php diff --git a/tests/CarrierServiceTest.php b/tests/ShopifyResource/CarrierServiceTest.php similarity index 100% rename from tests/CarrierServiceTest.php rename to tests/ShopifyResource/CarrierServiceTest.php diff --git a/tests/CollectTest.php b/tests/ShopifyResource/CollectTest.php similarity index 100% rename from tests/CollectTest.php rename to tests/ShopifyResource/CollectTest.php diff --git a/tests/CommentTest.php b/tests/ShopifyResource/CommentTest.php similarity index 100% rename from tests/CommentTest.php rename to tests/ShopifyResource/CommentTest.php diff --git a/tests/CountryTest.php b/tests/ShopifyResource/CountryTest.php similarity index 100% rename from tests/CountryTest.php rename to tests/ShopifyResource/CountryTest.php diff --git a/tests/CurrencyTest.php b/tests/ShopifyResource/CurrencyTest.php similarity index 100% rename from tests/CurrencyTest.php rename to tests/ShopifyResource/CurrencyTest.php diff --git a/tests/CustomCollectionTest.php b/tests/ShopifyResource/CustomCollectionTest.php similarity index 100% rename from tests/CustomCollectionTest.php rename to tests/ShopifyResource/CustomCollectionTest.php diff --git a/tests/CustomerSavedSearchTest.php b/tests/ShopifyResource/CustomerSavedSearchTest.php similarity index 100% rename from tests/CustomerSavedSearchTest.php rename to tests/ShopifyResource/CustomerSavedSearchTest.php diff --git a/tests/CustomerTest.php b/tests/ShopifyResource/CustomerTest.php similarity index 100% rename from tests/CustomerTest.php rename to tests/ShopifyResource/CustomerTest.php diff --git a/tests/FulfillmentServiceTest.php b/tests/ShopifyResource/FulfillmentServiceTest.php similarity index 100% rename from tests/FulfillmentServiceTest.php rename to tests/ShopifyResource/FulfillmentServiceTest.php diff --git a/tests/LocationTest.php b/tests/ShopifyResource/LocationTest.php similarity index 100% rename from tests/LocationTest.php rename to tests/ShopifyResource/LocationTest.php diff --git a/tests/MetafieldTest.php b/tests/ShopifyResource/MetafieldTest.php similarity index 100% rename from tests/MetafieldTest.php rename to tests/ShopifyResource/MetafieldTest.php diff --git a/tests/OrderTest.php b/tests/ShopifyResource/OrderTest.php similarity index 100% rename from tests/OrderTest.php rename to tests/ShopifyResource/OrderTest.php diff --git a/tests/PageTest.php b/tests/ShopifyResource/PageTest.php similarity index 100% rename from tests/PageTest.php rename to tests/ShopifyResource/PageTest.php diff --git a/tests/PolicyTest.php b/tests/ShopifyResource/PolicyTest.php similarity index 100% rename from tests/PolicyTest.php rename to tests/ShopifyResource/PolicyTest.php diff --git a/tests/ProductListingTest.php b/tests/ShopifyResource/ProductListingTest.php similarity index 100% rename from tests/ProductListingTest.php rename to tests/ShopifyResource/ProductListingTest.php diff --git a/tests/ProductTest.php b/tests/ShopifyResource/ProductTest.php similarity index 100% rename from tests/ProductTest.php rename to tests/ShopifyResource/ProductTest.php diff --git a/tests/RecurringApplicationChargeTest.php b/tests/ShopifyResource/RecurringApplicationChargeTest.php similarity index 100% rename from tests/RecurringApplicationChargeTest.php rename to tests/ShopifyResource/RecurringApplicationChargeTest.php diff --git a/tests/RedirectTest.php b/tests/ShopifyResource/RedirectTest.php similarity index 100% rename from tests/RedirectTest.php rename to tests/ShopifyResource/RedirectTest.php diff --git a/tests/ReportTest.php b/tests/ShopifyResource/ReportTest.php similarity index 100% rename from tests/ReportTest.php rename to tests/ShopifyResource/ReportTest.php diff --git a/tests/ScriptTagTest.php b/tests/ShopifyResource/ScriptTagTest.php similarity index 100% rename from tests/ScriptTagTest.php rename to tests/ShopifyResource/ScriptTagTest.php diff --git a/tests/ShippingZoneTest.php b/tests/ShopifyResource/ShippingZoneTest.php similarity index 100% rename from tests/ShippingZoneTest.php rename to tests/ShopifyResource/ShippingZoneTest.php diff --git a/tests/ShopTest.php b/tests/ShopifyResource/ShopTest.php similarity index 100% rename from tests/ShopTest.php rename to tests/ShopifyResource/ShopTest.php diff --git a/tests/SmartCollectionTest.php b/tests/ShopifyResource/SmartCollectionTest.php similarity index 100% rename from tests/SmartCollectionTest.php rename to tests/ShopifyResource/SmartCollectionTest.php diff --git a/tests/ThemeTest.php b/tests/ShopifyResource/ThemeTest.php similarity index 100% rename from tests/ThemeTest.php rename to tests/ShopifyResource/ThemeTest.php diff --git a/tests/WebhookTest.php b/tests/ShopifyResource/WebhookTest.php similarity index 100% rename from tests/WebhookTest.php rename to tests/ShopifyResource/WebhookTest.php From 561c0c4ee2b8c411db0bdb09f1c4cd2958ce4441 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 11:35:14 +0000 Subject: [PATCH 15/29] Update test resources namespaces. --- tests/ShopifyResource/AbandonedCheckoutTest.php | 4 +++- tests/ShopifyResource/ApplicationChargeTest.php | 4 +++- tests/ShopifyResource/BlogTest.php | 8 ++------ tests/ShopifyResource/CarrierServiceTest.php | 10 +++------- tests/ShopifyResource/CollectTest.php | 3 ++- tests/ShopifyResource/CommentTest.php | 4 +++- tests/ShopifyResource/CountryTest.php | 6 ++++-- tests/ShopifyResource/CurrencyTest.php | 4 +++- tests/ShopifyResource/CustomCollectionTest.php | 4 +++- tests/ShopifyResource/CustomerSavedSearchTest.php | 4 +++- tests/ShopifyResource/CustomerTest.php | 4 +++- tests/ShopifyResource/FulfillmentServiceTest.php | 4 +++- tests/ShopifyResource/LocationTest.php | 4 +++- tests/ShopifyResource/MetafieldTest.php | 4 +++- tests/ShopifyResource/OrderTest.php | 4 +++- tests/ShopifyResource/PageTest.php | 4 +++- tests/ShopifyResource/PolicyTest.php | 4 +++- tests/ShopifyResource/ProductListingTest.php | 4 +++- tests/ShopifyResource/ProductTest.php | 4 +++- .../ShopifyResource/RecurringApplicationChargeTest.php | 4 +++- tests/ShopifyResource/RedirectTest.php | 4 +++- tests/ShopifyResource/ReportTest.php | 4 +++- tests/ShopifyResource/ScriptTagTest.php | 4 +++- tests/ShopifyResource/ShippingZoneTest.php | 4 +++- tests/ShopifyResource/ShopTest.php | 2 ++ tests/ShopifyResource/SmartCollectionTest.php | 4 +++- tests/ShopifyResource/ThemeTest.php | 4 +++- tests/ShopifyResource/WebhookTest.php | 4 +++- 28 files changed, 82 insertions(+), 39 deletions(-) diff --git a/tests/ShopifyResource/AbandonedCheckoutTest.php b/tests/ShopifyResource/AbandonedCheckoutTest.php index 8757a32..fb3731d 100644 --- a/tests/ShopifyResource/AbandonedCheckoutTest.php +++ b/tests/ShopifyResource/AbandonedCheckoutTest.php @@ -1,6 +1,8 @@ - * Created at: 9/10/16 10:43 AM UTC+06:00 - */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\TestSimpleResource; class BlogTest extends TestSimpleResource { diff --git a/tests/ShopifyResource/CarrierServiceTest.php b/tests/ShopifyResource/CarrierServiceTest.php index b01add7..2473475 100644 --- a/tests/ShopifyResource/CarrierServiceTest.php +++ b/tests/ShopifyResource/CarrierServiceTest.php @@ -1,12 +1,8 @@ - * Created at: 9/10/16 10:44 AM UTC+06:00 - */ -namespace PHPShopify; +namespace PHPShopify\ShopifyResource; +use PHPShopify\TestSimpleResource; class CarrierServiceTest extends TestSimpleResource { @@ -19,4 +15,4 @@ class CarrierServiceTest extends TestSimpleResource "name" => "Updated Shipping Rate Provider", "active" => false, ]; -} \ No newline at end of file +} diff --git a/tests/ShopifyResource/CollectTest.php b/tests/ShopifyResource/CollectTest.php index 00fe200..bb475fa 100644 --- a/tests/ShopifyResource/CollectTest.php +++ b/tests/ShopifyResource/CollectTest.php @@ -1,7 +1,8 @@ assertEquals(1, 1); } -} \ No newline at end of file +} diff --git a/tests/ShopifyResource/CurrencyTest.php b/tests/ShopifyResource/CurrencyTest.php index b1733c2..1dce5a1 100644 --- a/tests/ShopifyResource/CurrencyTest.php +++ b/tests/ShopifyResource/CurrencyTest.php @@ -1,6 +1,8 @@ Date: Mon, 9 Mar 2020 11:57:30 +0000 Subject: [PATCH 16/29] Several partial small cleanups and fixes, switches to a variants of PSR-joeyhub (brackets for classes / methods, sensible commas) which improves readability, consistency and accessibility to members of the lower classes or people with social deficit disorders that cannot fathom the need for pointless ritual. --- .gitignore | 4 ++-- .travis.yml | 2 +- README.md | 30 +++++++++++------------ lib/ShopifyResource.php | 3 ++- lib/ShopifySDK.php | 20 ++++++---------- phpunit.xml | 2 +- tests/TestResource.php | 38 +++++++++-------------------- tests/TestSimpleResource.php | 46 +++++++++--------------------------- 8 files changed, 50 insertions(+), 95 deletions(-) diff --git a/.gitignore b/.gitignore index 432b975..e4aa829 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -vendor +/vendor/ /nbproject/private/ -.idea/ \ No newline at end of file +.idea/ diff --git a/.travis.yml b/.travis.yml index d8af61b..04812b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php php: - - 7.1 + - 7.3 before_script: composer install diff --git a/README.md b/README.md index db54033..b686783 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/phpclassic/php-shopify.svg?branch=master)](https://travis-ci.org/phpclassic/php-shopify) [![Monthly Downloads](https://poser.pugx.org/phpclassic/php-shopify/d/monthly)](https://packagist.org/packages/phpclassic/php-shopify) [![Total Downloads](https://poser.pugx.org/phpclassic/php-shopify/downloads)](https://packagist.org/packages/phpclassic/php-shopify) [![Latest Stable Version](https://poser.pugx.org/phpclassic/php-shopify/v/stable)](https://packagist.org/packages/phpclassic/php-shopify) [![Latest Unstable Version](https://poser.pugx.org/phpclassic/php-shopify/v/unstable)](https://packagist.org/packages/phpclassic/php-shopify) [![License](https://poser.pugx.org/phpclassic/php-shopify/license)](https://packagist.org/packages/phpclassic/php-shopify) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ME9N6M2B87XT4¤cy_code=USD&source=url) -PHPShopify is a simple SDK implementation of Shopify API. It helps accessing the API in an object oriented way. +PHPShopify is a minimal SDK for using the Shopify API. ## Installation Install with Composer @@ -11,8 +11,8 @@ composer require phpclassic/php-shopify ``` ### Requirements -PHPShopify uses curl extension for handling http calls. So you need to have the curl extension installed and enabled with PHP. ->However if you prefer to use any other available package library for handling HTTP calls, you can easily do so by modifying 1 line in each of the `get()`, `post()`, `put()`, `delete()` methods in `PHPShopify\HttpRequestJson` class. + +PHPShopify uses curl extension for handling http calls. So you need to have the PHP curl extension installed and enabled. ## Usage @@ -22,24 +22,24 @@ You can use PHPShopify in a pretty simple object oriented way. If you are using your own private API, provide the ApiKey and Password. ```php -$config = array( +$config = [ 'ShopUrl' => 'yourshop.myshopify.com', 'ApiKey' => '***YOUR-PRIVATE-API-KEY***', - 'Password' => '***YOUR-PRIVATE-API-PASSWORD***', -); + 'Password' => '***YOUR-PRIVATE-API-PASSWORD***' +]; -PHPShopify\ShopifySDK::config($config); +$shopifyClient = new PHPShopify\ShopifySDK($config); ``` For Third party apps, use the permanent access token. ```php -$config = array( +$config = [ 'ShopUrl' => 'yourshop.myshopify.com', - 'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APP***', -); + 'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APP***' +]; -PHPShopify\ShopifySDK::config($config); +$shopifyClient = new PHPShopify\ShopifySDK($config); ``` ##### How to get the permanent access token for a shop? There is a AuthHelper class to help you getting the permanent access token from the shop using oAuth. @@ -47,13 +47,13 @@ There is a AuthHelper class to help you getting the permanent access token from 1) First, you need to configure the SDK with additional parameter SharedSecret ```php -$config = array( +$config = [ 'ShopUrl' => 'yourshop.myshopify.com', 'ApiKey' => '***YOUR-PRIVATE-API-KEY***', - 'SharedSecret' => '***YOUR-SHARED-SECRET***', -); + 'SharedSecret' => '***YOUR-SHARED-SECRET***' +]; -PHPShopify\ShopifySDK::config($config); +$shopifyClient = new PHPShopify\ShopifySDK($config); ``` 2) Create the authentication request diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 25dcfd6..1b9d488 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -111,6 +111,7 @@ public function __construct(ShopifySdk $sdk, $id = null, $parentResourceUrl = '' { $this->id = $id; $this->sdk = $sdk; + $config = $sdk->getConfig(); $this->resourceUrl = ($parentResourceUrl ? $parentResourceUrl . '/' : $config['ApiUrl']) . $this->getResourcePath() . ($this->id ? '/' . $this->id : ''); @@ -386,7 +387,7 @@ protected static function castString(array $array): string $i = 0; foreach ($array as $key => $val) { - $string .= ($i === $key ? '' : "$key - ") . $this->castString($val) . ', '; + $string .= ($i === $key ? '' : "$key - ") . self::castString($val) . ', '; $i++; } diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index d1b4771..5e5655f 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -140,8 +140,7 @@ * @method ShopifyResource\Webhook Webhook(integer $id = null) * @method ShopifyResource\GraphQL GraphQL() */ -class ShopifySDK -{ +class ShopifySDK { /** * List of available resources which can be called from this client * @@ -229,11 +228,10 @@ class ShopifySDK 'Province' => 'Country', 'Refund' => 'Order', 'Transaction' => 'Order', - 'UsageCharge' => 'RecurringApplicationCharge', + 'UsageCharge' => 'RecurringApplicationCharge' ]; - public function __construct(array $config = []) - { + public function __construct(array $config = []) { $config += ['ApiVersion' => self::$defaultApiVersion]; $shopUrl = $config['ShopUrl']; @@ -257,8 +255,7 @@ public function __construct(array $config = []) } } - public function getConfig(): array - { + public function getConfig(): array { return $this->config; } @@ -270,8 +267,7 @@ public function getConfig(): array * @param string $resourceName * @return ShopifyResource */ - public function __get($resourceName) - { + public function __get($resourceName) { return $this->$resourceName(); } @@ -287,8 +283,7 @@ public function __get($resourceName) * * @return ShopifyResource */ - public function __call($resourceName, $arguments) - { + public function __call($resourceName, $arguments) { if (!in_array($resourceName, $this->resources)) { if (isset($this->childResources[$resourceName])) { $message = "$resourceName is a child resource of " . $this->childResources[$resourceName] . ". Cannot be accessed directly."; @@ -316,8 +311,7 @@ public function __call($resourceName, $arguments) * @see https://help.shopify.com/api/guides/api-call-limit * @param bool $firstCallWait Whether to maintain the wait time even if it is the first API call */ - public static function checkApiCallLimit($firstCallWait = false): void - { + public static function checkApiCallLimit($firstCallWait = false): void { $timeToWait = 0; if (static::$microtimeOfLastApiCall == null) { diff --git a/phpunit.xml b/phpunit.xml index aeefd1a..3e65a9b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/tests/TestResource.php b/tests/TestResource.php index 1c9a268..661551a 100644 --- a/tests/TestResource.php +++ b/tests/TestResource.php @@ -1,39 +1,23 @@ - * Created at: 9/9/16 12:28 PM UTC+06:00 - */ namespace PHPShopify; -class TestResource extends \PHPUnit_Framework_TestCase -{ - /** - * @var ShopifySDK $shopify; - */ +class TestResource extends \PHPUnit_Framework_TestCase { + /** @var ShopifySDK */ public static $shopify; - /** - * @inheritDoc - */ - public static function setUpBeforeClass() - { - $config = array( - 'ShopUrl' => getenv('SHOPIFY_SHOP_URL'), //Your shop URL - 'ApiKey' => getenv('SHOPIFY_API_KEY'), //Your Private API Key - 'Password' => getenv('SHOPIFY_API_PASSWORD'), //Your Private API Password - ); + public static function setUpBeforeClass() { + $config = [ + 'ShopUrl' => getenv('SHOPIFY_SHOP_URL'), + 'ApiKey' => getenv('SHOPIFY_API_KEY'), + 'Password' => getenv('SHOPIFY_API_PASSWORD'), + ]; - self::$shopify = ShopifySDK::config($config); + self::$shopify = new ShopifySDK($config); ShopifySDK::checkApiCallLimit(); } - /** - * @inheritDoc - */ - public static function tearDownAfterClass() - { + public static function tearDownAfterClass() { self::$shopify = null; } -} \ No newline at end of file +} diff --git a/tests/TestSimpleResource.php b/tests/TestSimpleResource.php index 1e6c28a..a8741de 100644 --- a/tests/TestSimpleResource.php +++ b/tests/TestSimpleResource.php @@ -1,15 +1,8 @@ - * Created at: 9/9/16 12:38 PM UTC+06:00 - */ namespace PHPShopify; -class TestSimpleResource extends TestResource -{ - +class TestSimpleResource extends TestResource { /** * @var string Resource name */ @@ -30,48 +23,36 @@ class TestSimpleResource extends TestResource */ public $errorPostArray; - - /** - * TestSimpleResource constructor. - */ - public function __construct() - { + public function __construct() { $this->resourceName = preg_replace('/.+\\\\(\w+)Test$/', '$1', get_called_class()); parent::__construct(); } - /** - * Test post resource - * - * @return int - */ - public function testPost() - { + public function testPost(): ?int { if ($this->postArray) { $result = static::$shopify->{$this->resourceName}->post($this->postArray); $this->assertTrue(is_array($result)); $this->assertNotEmpty($result); return $result['id']; } + + return null; } /** - * Test get resource - * * @depends testPost */ - public function testGet() - { + public function testGet() { $resource = static::$shopify->{$this->resourceName}; $result = $resource->get(); $this->assertTrue(is_array($result)); - //Data posted, so cannot be empty + if($this->postArray) { $this->assertNotEmpty($result); } + if($resource->countEnabled) { - //Count should match the result array count $count = static::$shopify->{$this->resourceName}->count(); $this->assertEquals($count, count($result)); } @@ -82,8 +63,7 @@ public function testGet() * * @depends testPost */ - public function testGetSelf($id) - { + public function testGetSelf($id) { if ($id) { $product = static::$shopify->{$this->resourceName}($id)->get(); @@ -98,8 +78,7 @@ public function testGetSelf($id) * * @depends testPost */ - public function testPut($id) - { + public function testPut($id) { if ($this->putArray) { $result = static::$shopify->{$this->resourceName}($id)->put($this->putArray); $this->assertTrue(is_array($result)); @@ -111,12 +90,9 @@ public function testPut($id) } /** - * Test delete resource - * * @depends testPost */ - public function testDelete($id) - { + public function testDelete($id) { if ($id) { $result = static::$shopify->{$this->resourceName}($id)->delete(); $this->assertEmpty($result); From 866656731dcb41555bd0bf498144f3fb0cb56dee Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 12:00:49 +0000 Subject: [PATCH 17/29] Add consistent formatting to tests. --- tests/ShopifyResource/AbandonedCheckoutTest.php | 3 +-- tests/ShopifyResource/ApplicationChargeTest.php | 3 +-- tests/ShopifyResource/BlogTest.php | 7 +++---- tests/ShopifyResource/CarrierServiceTest.php | 5 ++--- tests/ShopifyResource/CollectTest.php | 3 +-- tests/ShopifyResource/CommentTest.php | 3 +-- tests/ShopifyResource/CountryTest.php | 10 ++++------ tests/ShopifyResource/CurrencyTest.php | 3 +-- tests/ShopifyResource/CustomCollectionTest.php | 7 +++---- tests/ShopifyResource/CustomerSavedSearchTest.php | 7 +++---- tests/ShopifyResource/CustomerTest.php | 10 ++++------ tests/ShopifyResource/FulfillmentServiceTest.php | 7 +++---- tests/ShopifyResource/LocationTest.php | 3 +-- tests/ShopifyResource/MetafieldTest.php | 7 +++---- tests/ShopifyResource/OrderTest.php | 3 +-- tests/ShopifyResource/PageTest.php | 5 ++--- tests/ShopifyResource/PolicyTest.php | 3 +-- tests/ShopifyResource/ProductListingTest.php | 3 +-- tests/ShopifyResource/ProductTest.php | 7 +++---- .../RecurringApplicationChargeTest.php | 3 +-- tests/ShopifyResource/RedirectTest.php | 7 +++---- tests/ShopifyResource/ReportTest.php | 7 +++---- tests/ShopifyResource/ScriptTagTest.php | 7 +++---- tests/ShopifyResource/ShippingZoneTest.php | 3 +-- tests/ShopifyResource/ShopTest.php | 3 +-- tests/ShopifyResource/SmartCollectionTest.php | 13 ++++--------- tests/ShopifyResource/ThemeTest.php | 3 +-- tests/ShopifyResource/WebhookTest.php | 5 ++--- 28 files changed, 58 insertions(+), 92 deletions(-) diff --git a/tests/ShopifyResource/AbandonedCheckoutTest.php b/tests/ShopifyResource/AbandonedCheckoutTest.php index fb3731d..1732814 100644 --- a/tests/ShopifyResource/AbandonedCheckoutTest.php +++ b/tests/ShopifyResource/AbandonedCheckoutTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class AbandonedCheckoutTest extends TestSimpleResource -{ +class AbandonedCheckoutTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/ApplicationChargeTest.php b/tests/ShopifyResource/ApplicationChargeTest.php index c81f99c..fa342f9 100644 --- a/tests/ShopifyResource/ApplicationChargeTest.php +++ b/tests/ShopifyResource/ApplicationChargeTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class ApplicationChargeTest extends TestSimpleResource -{ +class ApplicationChargeTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/BlogTest.php b/tests/ShopifyResource/BlogTest.php index 56fae67..d271ed8 100644 --- a/tests/ShopifyResource/BlogTest.php +++ b/tests/ShopifyResource/BlogTest.php @@ -4,12 +4,11 @@ use PHPShopify\TestSimpleResource; -class BlogTest extends TestSimpleResource -{ +class BlogTest extends TestSimpleResource { public $postArray = [ - "title" => "PHPShopify Test Blog", + "title" => "PHPShopify Test Blog" ]; public $putArray = [ - "title" => "PHPShopify Test Blog Modified", + "title" => "PHPShopify Test Blog Modified" ]; } diff --git a/tests/ShopifyResource/CarrierServiceTest.php b/tests/ShopifyResource/CarrierServiceTest.php index 2473475..29a7bae 100644 --- a/tests/ShopifyResource/CarrierServiceTest.php +++ b/tests/ShopifyResource/CarrierServiceTest.php @@ -4,8 +4,7 @@ use PHPShopify\TestSimpleResource; -class CarrierServiceTest extends TestSimpleResource -{ +class CarrierServiceTest extends TestSimpleResource { public $postArray = [ "name" => "Shipping Rate Provider", "callback_url" => "http://shippingrateprovider.com", @@ -13,6 +12,6 @@ class CarrierServiceTest extends TestSimpleResource ]; public $putArray = [ "name" => "Updated Shipping Rate Provider", - "active" => false, + "active" => false ]; } diff --git a/tests/ShopifyResource/CollectTest.php b/tests/ShopifyResource/CollectTest.php index bb475fa..5767d24 100644 --- a/tests/ShopifyResource/CollectTest.php +++ b/tests/ShopifyResource/CollectTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class CollectTest extends TestSimpleResource -{ +class CollectTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/CommentTest.php b/tests/ShopifyResource/CommentTest.php index 83af556..57497b3 100644 --- a/tests/ShopifyResource/CommentTest.php +++ b/tests/ShopifyResource/CommentTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class CommentTest extends TestSimpleResource -{ +class CommentTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/CountryTest.php b/tests/ShopifyResource/CountryTest.php index e79574d..1c7ee39 100644 --- a/tests/ShopifyResource/CountryTest.php +++ b/tests/ShopifyResource/CountryTest.php @@ -4,19 +4,17 @@ use PHPShopify\TestSimpleResource; -class CountryTest extends TestSimpleResource -{ +class CountryTest extends TestSimpleResource { public $postArray = [ "code" => "BD", - "tax" => 0.25, + "tax" => 0.25 ]; public $putArray = [ - "tax" => 0.01, + "tax" => 0.01 ]; - public function testGet() - { + public function testGet() { $this->assertEquals(1, 1); } } diff --git a/tests/ShopifyResource/CurrencyTest.php b/tests/ShopifyResource/CurrencyTest.php index 1dce5a1..a6f28c8 100644 --- a/tests/ShopifyResource/CurrencyTest.php +++ b/tests/ShopifyResource/CurrencyTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class CurrencyTest extends TestSimpleResource -{ +class CurrencyTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/CustomCollectionTest.php b/tests/ShopifyResource/CustomCollectionTest.php index ce89f69..7361a77 100644 --- a/tests/ShopifyResource/CustomCollectionTest.php +++ b/tests/ShopifyResource/CustomCollectionTest.php @@ -4,13 +4,12 @@ use PHPShopify\TestSimpleResource; -class CustomCollectionTest extends TestSimpleResource -{ +class CustomCollectionTest extends TestSimpleResource { public $postArray = [ - "title" => "Macbooks", + "title" => "Macbooks" ]; public $putArray = [ "title" => "Updated - Macbooks", - "body_html" => "

The best selling Macbooks ever

", + "body_html" => "

The best selling Macbooks ever

" ]; } diff --git a/tests/ShopifyResource/CustomerSavedSearchTest.php b/tests/ShopifyResource/CustomerSavedSearchTest.php index 8962f44..ac294a1 100644 --- a/tests/ShopifyResource/CustomerSavedSearchTest.php +++ b/tests/ShopifyResource/CustomerSavedSearchTest.php @@ -4,13 +4,12 @@ use PHPShopify\TestSimpleResource; -class CustomerSavedSearchTest extends TestSimpleResource -{ +class CustomerSavedSearchTest extends TestSimpleResource { public $postArray = [ "name" => "Spent more than $50 and after 2015", - "query" => "total_spent:>50 order_date:>=2015-01-01", + "query" => "total_spent:>50 order_date:>=2015-01-01" ]; public $putArray = [ - "name" => "This Name Has Been Changed", + "name" => "This Name Has Been Changed" ]; } diff --git a/tests/ShopifyResource/CustomerTest.php b/tests/ShopifyResource/CustomerTest.php index d949253..7549521 100644 --- a/tests/ShopifyResource/CustomerTest.php +++ b/tests/ShopifyResource/CustomerTest.php @@ -4,19 +4,17 @@ use PHPShopify\TestSimpleResource; -class CustomerTest extends TestSimpleResource -{ +class CustomerTest extends TestSimpleResource { public $postArray = [ "first_name" => "Steve", "last_name" => "Lastnameson", - "email" => "steve.lastnameson@example.com", + "email" => "steve.lastnameson@example.com" ]; public $putArray = [ - "verified_email" => true, + "verified_email" => true ]; - public function testGet() - { + public function testGet() { $this->assertEquals(1, 1); } } diff --git a/tests/ShopifyResource/FulfillmentServiceTest.php b/tests/ShopifyResource/FulfillmentServiceTest.php index 62d9d57..d278a29 100644 --- a/tests/ShopifyResource/FulfillmentServiceTest.php +++ b/tests/ShopifyResource/FulfillmentServiceTest.php @@ -4,18 +4,17 @@ use PHPShopify\TestSimpleResource; -class FulfillmentServiceTest extends TestSimpleResource -{ +class FulfillmentServiceTest extends TestSimpleResource { public $postArray = [ "name" => "MarsFulfillment", "callback_url" => "http://google.com", "inventory_management" => true, "tracking_support" => true, "requires_shipping_method" => true, - "format" => "json", + "format" => "json" ]; public $putArray = [ - "tracking_support" => false, + "tracking_support" => false ]; } diff --git a/tests/ShopifyResource/LocationTest.php b/tests/ShopifyResource/LocationTest.php index 9291886..f25f839 100644 --- a/tests/ShopifyResource/LocationTest.php +++ b/tests/ShopifyResource/LocationTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class LocationTest extends TestSimpleResource -{ +class LocationTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/MetafieldTest.php b/tests/ShopifyResource/MetafieldTest.php index 159364f..398af54 100644 --- a/tests/ShopifyResource/MetafieldTest.php +++ b/tests/ShopifyResource/MetafieldTest.php @@ -4,17 +4,16 @@ use PHPShopify\TestSimpleResource; -class MetafieldTest extends TestSimpleResource -{ +class MetafieldTest extends TestSimpleResource { public $postArray = [ "namespace" => "inventory", "key" => "warehouse", "value" => 25, - "value_type" => "integer", + "value_type" => "integer" ]; public $putArray = [ "value" => "something new", - "value_type" => "string", + "value_type" => "string" ]; } diff --git a/tests/ShopifyResource/OrderTest.php b/tests/ShopifyResource/OrderTest.php index 117aa16..69f9e23 100644 --- a/tests/ShopifyResource/OrderTest.php +++ b/tests/ShopifyResource/OrderTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class OrderTest extends TestSimpleResource -{ +class OrderTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/PageTest.php b/tests/ShopifyResource/PageTest.php index 6859c75..2025022 100644 --- a/tests/ShopifyResource/PageTest.php +++ b/tests/ShopifyResource/PageTest.php @@ -4,11 +4,10 @@ use PHPShopify\TestSimpleResource; -class PageTest extends TestSimpleResource -{ +class PageTest extends TestSimpleResource { public $postArray = [ "title" => "Warranty information", - "body_html" => "

Warranty

\n

Forget it, we ain't giving you nothing

", + "body_html" => "

Warranty

\n

Forget it, we ain't giving you nothing

" ]; public $putArray = [ "title" => "Updated Warranty information" diff --git a/tests/ShopifyResource/PolicyTest.php b/tests/ShopifyResource/PolicyTest.php index b4206ea..0f2df92 100644 --- a/tests/ShopifyResource/PolicyTest.php +++ b/tests/ShopifyResource/PolicyTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class PolicyTest extends TestSimpleResource -{ +class PolicyTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/ProductListingTest.php b/tests/ShopifyResource/ProductListingTest.php index 1b98861..5981a3d 100644 --- a/tests/ShopifyResource/ProductListingTest.php +++ b/tests/ShopifyResource/ProductListingTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class ProductListingTest extends TestSimpleResource -{ +class ProductListingTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/ProductTest.php b/tests/ShopifyResource/ProductTest.php index 7e49414..d667f16 100644 --- a/tests/ShopifyResource/ProductTest.php +++ b/tests/ShopifyResource/ProductTest.php @@ -4,8 +4,7 @@ use PHPShopify\TestSimpleResource; -class ProductTest extends TestSimpleResource -{ +class ProductTest extends TestSimpleResource { public $postArray = [ "title" => "Burton Custom Freestlye 151", "body_html" => "Good snowboard!", @@ -21,8 +20,8 @@ class ProductTest extends TestSimpleResource "option1" => "Second", "price" => "20.00", "sku" => "123" - ], - ], + ] + ] ]; public $errorPostArray = ["description" => "A mystery!"]; public $putArray = ["title" => "New product title"]; diff --git a/tests/ShopifyResource/RecurringApplicationChargeTest.php b/tests/ShopifyResource/RecurringApplicationChargeTest.php index c243df1..508c78c 100644 --- a/tests/ShopifyResource/RecurringApplicationChargeTest.php +++ b/tests/ShopifyResource/RecurringApplicationChargeTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class RecurringApplicationChargeTest extends TestSimpleResource -{ +class RecurringApplicationChargeTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/RedirectTest.php b/tests/ShopifyResource/RedirectTest.php index 497a951..feee0cc 100644 --- a/tests/ShopifyResource/RedirectTest.php +++ b/tests/ShopifyResource/RedirectTest.php @@ -4,14 +4,13 @@ use PHPShopify\TestSimpleResource; -class RedirectTest extends TestSimpleResource -{ +class RedirectTest extends TestSimpleResource { public $postArray = [ "path" => "http://www.apple.com/forums", - "target" => "http://forums.apple.com", + "target" => "http://forums.apple.com" ]; public $putArray = [ - "path" => "/tiger", + "path" => "/tiger" ]; } \ No newline at end of file diff --git a/tests/ShopifyResource/ReportTest.php b/tests/ShopifyResource/ReportTest.php index bfe792e..b9c783c 100644 --- a/tests/ShopifyResource/ReportTest.php +++ b/tests/ShopifyResource/ReportTest.php @@ -4,14 +4,13 @@ use PHPShopify\TestSimpleResource; -class ReportTest extends TestSimpleResource -{ +class ReportTest extends TestSimpleResource { public $postArray = [ "name" => "A new app report", - "shopify_ql" => "SHOW total_sales BY country FROM order SINCE -1m UNTIL today ORDER BY total_sales", + "shopify_ql" => "SHOW total_sales BY country FROM order SINCE -1m UNTIL today ORDER BY total_sales" ]; public $putArray = [ - "name" => "A new app report - updated", + "name" => "A new app report - updated" ]; } diff --git a/tests/ShopifyResource/ScriptTagTest.php b/tests/ShopifyResource/ScriptTagTest.php index 39d5485..4c4d847 100644 --- a/tests/ShopifyResource/ScriptTagTest.php +++ b/tests/ShopifyResource/ScriptTagTest.php @@ -4,14 +4,13 @@ use PHPShopify\TestSimpleResource; -class ScriptTagTest extends TestSimpleResource -{ +class ScriptTagTest extends TestSimpleResource { public $postArray = [ "event" => "onload", - "src" => "https://djavaskripped.org/fancy.js", + "src" => "https://djavaskripped.org/fancy.js" ]; public $putArray = [ - "src" => "https://somewhere-else.com/another.js", + "src" => "https://somewhere-else.com/another.js" ]; } diff --git a/tests/ShopifyResource/ShippingZoneTest.php b/tests/ShopifyResource/ShippingZoneTest.php index 3af4ba6..fffe123 100644 --- a/tests/ShopifyResource/ShippingZoneTest.php +++ b/tests/ShopifyResource/ShippingZoneTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class ShippingZoneTest extends TestSimpleResource -{ +class ShippingZoneTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/ShopTest.php b/tests/ShopifyResource/ShopTest.php index 6ff45cc..4278225 100644 --- a/tests/ShopifyResource/ShopTest.php +++ b/tests/ShopifyResource/ShopTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class ShopTest extends TestSimpleResource -{ +class ShopTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/SmartCollectionTest.php b/tests/ShopifyResource/SmartCollectionTest.php index 0701336..759009b 100644 --- a/tests/ShopifyResource/SmartCollectionTest.php +++ b/tests/ShopifyResource/SmartCollectionTest.php @@ -4,8 +4,7 @@ use PHPShopify\TestSimpleResource; -class SmartCollectionTest extends TestSimpleResource -{ +class SmartCollectionTest extends TestSimpleResource { public $postArray = [ "title" => "McBooks", "published" => false, @@ -13,15 +12,11 @@ class SmartCollectionTest extends TestSimpleResource [ "column" => "vendor", "relation" => "equals", - "condition" => "Coconut", + "condition" => "Coconut" ] - ], + ] ]; - - /** - * @inheritDoc - */ public $putArray = [ - "body_html" => "

The most expensive McBook ever.

", + "body_html" => "

The most expensive McBook ever.

" ]; } diff --git a/tests/ShopifyResource/ThemeTest.php b/tests/ShopifyResource/ThemeTest.php index 09c6748..97e8fe2 100644 --- a/tests/ShopifyResource/ThemeTest.php +++ b/tests/ShopifyResource/ThemeTest.php @@ -4,6 +4,5 @@ use PHPShopify\TestSimpleResource; -class ThemeTest extends TestSimpleResource -{ +class ThemeTest extends TestSimpleResource { } diff --git a/tests/ShopifyResource/WebhookTest.php b/tests/ShopifyResource/WebhookTest.php index 98632a2..77caf38 100644 --- a/tests/ShopifyResource/WebhookTest.php +++ b/tests/ShopifyResource/WebhookTest.php @@ -4,14 +4,13 @@ use PHPShopify\TestSimpleResource; -class WebhookTest extends TestSimpleResource -{ +class WebhookTest extends TestSimpleResource { public $postArray = [ "topic" => "orders/create", "address" => "https://whatever.phpclassic.com/", "format" => "json" ]; public $putArray = [ - "address" => "https://whatsoever.phpclassic.com/", + "address" => "https://whatsoever.phpclassic.com/" ]; } From 10df66f0902ef4ca68f20e112940df8a0db9f330 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 13:24:35 +0000 Subject: [PATCH 18/29] Apply consistent style to shopify resources. --- LICENSE | 6 ++++ lib/Exception/ApiException.php | 12 ++------ lib/Exception/CurlException.php | 11 ++----- lib/Exception/ResourceRateLimitException.php | 4 +-- lib/Exception/SdkException.php | 11 ++----- lib/Http/CurlRequest.php | 30 +++++++------------ lib/Http/CurlResponse.php | 18 ++++------- lib/Http/HttpRequestJson.php | 12 +++----- lib/ShopifyResource/AbandonedCheckout.php | 3 +- lib/ShopifyResource/ApplicationCharge.php | 5 ++-- lib/ShopifyResource/Article.php | 5 ++-- lib/ShopifyResource/Asset.php | 3 +- lib/ShopifyResource/Blog.php | 5 ++-- lib/ShopifyResource/CarrierService.php | 3 +- lib/ShopifyResource/Collect.php | 3 +- lib/ShopifyResource/Comment.php | 7 ++--- lib/ShopifyResource/Country.php | 8 ++--- lib/ShopifyResource/Currency.php | 6 ++-- lib/ShopifyResource/CustomCollection.php | 5 ++-- lib/ShopifyResource/Customer.php | 8 ++--- lib/ShopifyResource/CustomerAddress.php | 11 +++---- lib/ShopifyResource/CustomerSavedSearch.php | 8 ++--- lib/ShopifyResource/Discount.php | 5 ++-- lib/ShopifyResource/DiscountCode.php | 5 ++-- lib/ShopifyResource/DraftOrder.php | 7 ++--- lib/ShopifyResource/Event.php | 3 +- lib/ShopifyResource/Fulfillment.php | 7 ++--- lib/ShopifyResource/FulfillmentEvent.php | 9 ++---- lib/ShopifyResource/FulfillmentService.php | 3 +- lib/ShopifyResource/GiftCard.php | 8 ++--- lib/ShopifyResource/GraphQL.php | 18 ++++------- lib/ShopifyResource/InventoryItem.php | 3 +- lib/ShopifyResource/InventoryLevel.php | 5 ++-- lib/ShopifyResource/Location.php | 5 ++-- lib/ShopifyResource/Metafield.php | 3 +- lib/ShopifyResource/Multipass.php | 6 ++-- lib/ShopifyResource/Order.php | 7 ++--- lib/ShopifyResource/OrderRisk.php | 3 +- lib/ShopifyResource/Page.php | 5 ++-- lib/ShopifyResource/Policy.php | 6 ++-- lib/ShopifyResource/PriceRule.php | 5 ++-- lib/ShopifyResource/Product.php | 5 ++-- lib/ShopifyResource/ProductImage.php | 3 +- lib/ShopifyResource/ProductListing.php | 5 ++-- lib/ShopifyResource/ProductVariant.php | 5 ++-- lib/ShopifyResource/Province.php | 3 +- .../RecurringApplicationCharge.php | 10 +++---- lib/ShopifyResource/Redirect.php | 3 +- lib/ShopifyResource/Refund.php | 5 ++-- lib/ShopifyResource/Report.php | 3 +- lib/ShopifyResource/ScriptTag.php | 3 +- lib/ShopifyResource/ShippingZone.php | 3 +- lib/ShopifyResource/Shop.php | 6 ++-- lib/ShopifyResource/SmartCollection.php | 8 ++--- lib/ShopifyResource/Theme.php | 5 ++-- lib/ShopifyResource/Transaction.php | 3 +- lib/ShopifyResource/UsageCharge.php | 3 +- lib/ShopifyResource/User.php | 5 ++-- lib/ShopifyResource/Webhook.php | 3 +- 59 files changed, 135 insertions(+), 243 deletions(-) diff --git a/LICENSE b/LICENSE index 8dada3e..04b10a7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,9 @@ +/** + * This license applies to all files within this code base. + * This license must be attached if files are moved out of this codebase. + * @copyright Tareq Mahmood + */ + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ diff --git a/lib/Exception/ApiException.php b/lib/Exception/ApiException.php index 9acf168..325c016 100644 --- a/lib/Exception/ApiException.php +++ b/lib/Exception/ApiException.php @@ -1,14 +1,6 @@ - * Created at 8/19/16 10:28 AM UTC+06:00 - */ namespace PHPShopify\Exception; - -class ApiException extends \Exception -{ - -} \ No newline at end of file +class ApiException extends \Exception { +} diff --git a/lib/Exception/CurlException.php b/lib/Exception/CurlException.php index fe00e8f..f16c8e4 100644 --- a/lib/Exception/CurlException.php +++ b/lib/Exception/CurlException.php @@ -1,13 +1,6 @@ - * Created at 8/19/16 10:26 AM UTC+06:00 - */ namespace PHPShopify\Exception; -class CurlException extends \Exception -{ - -} \ No newline at end of file +class CurlException extends \Exception { +} diff --git a/lib/Exception/ResourceRateLimitException.php b/lib/Exception/ResourceRateLimitException.php index 1e7843d..99b51dd 100644 --- a/lib/Exception/ResourceRateLimitException.php +++ b/lib/Exception/ResourceRateLimitException.php @@ -2,7 +2,5 @@ namespace PHPShopify\Exception; -class ResourceRateLimitException extends ApiException -{ - +class ResourceRateLimitException extends ApiException { } diff --git a/lib/Exception/SdkException.php b/lib/Exception/SdkException.php index 343ca46..9d7e08e 100644 --- a/lib/Exception/SdkException.php +++ b/lib/Exception/SdkException.php @@ -1,13 +1,6 @@ - * Created at 8/19/16 10:29 AM UTC+06:00 - */ namespace PHPShopify\Exception; -class SdkException extends \Exception -{ - -} \ No newline at end of file +class SdkException extends \Exception { +} diff --git a/lib/Http/CurlRequest.php b/lib/Http/CurlRequest.php index c3525ab..bffd588 100644 --- a/lib/Http/CurlRequest.php +++ b/lib/Http/CurlRequest.php @@ -5,8 +5,7 @@ use PHPShopify\Exception\CurlException; use PHPShopify\Exception\ResourceRateLimitException; -class CurlRequest -{ +class CurlRequest { /** * The time wait before retrying when the request was rate limited in microseconds. */ @@ -23,8 +22,7 @@ class CurlRequest * @param string|string[]|null $data * @return resource */ - protected static function init(string $method, string $url, array $httpHeaders = [], $data = null) - { + protected static function init(string $method, string $url, array $httpHeaders = [], $data = null) { if (self::$ch === null) { self::$ch = curl_init(); @@ -54,8 +52,7 @@ protected static function init(string $method, string $url, array $httpHeaders = return self::$ch; } - public static function destroy(): void - { + public static function destroy(): void { if (self::$ch !== null) { $ch = self::$ch; self::$ch = null; @@ -63,8 +60,7 @@ public static function destroy(): void } } - public static function get(string $url, array $httpHeaders = []): CurlResponse - { + public static function get(string $url, array $httpHeaders = []): CurlResponse { return self::processRequest(self::init('GET', $url, $httpHeaders)); } @@ -72,18 +68,15 @@ public static function get(string $url, array $httpHeaders = []): CurlResponse * @inheritDoc * @param string|array $data */ - public static function post(string $url, $data, array $httpHeaders = []): CurlResponse - { + public static function post(string $url, $data, array $httpHeaders = []): CurlResponse { return self::processRequest(self::init('POST', $url, $httpHeaders, $data)); } - public static function put($url, $data, array $httpHeaders = []): CurlResponse - { + public static function put($url, $data, array $httpHeaders = []): CurlResponse { return self::processRequest(self::init('PUT', $url, $httpHeaders, $data)); } - public static function delete(string $url, array $httpHeaders = []): CurlResponse - { + public static function delete(string $url, array $httpHeaders = []): CurlResponse { return self::processRequest(self::init('DELETE', $url, $httpHeaders)); } @@ -92,8 +85,7 @@ public static function delete(string $url, array $httpHeaders = []): CurlRespons * @param resource $ch * @throws CurlException if curl request is failed with error */ - protected static function processRequest($ch): CurlResponse - { + protected static function processRequest($ch): CurlResponse { # Check for 429 leaky bucket error while (true) { $output = curl_exec($ch); @@ -125,8 +117,7 @@ protected static function processRequest($ch): CurlResponse return $response; } - private static function parseResponse(string $response): array - { + private static function parseResponse(string $response): array { $response = explode("\r\n\r\n", $response, 2); $headers = []; @@ -148,8 +139,7 @@ private static function parseResponse(string $response): array return compact('headers', 'body'); } - protected static function parseBody(string $body) - { + protected static function parseBody(string $body) { return $body; } } diff --git a/lib/Http/CurlResponse.php b/lib/Http/CurlResponse.php index 2f02533..70322c1 100644 --- a/lib/Http/CurlResponse.php +++ b/lib/Http/CurlResponse.php @@ -2,38 +2,32 @@ namespace PHPShopify\Http; -class CurlResponse -{ +class CurlResponse { /** @var int */ private $status; /** @var array */ private $headers = []; private $body; - public function __construct(int $status, array $headers, $body) - { + public function __construct(int $status, array $headers, $body) { $this->status = $status; $this->headers = $headers; $this->body = $body; } - public function getHeader(string $key): ?string - { + public function getHeader(string $key): ?string { return $this->headers[$key] ?? null; } - public function getBody() - { + public function getBody() { return $this->body; } - public function getStatus(): int - { + public function getStatus(): int { return $this->status; } - public function __toString() - { + public function __toString() { $body = $this->getBody(); $body = $body ? : ''; diff --git a/lib/Http/HttpRequestJson.php b/lib/Http/HttpRequestJson.php index 6a11ba5..3c3a979 100644 --- a/lib/Http/HttpRequestJson.php +++ b/lib/Http/HttpRequestJson.php @@ -2,10 +2,8 @@ namespace PHPShopify\Http; -class HttpRequestJson extends CurlRequest -{ - protected static function init(string $method, string $url, array $httpHeaders = [], $data = null) - { +class HttpRequestJson extends CurlRequest { + protected static function init(string $method, string $url, array $httpHeaders = [], $data = null) { // Note: Is null valid for any shopify calls? if ($data !== null) { $httpHeaders['Content-type'] = 'application/json'; @@ -15,13 +13,11 @@ protected static function init(string $method, string $url, array $httpHeaders = return parent::init($method, $url, $httpHeaders, $data); } - protected static function parseBody(string $body) - { + protected static function parseBody(string $body) { return json_decode($body, true); } - public static function encode($data): string - { + public static function encode($data): string { return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } } diff --git a/lib/ShopifyResource/AbandonedCheckout.php b/lib/ShopifyResource/AbandonedCheckout.php index f8908d4..acf87a9 100644 --- a/lib/ShopifyResource/AbandonedCheckout.php +++ b/lib/ShopifyResource/AbandonedCheckout.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class AbandonedCheckout extends ShopifyResource -{ +class AbandonedCheckout extends ShopifyResource { protected $resourceKey = 'checkout'; } diff --git a/lib/ShopifyResource/ApplicationCharge.php b/lib/ShopifyResource/ApplicationCharge.php index 786741e..0c30d6d 100644 --- a/lib/ShopifyResource/ApplicationCharge.php +++ b/lib/ShopifyResource/ApplicationCharge.php @@ -7,11 +7,10 @@ use PHPShopify\ShopifyResource; -class ApplicationCharge extends ShopifyResource -{ +class ApplicationCharge extends ShopifyResource { protected $resourceKey = 'application_charge'; public $countEnabled = false; protected $customPostActions = [ - 'activate', + 'activate' ]; } diff --git a/lib/ShopifyResource/Article.php b/lib/ShopifyResource/Article.php index d127861..eee1db4 100644 --- a/lib/ShopifyResource/Article.php +++ b/lib/ShopifyResource/Article.php @@ -13,11 +13,10 @@ * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) */ -class Article extends ShopifyResource -{ +class Article extends ShopifyResource { protected $resourceKey = 'article'; protected $childResource = [ 'Event', - 'Metafield', + 'Metafield' ]; } diff --git a/lib/ShopifyResource/Asset.php b/lib/ShopifyResource/Asset.php index a0e9776..ff8fe53 100644 --- a/lib/ShopifyResource/Asset.php +++ b/lib/ShopifyResource/Asset.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class Asset extends ShopifyResource -{ +class Asset extends ShopifyResource { protected $resourceKey = 'asset'; } diff --git a/lib/ShopifyResource/Blog.php b/lib/ShopifyResource/Blog.php index e55e2b5..eb97878 100644 --- a/lib/ShopifyResource/Blog.php +++ b/lib/ShopifyResource/Blog.php @@ -15,12 +15,11 @@ * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) */ -class Blog extends ShopifyResource -{ +class Blog extends ShopifyResource { public $resourceKey = 'blog'; protected $childResource = [ 'Article', 'Event', - 'Metafield', + 'Metafield' ]; } diff --git a/lib/ShopifyResource/CarrierService.php b/lib/ShopifyResource/CarrierService.php index 0e6951f..7def025 100644 --- a/lib/ShopifyResource/CarrierService.php +++ b/lib/ShopifyResource/CarrierService.php @@ -7,8 +7,7 @@ use PHPShopify\ShopifyResource; -class CarrierService extends ShopifyResource -{ +class CarrierService extends ShopifyResource { protected $resourceKey = 'carrier_service'; public $countEnabled = false; } diff --git a/lib/ShopifyResource/Collect.php b/lib/ShopifyResource/Collect.php index 6b855b5..22c0578 100644 --- a/lib/ShopifyResource/Collect.php +++ b/lib/ShopifyResource/Collect.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class Collect extends ShopifyResource -{ +class Collect extends ShopifyResource { protected $resourceKey = 'collect'; } diff --git a/lib/ShopifyResource/Comment.php b/lib/ShopifyResource/Comment.php index c907c6a..f4065fc 100644 --- a/lib/ShopifyResource/Comment.php +++ b/lib/ShopifyResource/Comment.php @@ -16,11 +16,10 @@ * @method array remove() Remove a Comment * @method array restore() Restore a Comment */ -class Comment extends ShopifyResource -{ +class Comment extends ShopifyResource { protected $resourceKey = 'comment'; protected $childResource = [ - 'Event', + 'Event' ]; protected $customPostActions = [ @@ -28,6 +27,6 @@ class Comment extends ShopifyResource 'not_spam' => 'markNotSpam', 'approve', 'remove', - 'restore', + 'restore' ]; } diff --git a/lib/ShopifyResource/Country.php b/lib/ShopifyResource/Country.php index ab77ff2..f444a07 100644 --- a/lib/ShopifyResource/Country.php +++ b/lib/ShopifyResource/Country.php @@ -16,15 +16,13 @@ * @method Province Province(integer $id = null) * */ -class Country extends ShopifyResource -{ +class Country extends ShopifyResource { protected $resourceKey = 'country'; protected $childResource = [ - 'Province', + 'Province' ]; - protected function pluralizeKey() - { + protected function pluralizeKey() { return 'countries'; } } diff --git a/lib/ShopifyResource/Currency.php b/lib/ShopifyResource/Currency.php index 34e9eeb..2cba76d 100644 --- a/lib/ShopifyResource/Currency.php +++ b/lib/ShopifyResource/Currency.php @@ -7,14 +7,12 @@ use PHPShopify\ShopifyResource; -class Currency extends ShopifyResource -{ +class Currency extends ShopifyResource { protected $resourceKey = 'currency'; public $countEnabled = false; public $readOnly = true; - public function pluralizeKey() - { + public function pluralizeKey() { return 'currencies'; } } diff --git a/lib/ShopifyResource/CustomCollection.php b/lib/ShopifyResource/CustomCollection.php index 1aa4cdc..135edc3 100644 --- a/lib/ShopifyResource/CustomCollection.php +++ b/lib/ShopifyResource/CustomCollection.php @@ -13,11 +13,10 @@ * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) */ -class CustomCollection extends ShopifyResource -{ +class CustomCollection extends ShopifyResource { protected $resourceKey = 'custom_collection'; protected $childResource = [ 'Event', - 'Metafield', + 'Metafield' ]; } diff --git a/lib/ShopifyResource/Customer.php b/lib/ShopifyResource/Customer.php index 5582fd8..ccab2b8 100644 --- a/lib/ShopifyResource/Customer.php +++ b/lib/ShopifyResource/Customer.php @@ -14,18 +14,16 @@ * @method Metafield Metafield(integer $id = null) * @method array search() Search for customers matching supplied query */ -class Customer extends ShopifyResource -{ +class Customer extends ShopifyResource { protected $resourceKey ='customer'; public $searchEnabled = true; protected $childResource = [ 'CustomerAddress' => 'Address', 'Metafield', - 'Order', + 'Order' ]; - public function send_invite(array $customer_invite = []): array - { + public function send_invite(array $customer_invite = []): array { if (empty ( $customer_invite ) ) $customer_invite = new \stdClass(); $url = $this->generateUrl([], 'send_invite'); $dataArray = $this->wrapData($customer_invite, 'customer_invite'); diff --git a/lib/ShopifyResource/CustomerAddress.php b/lib/ShopifyResource/CustomerAddress.php index 6ac816d..0a9c814 100644 --- a/lib/ShopifyResource/CustomerAddress.php +++ b/lib/ShopifyResource/CustomerAddress.php @@ -10,15 +10,13 @@ /** * @method array makeDefault() Sets the address as default for the customer */ -class CustomerAddress extends ShopifyResource -{ +class CustomerAddress extends ShopifyResource { protected $resourceKey = 'address'; protected $customPutActions = [ - 'default' => 'makeDefault', + 'default' => 'makeDefault' ]; - protected function pluralizeKey() - { + protected function pluralizeKey() { return 'addresses'; } @@ -28,8 +26,7 @@ protected function pluralizeKey() * @param array $params * @return array */ - public function set(array $params): array - { + public function set(array $params): array { $url = $this->generateUrl($params, 'set'); return $this->put([], $url); diff --git a/lib/ShopifyResource/CustomerSavedSearch.php b/lib/ShopifyResource/CustomerSavedSearch.php index 1a84e40..c18101d 100644 --- a/lib/ShopifyResource/CustomerSavedSearch.php +++ b/lib/ShopifyResource/CustomerSavedSearch.php @@ -11,15 +11,13 @@ * @property-read Customer $Customer * @method Customer Customer(integer $id = null) */ -class CustomerSavedSearch extends ShopifyResource -{ +class CustomerSavedSearch extends ShopifyResource { protected $resourceKey = 'customer_saved_search'; protected $childResource = [ - 'Customer', + 'Customer' ]; - protected function pluralizeKey() - { + protected function pluralizeKey() { return 'customer_saved_searches'; } } diff --git a/lib/ShopifyResource/Discount.php b/lib/ShopifyResource/Discount.php index d5c13ba..1a7ca25 100644 --- a/lib/ShopifyResource/Discount.php +++ b/lib/ShopifyResource/Discount.php @@ -11,11 +11,10 @@ * @method array enable() Enable a discount * @method array disable() Disable a discount */ -class Discount extends ShopifyResource -{ +class Discount extends ShopifyResource { protected $resourceKey = 'discount'; protected $customPostActions = [ 'enable', - 'disable', + 'disable' ]; } diff --git a/lib/ShopifyResource/DiscountCode.php b/lib/ShopifyResource/DiscountCode.php index 6fb022a..aec3c12 100644 --- a/lib/ShopifyResource/DiscountCode.php +++ b/lib/ShopifyResource/DiscountCode.php @@ -10,10 +10,9 @@ /** * @method array lookup() Retrieves the location of a discount code. */ -class DiscountCode extends ShopifyResource -{ +class DiscountCode extends ShopifyResource { protected $resourceKey = 'discount_code'; protected $customGetActions = [ - 'lookup', + 'lookup' ]; } diff --git a/lib/ShopifyResource/DraftOrder.php b/lib/ShopifyResource/DraftOrder.php index 4e2f777..c07ef52 100644 --- a/lib/ShopifyResource/DraftOrder.php +++ b/lib/ShopifyResource/DraftOrder.php @@ -11,13 +11,12 @@ * @method array send_invoice() Send the invoice for a DraftOrder * @method array complete() Complete a DraftOrder */ -class DraftOrder extends ShopifyResource -{ +class DraftOrder extends ShopifyResource { protected $resourceKey = 'draft_order'; protected $customPostActions = [ - 'send_invoice', + 'send_invoice' ]; protected $customPutActions = [ - 'complete', + 'complete' ]; } diff --git a/lib/ShopifyResource/Event.php b/lib/ShopifyResource/Event.php index c42bec9..04dfbe0 100644 --- a/lib/ShopifyResource/Event.php +++ b/lib/ShopifyResource/Event.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class Event extends ShopifyResource -{ +class Event extends ShopifyResource { protected $resourceKey = 'event'; } diff --git a/lib/ShopifyResource/Fulfillment.php b/lib/ShopifyResource/Fulfillment.php index 27b5ca1..7146027 100644 --- a/lib/ShopifyResource/Fulfillment.php +++ b/lib/ShopifyResource/Fulfillment.php @@ -14,15 +14,14 @@ * @method array open() Open a pending fulfillment * @method array cancel() Cancel a fulfillment */ -class Fulfillment extends ShopifyResource -{ +class Fulfillment extends ShopifyResource { protected $resourceKey = 'fulfillment'; protected $childResource = [ - 'FulfillmentEvent' => 'Event', + 'FulfillmentEvent' => 'Event' ]; protected $customPostActions = [ 'complete', 'open', - 'cancel', + 'cancel' ]; } diff --git a/lib/ShopifyResource/FulfillmentEvent.php b/lib/ShopifyResource/FulfillmentEvent.php index 2a5a325..f0763b8 100644 --- a/lib/ShopifyResource/FulfillmentEvent.php +++ b/lib/ShopifyResource/FulfillmentEvent.php @@ -7,16 +7,13 @@ use PHPShopify\ShopifyResource; -class FulfillmentEvent extends ShopifyResource -{ +class FulfillmentEvent extends ShopifyResource { protected $resourceKey = 'fulfillment_event'; - public function getResourcePath() - { + public function getResourcePath() { return 'events'; } - public function getResourcePostKey() - { + public function getResourcePostKey() { return 'event'; } } diff --git a/lib/ShopifyResource/FulfillmentService.php b/lib/ShopifyResource/FulfillmentService.php index 4a47251..47e67e0 100644 --- a/lib/ShopifyResource/FulfillmentService.php +++ b/lib/ShopifyResource/FulfillmentService.php @@ -7,8 +7,7 @@ use PHPShopify\ShopifyResource; -class FulfillmentService extends ShopifyResource -{ +class FulfillmentService extends ShopifyResource { protected $resourceKey = 'fulfillment_service'; public $countEnabled = false; } diff --git a/lib/ShopifyResource/GiftCard.php b/lib/ShopifyResource/GiftCard.php index f65475c..27d007f 100644 --- a/lib/ShopifyResource/GiftCard.php +++ b/lib/ShopifyResource/GiftCard.php @@ -10,8 +10,7 @@ /** * @method array search() Search for gift cards matching supplied query */ -class GiftCard extends ShopifyResource -{ +class GiftCard extends ShopifyResource { protected $resourceKey = 'gift_card'; public $searchEnabled = true; @@ -19,12 +18,11 @@ class GiftCard extends ShopifyResource * Disable a gift card. * Disabling a gift card is permanent and cannot be undone. */ - public function disable(): array - { + public function disable(): array { $url = $this->generateUrl([], 'disable'); $dataArray = [ - 'id' => $this->id, + 'id' => $this->id ]; return $this->post($dataArray, $url); diff --git a/lib/ShopifyResource/GraphQL.php b/lib/ShopifyResource/GraphQL.php index b1f09b8..32c2678 100644 --- a/lib/ShopifyResource/GraphQL.php +++ b/lib/ShopifyResource/GraphQL.php @@ -11,10 +11,8 @@ use PHPShopify\Exception\CurlException; use PHPShopify\Exception\SdkException; -class GraphQL extends ShopifyResource -{ - protected function getResourcePath() - { +class GraphQL extends ShopifyResource { + protected function getResourcePath() { return 'graphql'; } @@ -28,8 +26,7 @@ protected function getResourcePath() * @throws CurlException if response received with unexpected HTTP code. * @return array */ - public function query(string $graphQL, ?string $url = null, ?array $variables = null): array - { + public function query(string $graphQL, ?string $url = null, ?array $variables = null): array { if ($url === null) { $url = $this->generateUrl(); } @@ -55,8 +52,7 @@ public function query(string $graphQL, ?string $url = null, ?array $variables = * @inheritdoc * @throws SdkException */ - public function get($urlParams = [], $url = null, $dataKey = null) - { + public function get($urlParams = [], $url = null, $dataKey = null) { throw new SdkException("Only POST method is allowed for GraphQL!"); } @@ -64,8 +60,7 @@ public function get($urlParams = [], $url = null, $dataKey = null) * @inheritdoc * @throws SdkException */ - public function put($dataArray, $url = null, $wrapData = true) - { + public function put($dataArray, $url = null, $wrapData = true) { throw new SdkException("Only POST method is allowed for GraphQL!"); } @@ -73,8 +68,7 @@ public function put($dataArray, $url = null, $wrapData = true) * @inheritdoc * @throws SdkException */ - public function delete($urlParams = [], $url = null) - { + public function delete($urlParams = [], $url = null) { throw new SdkException("Only POST method is allowed for GraphQL!"); } } diff --git a/lib/ShopifyResource/InventoryItem.php b/lib/ShopifyResource/InventoryItem.php index 4ade82a..abf87e2 100644 --- a/lib/ShopifyResource/InventoryItem.php +++ b/lib/ShopifyResource/InventoryItem.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class InventoryItem extends ShopifyResource -{ +class InventoryItem extends ShopifyResource { protected $resourceKey = 'inventory_item'; } diff --git a/lib/ShopifyResource/InventoryLevel.php b/lib/ShopifyResource/InventoryLevel.php index bd03c2c..7edd9f9 100644 --- a/lib/ShopifyResource/InventoryLevel.php +++ b/lib/ShopifyResource/InventoryLevel.php @@ -12,12 +12,11 @@ * @method array connect($data) Connect an inventory item to a location. * @method array set($data) Sets an inventory level for a single inventory item within a location. */ -class InventoryLevel extends ShopifyResource -{ +class InventoryLevel extends ShopifyResource { protected $resourceKey = 'inventory_level'; protected $customPostActions = [ 'adjust', 'connect', - 'set', + 'set' ]; } diff --git a/lib/ShopifyResource/Location.php b/lib/ShopifyResource/Location.php index bae5b88..5afe6b9 100644 --- a/lib/ShopifyResource/Location.php +++ b/lib/ShopifyResource/Location.php @@ -7,12 +7,11 @@ use PHPShopify\ShopifyResource; -class Location extends ShopifyResource -{ +class Location extends ShopifyResource { protected $resourceKey = 'location'; public $countEnabled = false; public $readOnly = true; protected $childResource = [ - 'InventoryLevel', + 'InventoryLevel' ]; } diff --git a/lib/ShopifyResource/Metafield.php b/lib/ShopifyResource/Metafield.php index b1671a2..79fe059 100644 --- a/lib/ShopifyResource/Metafield.php +++ b/lib/ShopifyResource/Metafield.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class Metafield extends ShopifyResource -{ +class Metafield extends ShopifyResource { protected $resourceKey = 'metafield'; } diff --git a/lib/ShopifyResource/Multipass.php b/lib/ShopifyResource/Multipass.php index 454bc1e..5db35b7 100644 --- a/lib/ShopifyResource/Multipass.php +++ b/lib/ShopifyResource/Multipass.php @@ -8,14 +8,12 @@ use PHPShopify\ShopifyResource; use PHPShopify\Exception\ApiException; -class Multipass extends ShopifyResource -{ +class Multipass extends ShopifyResource { /** * @inheritDoc * @throws ApiException */ - public function __construct(int $id = null) - { + public function __construct(int $id = null) { throw new ApiException("Multipass API is not available yet!"); } } diff --git a/lib/ShopifyResource/Order.php b/lib/ShopifyResource/Order.php index b56905b..a5c2e0d 100644 --- a/lib/ShopifyResource/Order.php +++ b/lib/ShopifyResource/Order.php @@ -24,8 +24,7 @@ * @method array open() * @method array cancel(array $data) */ -class Order extends ShopifyResource -{ +class Order extends ShopifyResource { protected $resourceKey = 'order'; protected $childResource = [ 'Fulfillment', @@ -33,11 +32,11 @@ class Order extends ShopifyResource 'Refund', 'Transaction', 'Event', - 'Metafield', + 'Metafield' ]; protected $customPostActions = [ 'close', 'open', - 'cancel', + 'cancel' ]; } diff --git a/lib/ShopifyResource/OrderRisk.php b/lib/ShopifyResource/OrderRisk.php index d287c42..d96e752 100644 --- a/lib/ShopifyResource/OrderRisk.php +++ b/lib/ShopifyResource/OrderRisk.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class OrderRisk extends ShopifyResource -{ +class OrderRisk extends ShopifyResource { protected $resourceKey = 'risk'; } diff --git a/lib/ShopifyResource/Page.php b/lib/ShopifyResource/Page.php index c7c5026..d704da5 100644 --- a/lib/ShopifyResource/Page.php +++ b/lib/ShopifyResource/Page.php @@ -13,11 +13,10 @@ * @method Event Event(integer $id = null) * @method Metafield Metafield(integer $id = null) */ -class Page extends ShopifyResource -{ +class Page extends ShopifyResource { protected $resourceKey = 'page'; protected $childResource = [ 'Event', - 'Metafield', + 'Metafield' ]; } diff --git a/lib/ShopifyResource/Policy.php b/lib/ShopifyResource/Policy.php index 655cdf3..8f8c880 100644 --- a/lib/ShopifyResource/Policy.php +++ b/lib/ShopifyResource/Policy.php @@ -7,14 +7,12 @@ use PHPShopify\ShopifyResource; -class Policy extends ShopifyResource -{ +class Policy extends ShopifyResource { protected $resourceKey = 'policy'; public $countEnabled = false; public $readOnly = true; - public function pluralizeKey() - { + public function pluralizeKey() { return 'policies'; } } diff --git a/lib/ShopifyResource/PriceRule.php b/lib/ShopifyResource/PriceRule.php index e39def9..47e903a 100644 --- a/lib/ShopifyResource/PriceRule.php +++ b/lib/ShopifyResource/PriceRule.php @@ -11,11 +11,10 @@ * @property-read ShopifyResource $DiscountCode * @method ShopifyResource DiscountCode(integer $id = null) */ -class PriceRule extends ShopifyResource -{ +class PriceRule extends ShopifyResource { public $resourceKey = 'price_rule'; public $countEnabled = false; protected $childResource = [ - 'DiscountCode', + 'DiscountCode' ]; } diff --git a/lib/ShopifyResource/Product.php b/lib/ShopifyResource/Product.php index afb0415..e5c7601 100644 --- a/lib/ShopifyResource/Product.php +++ b/lib/ShopifyResource/Product.php @@ -17,13 +17,12 @@ * @method Metafield Metafield(integer $id = null) * @method Event Event(integer $id = null) */ -class Product extends ShopifyResource -{ +class Product extends ShopifyResource { public $resourceKey = 'product'; protected $childResource = [ 'ProductImage' => 'Image', 'ProductVariant' => 'Variant', 'Metafield', - 'Event', + 'Event' ]; } diff --git a/lib/ShopifyResource/ProductImage.php b/lib/ShopifyResource/ProductImage.php index 07a6fdf..f10ef8a 100644 --- a/lib/ShopifyResource/ProductImage.php +++ b/lib/ShopifyResource/ProductImage.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class ProductImage extends ShopifyResource -{ +class ProductImage extends ShopifyResource { protected $resourceKey = 'image'; } diff --git a/lib/ShopifyResource/ProductListing.php b/lib/ShopifyResource/ProductListing.php index 5cf08ad..1bff707 100644 --- a/lib/ShopifyResource/ProductListing.php +++ b/lib/ShopifyResource/ProductListing.php @@ -7,10 +7,9 @@ use PHPShopify\ShopifyResource; -class ProductListing extends ShopifyResource -{ +class ProductListing extends ShopifyResource { protected $resourceKey = 'product_listing'; protected $customGetActions = [ - 'product_ids' => 'productIds', + 'product_ids' => 'productIds' ]; } diff --git a/lib/ShopifyResource/ProductVariant.php b/lib/ShopifyResource/ProductVariant.php index e639d8a..91d9208 100644 --- a/lib/ShopifyResource/ProductVariant.php +++ b/lib/ShopifyResource/ProductVariant.php @@ -12,11 +12,10 @@ * @property-read Metafield $Metafield * @method Metafield Metafield(integer $id = null) */ -class ProductVariant extends ShopifyResource -{ +class ProductVariant extends ShopifyResource { protected $resourceKey = 'variant'; public $searchEnabled = true; protected $childResource = [ - 'Metafield', + 'Metafield' ]; } diff --git a/lib/ShopifyResource/Province.php b/lib/ShopifyResource/Province.php index 66e198b..9a52fbd 100644 --- a/lib/ShopifyResource/Province.php +++ b/lib/ShopifyResource/Province.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class Province extends ShopifyResource -{ +class Province extends ShopifyResource { protected $resourceKey = 'province'; } diff --git a/lib/ShopifyResource/RecurringApplicationCharge.php b/lib/ShopifyResource/RecurringApplicationCharge.php index 26656c8..66042b5 100644 --- a/lib/ShopifyResource/RecurringApplicationCharge.php +++ b/lib/ShopifyResource/RecurringApplicationCharge.php @@ -12,19 +12,17 @@ * @method UsageCharge UsageCharge(integer $id = null) * @method array activate() Activate a recurring application charge */ -class RecurringApplicationCharge extends ShopifyResource -{ +class RecurringApplicationCharge extends ShopifyResource { protected $resourceKey = 'recurring_application_charge'; public $countEnabled = false; protected $childResource = [ - 'UsageCharge', + 'UsageCharge' ]; protected $customPostActions = [ - 'activate', + 'activate' ]; - public function customize(array $dataArray): array - { + public function customize(array $dataArray): array { $dataArray = $this->wrapData($dataArray); $url = $this->generateUrl($dataArray, 'customize'); diff --git a/lib/ShopifyResource/Redirect.php b/lib/ShopifyResource/Redirect.php index 1461b3d..3b3b269 100644 --- a/lib/ShopifyResource/Redirect.php +++ b/lib/ShopifyResource/Redirect.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class Redirect extends ShopifyResource -{ +class Redirect extends ShopifyResource { protected $resourceKey = 'redirect'; } diff --git a/lib/ShopifyResource/Refund.php b/lib/ShopifyResource/Refund.php index bfe1c40..4f35ffd 100644 --- a/lib/ShopifyResource/Refund.php +++ b/lib/ShopifyResource/Refund.php @@ -10,10 +10,9 @@ /** * @method array calculate() Calculate a Refund. */ -class Refund extends ShopifyResource -{ +class Refund extends ShopifyResource { protected $resourceKey = 'refund'; protected $customPostActions = [ - 'calculate', + 'calculate' ]; } diff --git a/lib/ShopifyResource/Report.php b/lib/ShopifyResource/Report.php index 216ddd3..68e6680 100644 --- a/lib/ShopifyResource/Report.php +++ b/lib/ShopifyResource/Report.php @@ -4,8 +4,7 @@ use PHPShopify\ShopifyResource; -class Report extends ShopifyResource -{ +class Report extends ShopifyResource { protected $resourceKey = 'report'; public $countEnabled = false; } diff --git a/lib/ShopifyResource/ScriptTag.php b/lib/ShopifyResource/ScriptTag.php index 09cccc2..2a4ae17 100644 --- a/lib/ShopifyResource/ScriptTag.php +++ b/lib/ShopifyResource/ScriptTag.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class ScriptTag extends ShopifyResource -{ +class ScriptTag extends ShopifyResource { protected $resourceKey = 'script_tag'; } diff --git a/lib/ShopifyResource/ShippingZone.php b/lib/ShopifyResource/ShippingZone.php index c80a10b..7dc3d36 100644 --- a/lib/ShopifyResource/ShippingZone.php +++ b/lib/ShopifyResource/ShippingZone.php @@ -7,8 +7,7 @@ use PHPShopify\ShopifyResource; -class ShippingZone extends ShopifyResource -{ +class ShippingZone extends ShopifyResource { protected $resourceKey = 'shipping_zone'; public $countEnabled = false; public $readOnly = true; diff --git a/lib/ShopifyResource/Shop.php b/lib/ShopifyResource/Shop.php index 81d430b..6078599 100644 --- a/lib/ShopifyResource/Shop.php +++ b/lib/ShopifyResource/Shop.php @@ -7,14 +7,12 @@ use PHPShopify\ShopifyResource; -class Shop extends ShopifyResource -{ +class Shop extends ShopifyResource { protected $resourceKey = 'shop'; public $countEnabled = false; public $readOnly = true; - public function pluralizeKey(): string - { + public function pluralizeKey(): string { return 'shop'; } } diff --git a/lib/ShopifyResource/SmartCollection.php b/lib/ShopifyResource/SmartCollection.php index 53e4b4b..8d7d64e 100644 --- a/lib/ShopifyResource/SmartCollection.php +++ b/lib/ShopifyResource/SmartCollection.php @@ -11,19 +11,17 @@ * @property-read Event $Event * @method Event Event(integer $id = null) */ -class SmartCollection extends ShopifyResource -{ +class SmartCollection extends ShopifyResource { protected $resourceKey = 'smart_collection'; protected $childResource = [ 'Event', - 'Metafield', + 'Metafield' ]; /** * Set the ordering type and/or the manual order of products in a smart collection */ - public function sortOrder(array $params): array - { + public function sortOrder(array $params): array { $url = $this->generateUrl($params, 'order'); return $this->put([], $url); diff --git a/lib/ShopifyResource/Theme.php b/lib/ShopifyResource/Theme.php index b95c913..7809f49 100644 --- a/lib/ShopifyResource/Theme.php +++ b/lib/ShopifyResource/Theme.php @@ -11,11 +11,10 @@ * @property-read Asset $Asset * @method Asset Asset(integer $id = null) */ -class Theme extends ShopifyResource -{ +class Theme extends ShopifyResource { public $resourceKey = 'theme'; public $countEnabled = false; protected $childResource = [ - 'Asset', + 'Asset' ]; } diff --git a/lib/ShopifyResource/Transaction.php b/lib/ShopifyResource/Transaction.php index afaef85..944d26c 100644 --- a/lib/ShopifyResource/Transaction.php +++ b/lib/ShopifyResource/Transaction.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class Transaction extends ShopifyResource -{ +class Transaction extends ShopifyResource { protected $resourceKey = 'transaction'; } diff --git a/lib/ShopifyResource/UsageCharge.php b/lib/ShopifyResource/UsageCharge.php index 31b2900..6c9e8f2 100644 --- a/lib/ShopifyResource/UsageCharge.php +++ b/lib/ShopifyResource/UsageCharge.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class UsageCharge extends ShopifyResource -{ +class UsageCharge extends ShopifyResource { protected $resourceKey = 'usage_charge'; } diff --git a/lib/ShopifyResource/User.php b/lib/ShopifyResource/User.php index bc316d4..524a664 100644 --- a/lib/ShopifyResource/User.php +++ b/lib/ShopifyResource/User.php @@ -10,11 +10,10 @@ /** * @method array current() Get the current logged-in user */ -class User extends ShopifyResource -{ +class User extends ShopifyResource { protected $resourceKey = 'user'; public $readOnly = true; protected $customGetActions = [ - 'current', + 'current' ]; } diff --git a/lib/ShopifyResource/Webhook.php b/lib/ShopifyResource/Webhook.php index 05c1ec6..7a49e33 100644 --- a/lib/ShopifyResource/Webhook.php +++ b/lib/ShopifyResource/Webhook.php @@ -7,7 +7,6 @@ use PHPShopify\ShopifyResource; -class Webhook extends ShopifyResource -{ +class Webhook extends ShopifyResource { protected $resourceKey = 'webhook'; } From 5cf062c9ae400e83e365cba16b763b11869c7b65 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 13:27:12 +0000 Subject: [PATCH 19/29] Small fixes. Update composer packages. --- composer.lock | 117 ++++++++++++++++++++------------------- lib/Http/CurlRequest.php | 1 - 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/composer.lock b/composer.lock index 8a526e6..89af88e 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8624cace8c373f5a022e66c876da9f1f", + "content-hash": "2960f8805c6360d7e5e677e8141b46d0", "packages": [], "packages-dev": [ { @@ -65,16 +65,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.9.3", + "version": "1.9.5", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" + "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", - "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/b2c28789e80a97badd14145fda39b545d83ca3ef", + "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef", "shasum": "" }, "require": { @@ -109,7 +109,7 @@ "object", "object graph" ], - "time": "2019-08-09T12:45:53+00:00" + "time": "2020-01-17T21:11:47+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -165,40 +165,38 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.2", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", "shasum": "" }, "require": { - "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", - "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", - "webmozart/assert": "^1.0" + "ext-filter": "^7.1", + "php": "^7.2", + "phpdocumentor/reflection-common": "^2.0", + "phpdocumentor/type-resolver": "^1.0", + "webmozart/assert": "^1" }, "require-dev": { - "doctrine/instantiator": "^1.0.5", - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^6.4" + "doctrine/instantiator": "^1", + "mockery/mockery": "^1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev" + "dev-master": "5.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -209,33 +207,36 @@ { "name": "Mike van Riel", "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2019-09-12T14:27:41+00:00" + "time": "2020-02-22T12:28:44+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.0.1", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95", + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95", "shasum": "" }, "require": { - "php": "^7.1", + "php": "^7.2", "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "ext-tokenizer": "^7.1", - "mockery/mockery": "~1", - "phpunit/phpunit": "^7.0" + "ext-tokenizer": "^7.2", + "mockery/mockery": "~1" }, "type": "library", "extra": { @@ -259,37 +260,37 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2019-08-22T18:11:29+00:00" + "time": "2020-02-18T18:59:58+00:00" }, { "name": "phpspec/prophecy", - "version": "1.9.0", + "version": "v1.10.3", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" + "reference": "451c3cd1418cf640de218914901e51b064abb093" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", - "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/451c3cd1418cf640de218914901e51b064abb093", + "reference": "451c3cd1418cf640de218914901e51b064abb093", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", - "sebastian/comparator": "^1.1|^2.0|^3.0", - "sebastian/recursion-context": "^1.0|^2.0|^3.0" + "sebastian/comparator": "^1.2.3|^2.0|^3.0|^4.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0|^4.0" }, "require-dev": { - "phpspec/phpspec": "^2.5|^3.2", + "phpspec/phpspec": "^2.5 || ^3.2", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8.x-dev" + "dev-master": "1.10.x-dev" } }, "autoload": { @@ -322,7 +323,7 @@ "spy", "stub" ], - "time": "2019-10-03T11:07:50+00:00" + "time": "2020-03-05T15:02:03+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1230,16 +1231,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.13.1", + "version": "v1.14.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3" + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", "shasum": "" }, "require": { @@ -1251,7 +1252,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.14-dev" } }, "autoload": { @@ -1284,20 +1285,20 @@ "polyfill", "portable" ], - "time": "2019-11-27T13:56:44+00:00" + "time": "2020-01-13T11:15:53+00:00" }, { "name": "symfony/yaml", - "version": "v4.4.1", + "version": "v4.4.5", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "76de473358fe802578a415d5bb43c296cf09d211" + "reference": "94d005c176db2080e98825d98e01e8b311a97a88" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/76de473358fe802578a415d5bb43c296cf09d211", - "reference": "76de473358fe802578a415d5bb43c296cf09d211", + "url": "https://api.github.com/repos/symfony/yaml/zipball/94d005c176db2080e98825d98e01e8b311a97a88", + "reference": "94d005c176db2080e98825d98e01e8b311a97a88", "shasum": "" }, "require": { @@ -1343,20 +1344,20 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2019-11-12T14:51:11+00:00" + "time": "2020-02-03T10:46:43+00:00" }, { "name": "webmozart/assert", - "version": "1.6.0", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925" + "reference": "aed98a490f9a8f78468232db345ab9cf606cf598" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/573381c0a64f155a0d9a23f4b0c797194805b925", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925", + "url": "https://api.github.com/repos/webmozart/assert/zipball/aed98a490f9a8f78468232db345ab9cf606cf598", + "reference": "aed98a490f9a8f78468232db345ab9cf606cf598", "shasum": "" }, "require": { @@ -1391,7 +1392,7 @@ "check", "validate" ], - "time": "2019-11-24T13:36:37+00:00" + "time": "2020-02-14T12:15:55+00:00" } ], "aliases": [], @@ -1400,7 +1401,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.6", + "php": ">=7.3", "ext-curl": "*", "ext-json": "*" }, diff --git a/lib/Http/CurlRequest.php b/lib/Http/CurlRequest.php index bffd588..e333606 100644 --- a/lib/Http/CurlRequest.php +++ b/lib/Http/CurlRequest.php @@ -119,7 +119,6 @@ protected static function processRequest($ch): CurlResponse { private static function parseResponse(string $response): array { $response = explode("\r\n\r\n", $response, 2); - $headers = []; assert(count($response) === 2); [$headers, $body] = $response; From aa4d5c987a73dd872ed7b99f798758bd2cf1e1e3 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 14:13:48 +0000 Subject: [PATCH 20/29] Fix most broken tests. --- README.md | 1 + lib/Http/CurlRequest.php | 43 ++++++++++++--------- lib/Http/CurlResponse.php | 2 +- lib/Http/HttpRequestJson.php | 5 ++- lib/ShopifyResource.php | 4 +- lib/ShopifyResource/Country.php | 7 +--- lib/ShopifyResource/Currency.php | 2 +- lib/ShopifyResource/CustomerAddress.php | 2 +- lib/ShopifyResource/CustomerSavedSearch.php | 2 +- lib/ShopifyResource/Policy.php | 2 +- lib/ShopifySDK.php | 2 +- tests/ShopifyResource/BlogTest.php | 4 +- 12 files changed, 40 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index b686783..2d4575b 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ $config = [ 'SharedSecret' => '***YOUR-SHARED-SECRET***' ]; +$shopifyClient = new PHPShopify\ShopifySDK($config); $shopifyClient = new PHPShopify\ShopifySDK($config); ``` diff --git a/lib/Http/CurlRequest.php b/lib/Http/CurlRequest.php index e333606..512a27f 100644 --- a/lib/Http/CurlRequest.php +++ b/lib/Http/CurlRequest.php @@ -15,7 +15,7 @@ class CurlRequest { * This allows use of keepalive. * @var resource */ - private static $ch; + protected static $ch; /** * @inheritDoc @@ -34,13 +34,11 @@ protected static function init(string $method, string $url, array $httpHeaders = curl_setopt(self::$ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt(self::$ch, CURLOPT_URL, $url); - if ($data !== null) { - $headers['Content-Length'] = strlen($data); - curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $data); - } else { - curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $data); + if ($data !== null && !is_string($data)) { + $data = static::serializeData($data); } + curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $data); $headers = []; foreach ($httpHeaders as $key => $value) { @@ -61,7 +59,7 @@ public static function destroy(): void { } public static function get(string $url, array $httpHeaders = []): CurlResponse { - return self::processRequest(self::init('GET', $url, $httpHeaders)); + return static::processRequest(static::init('GET', $url, $httpHeaders)); } /** @@ -69,15 +67,15 @@ public static function get(string $url, array $httpHeaders = []): CurlResponse { * @param string|array $data */ public static function post(string $url, $data, array $httpHeaders = []): CurlResponse { - return self::processRequest(self::init('POST', $url, $httpHeaders, $data)); + return static::processRequest(static::init('POST', $url, $httpHeaders, $data)); } public static function put($url, $data, array $httpHeaders = []): CurlResponse { - return self::processRequest(self::init('PUT', $url, $httpHeaders, $data)); + return static::processRequest(static::init('PUT', $url, $httpHeaders, $data)); } public static function delete(string $url, array $httpHeaders = []): CurlResponse { - return self::processRequest(self::init('DELETE', $url, $httpHeaders)); + return static::processRequest(static::init('DELETE', $url, $httpHeaders)); } /** @@ -96,7 +94,7 @@ protected static function processRequest($ch): CurlResponse { assert(is_string($output)); - $parsedResponse = self::parseResponse($output); + $parsedResponse = static::parseResponse($output); // Note: Missing error handling here. $status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); $response = new CurlResponse($status, $parsedResponse['headers'], $parsedResponse['body']); @@ -111,7 +109,7 @@ protected static function processRequest($ch): CurlResponse { throw new ResourceRateLimitException($response->getBody()); } - usleep(self::RATE_LIMIT_RETRY_DELAY); + usleep(static::RATE_LIMIT_RETRY_DELAY); } return $response; @@ -121,23 +119,30 @@ private static function parseResponse(string $response): array { $response = explode("\r\n\r\n", $response, 2); assert(count($response) === 2); - [$headers, $body] = $response; + $headers = []; + [$headerString, $bodyString] = $response; - foreach (explode("\r\n", $headers) as $header) { + foreach (explode("\r\n", $headerString) as $header) { $pair = explode(': ', $header, 2); + [$key, $value] = $pair + [1 => null]; + $key = strtolower($key); - if (isset($pair[1])) { - $headerKey = strtolower($pair[0]); - $headers[$headerKey] = $pair[1]; + if (!array_key_exists($key, $headers)) { + $headers[$key] = []; } + + $headers[$key][] = $value; } - // Gimme yur body. - $body = self::parseBody($body); + $body = static::parseBody($bodyString); return compact('headers', 'body'); } + protected static function serializeData($data): string { + return http_build_query($data); + } + protected static function parseBody(string $body) { return $body; } diff --git a/lib/Http/CurlResponse.php b/lib/Http/CurlResponse.php index 70322c1..fc2ce8a 100644 --- a/lib/Http/CurlResponse.php +++ b/lib/Http/CurlResponse.php @@ -16,7 +16,7 @@ public function __construct(int $status, array $headers, $body) { } public function getHeader(string $key): ?string { - return $this->headers[$key] ?? null; + return $this->headers[$key][0] ?? null; } public function getBody() { diff --git a/lib/Http/HttpRequestJson.php b/lib/Http/HttpRequestJson.php index 3c3a979..0fa4cb2 100644 --- a/lib/Http/HttpRequestJson.php +++ b/lib/Http/HttpRequestJson.php @@ -7,7 +7,6 @@ protected static function init(string $method, string $url, array $httpHeaders = // Note: Is null valid for any shopify calls? if ($data !== null) { $httpHeaders['Content-type'] = 'application/json'; - $data = self::encode($data); } return parent::init($method, $url, $httpHeaders, $data); @@ -17,6 +16,10 @@ protected static function parseBody(string $body) { return json_decode($body, true); } + public static function serializeData($data): string { + return self::encode($data); + } + public static function encode($data): string { return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 1b9d488..c520a78 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -377,10 +377,10 @@ protected function wrapData(array $dataArray, $dataKey = null): array return [$dataKey => $dataArray]; } - protected static function castString(array $array): string + protected static function castString($array): string { if (!is_array($array)) { - return (string) $array; + return (string)$array; } $string = ''; diff --git a/lib/ShopifyResource/Country.php b/lib/ShopifyResource/Country.php index f444a07..3e0ce0d 100644 --- a/lib/ShopifyResource/Country.php +++ b/lib/ShopifyResource/Country.php @@ -8,13 +8,8 @@ use PHPShopify\ShopifyResource; /** - * -------------------------------------------------------------------------- - * Country -> Child Resources - * -------------------------------------------------------------------------- * @property-read Province $Province - * * @method Province Province(integer $id = null) - * */ class Country extends ShopifyResource { protected $resourceKey = 'country'; @@ -22,7 +17,7 @@ class Country extends ShopifyResource { 'Province' ]; - protected function pluralizeKey() { + protected function pluralizeKey(): string { return 'countries'; } } diff --git a/lib/ShopifyResource/Currency.php b/lib/ShopifyResource/Currency.php index 2cba76d..de26f4c 100644 --- a/lib/ShopifyResource/Currency.php +++ b/lib/ShopifyResource/Currency.php @@ -12,7 +12,7 @@ class Currency extends ShopifyResource { public $countEnabled = false; public $readOnly = true; - public function pluralizeKey() { + public function pluralizeKey(): string { return 'currencies'; } } diff --git a/lib/ShopifyResource/CustomerAddress.php b/lib/ShopifyResource/CustomerAddress.php index 0a9c814..fdea8d9 100644 --- a/lib/ShopifyResource/CustomerAddress.php +++ b/lib/ShopifyResource/CustomerAddress.php @@ -16,7 +16,7 @@ class CustomerAddress extends ShopifyResource { 'default' => 'makeDefault' ]; - protected function pluralizeKey() { + protected function pluralizeKey(): string { return 'addresses'; } diff --git a/lib/ShopifyResource/CustomerSavedSearch.php b/lib/ShopifyResource/CustomerSavedSearch.php index c18101d..d64bdd3 100644 --- a/lib/ShopifyResource/CustomerSavedSearch.php +++ b/lib/ShopifyResource/CustomerSavedSearch.php @@ -17,7 +17,7 @@ class CustomerSavedSearch extends ShopifyResource { 'Customer' ]; - protected function pluralizeKey() { + protected function pluralizeKey(): string { return 'customer_saved_searches'; } } diff --git a/lib/ShopifyResource/Policy.php b/lib/ShopifyResource/Policy.php index 8f8c880..5e6a273 100644 --- a/lib/ShopifyResource/Policy.php +++ b/lib/ShopifyResource/Policy.php @@ -12,7 +12,7 @@ class Policy extends ShopifyResource { public $countEnabled = false; public $readOnly = true; - public function pluralizeKey() { + public function pluralizeKey(): string { return 'policies'; } } diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 5e5655f..ec85278 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -294,7 +294,7 @@ public function __call($resourceName, $arguments) { throw new SdkException($message); } - $resourceClassName = __NAMESPACE__ . "\\$resourceName"; + $resourceClassName = ShopifyResource::class . "\\{$resourceName}"; //If first argument is provided, it will be considered as the ID of the resource. $resourceID = !empty($arguments) ? $arguments[0] : null; diff --git a/tests/ShopifyResource/BlogTest.php b/tests/ShopifyResource/BlogTest.php index d271ed8..adbb3b1 100644 --- a/tests/ShopifyResource/BlogTest.php +++ b/tests/ShopifyResource/BlogTest.php @@ -6,9 +6,9 @@ class BlogTest extends TestSimpleResource { public $postArray = [ - "title" => "PHPShopify Test Blog" + "title" => "Mega Test Blog" ]; public $putArray = [ - "title" => "PHPShopify Test Blog Modified" + "title" => "Mega Test Blog Modified" ]; } From c7962b71c707efaa609345e2fbdad0fc7985ee17 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 14:41:08 +0000 Subject: [PATCH 21/29] Apply PR 145 and remove comment noise. --- lib/ShopifyResource/AbandonedCheckout.php | 2 +- lib/ShopifyResource/ApplicationCharge.php | 2 +- lib/ShopifyResource/Article.php | 2 +- lib/ShopifyResource/Asset.php | 2 +- lib/ShopifyResource/Blog.php | 2 +- lib/ShopifyResource/CarrierService.php | 2 +- lib/ShopifyResource/Collect.php | 2 +- lib/ShopifyResource/Collection.php | 15 +++++++++++++++ lib/ShopifyResource/Comment.php | 2 +- lib/ShopifyResource/Country.php | 2 +- lib/ShopifyResource/Currency.php | 2 +- lib/ShopifyResource/CustomCollection.php | 2 +- lib/ShopifyResource/Customer.php | 2 +- lib/ShopifyResource/CustomerAddress.php | 2 +- lib/ShopifyResource/CustomerSavedSearch.php | 2 +- lib/ShopifyResource/Discount.php | 2 +- lib/ShopifyResource/DiscountCode.php | 2 +- lib/ShopifyResource/DraftOrder.php | 2 +- lib/ShopifyResource/Event.php | 2 +- lib/ShopifyResource/Fulfillment.php | 2 +- lib/ShopifyResource/FulfillmentEvent.php | 2 +- lib/ShopifyResource/FulfillmentService.php | 2 +- lib/ShopifyResource/GiftCard.php | 2 +- lib/ShopifyResource/Location.php | 2 +- lib/ShopifyResource/Metafield.php | 2 +- lib/ShopifyResource/Multipass.php | 2 +- lib/ShopifyResource/Order.php | 2 +- lib/ShopifyResource/OrderRisk.php | 2 +- lib/ShopifyResource/Page.php | 2 +- lib/ShopifyResource/Policy.php | 2 +- lib/ShopifyResource/PriceRule.php | 2 +- lib/ShopifyResource/Product.php | 2 +- lib/ShopifyResource/ProductImage.php | 2 +- lib/ShopifyResource/ProductListing.php | 2 +- lib/ShopifyResource/ProductVariant.php | 2 +- lib/ShopifyResource/Province.php | 2 +- .../RecurringApplicationCharge.php | 2 +- lib/ShopifyResource/Redirect.php | 2 +- lib/ShopifyResource/Refund.php | 2 +- lib/ShopifyResource/ScriptTag.php | 2 +- lib/ShopifyResource/ShippingZone.php | 2 +- lib/ShopifyResource/Shop.php | 2 +- lib/ShopifyResource/SmartCollection.php | 2 +- lib/ShopifyResource/Theme.php | 2 +- lib/ShopifyResource/Transaction.php | 2 +- lib/ShopifyResource/UsageCharge.php | 2 +- lib/ShopifyResource/User.php | 2 +- lib/ShopifyResource/Webhook.php | 2 +- lib/ShopifySDK.php | 4 +++- tests/ShopifyResource/CollectionTest.php | 8 ++++++++ 50 files changed, 73 insertions(+), 48 deletions(-) create mode 100644 lib/ShopifyResource/Collection.php create mode 100644 tests/ShopifyResource/CollectionTest.php diff --git a/lib/ShopifyResource/AbandonedCheckout.php b/lib/ShopifyResource/AbandonedCheckout.php index acf87a9..b2f3837 100644 --- a/lib/ShopifyResource/AbandonedCheckout.php +++ b/lib/ShopifyResource/AbandonedCheckout.php @@ -1,6 +1,6 @@ Date: Mon, 9 Mar 2020 15:01:39 +0000 Subject: [PATCH 22/29] Update auth helper and pull in pull request for params. --- lib/AuthHelper.php | 62 ++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index 8a5e000..133fd7a 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -7,8 +7,7 @@ class AuthHelper { - public static function getCurrentUrl(): string - { + public static function getCurrentUrl(): string { if ( in_array($_SERVER['HTTPS'] ?? null, ['on', 1]) && @@ -22,49 +21,38 @@ public static function getCurrentUrl(): string return "{$protocol}://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; } - /** - * Build a query string from a data array - * Note: Strings should be URL encoded though? - * This is a replacement for http_build_query because that returns an url-encoded string. - */ - public static function buildQueryString(array $data): string - { - $paramStrings = []; - - foreach ($data as $key => $value) { - $paramStrings[] = "{$key}={$value}"; - } - - return implode('&', $paramStrings); - } - /** * Verify if the request is made from shopify using hmac hash value * * @inheritDoc + * @see https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/hmac-calculation-vs-ids-arrays-320575 * @throws SdkException if SharedSecret is not provided or hmac is not found in the url parameters */ - public static function verifyShopifyRequest(array $config, array $data): bool - { + public static function verifyShopifyRequest(array $config, array $data): bool { $sharedSecret = $config['SharedSecret']; - if (isset($data['hmac'])) { - $hmac = $data['hmac']; - unset($data['hmac']); - } else { + if (!isset($data['hmac']) || !is_string($data['hmac'])) { throw new SdkException("HMAC value not found in url parameters."); } - // signature validation is deprecated - if (isset($data['signature'])) { - unset($data['signature']); - } + $hashItems = []; + + foreach ($data as $key => $value) { + if (in_array($key, ['hmac', 'signature'], true)) { + continue; + } - $dataString = self::buildQueryString($data); + if (is_array($value)) { + $value = '["' . implode('", "', $value) . '"]'; + } - $realHmac = hash_hmac('sha256', $dataString, $sharedSecret); + $hashItems[$key] = "{$key}={$value}"; + } + + ksort($hashItems); + $hashString = implode('&', $hashItems); - return $realHmac === $hmac; + return hash_hmac('sha256', $hashString, $sharedSecret) === $data['hmac']; } /** @@ -81,8 +69,7 @@ public static function createAuthRequest( string $redirectUrl, ?string $state = null, ?array $options = null - ): ?string - { + ): ?string { assert(is_string($scopes) || is_array($scopes)); if ($scopes !== null) { @@ -106,9 +93,8 @@ public static function createAuthRequest( * Get Access token for the API * Call this when being redirected from shopify page ( to the $redirectUrl) after authentication */ - public static function getAccessToken(array $config, array $data): string - { - if(self::verifyShopifyRequest($config)) { + public static function getAccessToken(array $config, array $data): string { + if(self::verifyShopifyRequest($config, $data)) { $data = [ 'client_id' => $config['ApiKey'], 'client_secret' => $config['SharedSecret'], @@ -118,8 +104,8 @@ public static function getAccessToken(array $config, array $data): string $response = HttpRequestJson::post("{$config['AdminUrl']}oauth/access_token", $data); return $response['access_token'] ?? null; - } else { - throw new SdkException("This request is not initiated from a valid shopify shop!"); } + + throw new SdkException("This request is not initiated from a valid shopify shop!"); } } From aa146517f2b05be3dbd35f6d80869efe85733ed4 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 15:45:43 +0000 Subject: [PATCH 23/29] Remove test that won't work (limited set of operations available for resource). Improve OOP extensibility. --- lib/AuthHelper.php | 38 +++++++---- lib/Http/CurlRequest.php | 22 +++---- lib/Http/HttpRequestJson.php | 6 +- lib/ShopifyResource.php | 80 +++++++++--------------- lib/ShopifyResource/FulfillmentEvent.php | 4 +- lib/ShopifyResource/GraphQL.php | 11 ++-- lib/ShopifySDK.php | 48 +++++++++++--- tests/ShopifyResource/CollectionTest.php | 8 --- 8 files changed, 115 insertions(+), 102 deletions(-) delete mode 100644 tests/ShopifyResource/CollectionTest.php diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index 133fd7a..0117c3d 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -7,6 +7,21 @@ class AuthHelper { + /** @var array */ + protected $config; + /** @var HttpRequestJson */ + protected $httpRequestJson; + + public function __construct(array $config, ?HttpRequestJson $httpRequestJson = null) { + $this->config = $config; + + if ($httpRequestJson === null) { + $httpRequestJson = new HttpRequestJson(); + } + + $this->httpRequestJson = $httpRequestJson; + } + public static function getCurrentUrl(): string { if ( in_array($_SERVER['HTTPS'] ?? null, ['on', 1]) @@ -28,8 +43,8 @@ public static function getCurrentUrl(): string { * @see https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/hmac-calculation-vs-ids-arrays-320575 * @throws SdkException if SharedSecret is not provided or hmac is not found in the url parameters */ - public static function verifyShopifyRequest(array $config, array $data): bool { - $sharedSecret = $config['SharedSecret']; + public function verifyShopifyRequest(array $data): bool { + $sharedSecret = $this->config['SharedSecret']; if (!isset($data['hmac']) || !is_string($data['hmac'])) { throw new SdkException("HMAC value not found in url parameters."); @@ -63,15 +78,18 @@ public static function verifyShopifyRequest(array $config, array $data): bool { * @param string|string[] $scopes Scopes required by app * @param string[] $options */ - public static function createAuthRequest( - array $config, + public function createAuthRequest( ?array $scopes, - string $redirectUrl, + ?string $redirectUrl, ?string $state = null, ?array $options = null ): ?string { assert(is_string($scopes) || is_array($scopes)); + if ($redirectUrl === null) { + $redirectUrl = static::getCurrentUrl(); + } + if ($scopes !== null) { $scopes = join(',', $scopes); } @@ -84,24 +102,22 @@ public static function createAuthRequest( $options = '&grant_options[]=' . implode(',', $options); } - // Official call structure - // https://{shop}.myshopify.com/admin/oauth/authorize?client_id={api_key}&scope={scopes}&redirect_uri={redirect_uri}&state={nonce}&grant_options[]={option} - return "{$config['AdminUrl']}oauth/authorize?client_id={$config['ApiKey']}&redirect_uri={$redirectUrl}&scope={$scopes}{$state}{$options}"; + return "{$this->config['AdminUrl']}oauth/authorize?client_id={$this->config['ApiKey']}&redirect_uri={$redirectUrl}&scope={$scopes}{$state}{$options}"; } /** * Get Access token for the API * Call this when being redirected from shopify page ( to the $redirectUrl) after authentication */ - public static function getAccessToken(array $config, array $data): string { - if(self::verifyShopifyRequest($config, $data)) { + public function getAccessToken(array $data): ?string { + if($this->verifyShopifyRequest($data)) { $data = [ 'client_id' => $config['ApiKey'], 'client_secret' => $config['SharedSecret'], 'code' => $data['code'], ]; - $response = HttpRequestJson::post("{$config['AdminUrl']}oauth/access_token", $data); + $response = $this->httpRequestJson->post("{$config['AdminUrl']}oauth/access_token", $data); return $response['access_token'] ?? null; } diff --git a/lib/Http/CurlRequest.php b/lib/Http/CurlRequest.php index 512a27f..f523ab3 100644 --- a/lib/Http/CurlRequest.php +++ b/lib/Http/CurlRequest.php @@ -22,7 +22,7 @@ class CurlRequest { * @param string|string[]|null $data * @return resource */ - protected static function init(string $method, string $url, array $httpHeaders = [], $data = null) { + protected function init(string $method, string $url, array $httpHeaders = [], $data = null) { if (self::$ch === null) { self::$ch = curl_init(); @@ -30,7 +30,7 @@ protected static function init(string $method, string $url, array $httpHeaders = curl_setopt(self::$ch, CURLOPT_HEADER, true); curl_setopt(self::$ch, CURLOPT_USERAGENT, 'PHPClassic/PHPShopify'); } - +vaR_dump($url); curl_setopt(self::$ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt(self::$ch, CURLOPT_URL, $url); @@ -50,7 +50,7 @@ protected static function init(string $method, string $url, array $httpHeaders = return self::$ch; } - public static function destroy(): void { + public function destroy(): void { if (self::$ch !== null) { $ch = self::$ch; self::$ch = null; @@ -58,7 +58,7 @@ public static function destroy(): void { } } - public static function get(string $url, array $httpHeaders = []): CurlResponse { + public function get(string $url, array $httpHeaders = []): CurlResponse { return static::processRequest(static::init('GET', $url, $httpHeaders)); } @@ -66,15 +66,15 @@ public static function get(string $url, array $httpHeaders = []): CurlResponse { * @inheritDoc * @param string|array $data */ - public static function post(string $url, $data, array $httpHeaders = []): CurlResponse { + public function post(string $url, $data, array $httpHeaders = []): CurlResponse { return static::processRequest(static::init('POST', $url, $httpHeaders, $data)); } - public static function put($url, $data, array $httpHeaders = []): CurlResponse { + public function put($url, $data, array $httpHeaders = []): CurlResponse { return static::processRequest(static::init('PUT', $url, $httpHeaders, $data)); } - public static function delete(string $url, array $httpHeaders = []): CurlResponse { + public function delete(string $url, array $httpHeaders = []): CurlResponse { return static::processRequest(static::init('DELETE', $url, $httpHeaders)); } @@ -83,7 +83,7 @@ public static function delete(string $url, array $httpHeaders = []): CurlRespons * @param resource $ch * @throws CurlException if curl request is failed with error */ - protected static function processRequest($ch): CurlResponse { + protected function processRequest($ch): CurlResponse { # Check for 429 leaky bucket error while (true) { $output = curl_exec($ch); @@ -115,7 +115,7 @@ protected static function processRequest($ch): CurlResponse { return $response; } - private static function parseResponse(string $response): array { + protected function parseResponse(string $response): array { $response = explode("\r\n\r\n", $response, 2); assert(count($response) === 2); @@ -139,11 +139,11 @@ private static function parseResponse(string $response): array { return compact('headers', 'body'); } - protected static function serializeData($data): string { + protected function serializeData($data): string { return http_build_query($data); } - protected static function parseBody(string $body) { + protected function parseBody(string $body) { return $body; } } diff --git a/lib/Http/HttpRequestJson.php b/lib/Http/HttpRequestJson.php index 0fa4cb2..b913a98 100644 --- a/lib/Http/HttpRequestJson.php +++ b/lib/Http/HttpRequestJson.php @@ -3,7 +3,7 @@ namespace PHPShopify\Http; class HttpRequestJson extends CurlRequest { - protected static function init(string $method, string $url, array $httpHeaders = [], $data = null) { + protected function init(string $method, string $url, array $httpHeaders = [], $data = null) { // Note: Is null valid for any shopify calls? if ($data !== null) { $httpHeaders['Content-type'] = 'application/json'; @@ -12,11 +12,11 @@ protected static function init(string $method, string $url, array $httpHeaders = return parent::init($method, $url, $httpHeaders, $data); } - protected static function parseBody(string $body) { + protected function parseBody(string $body) { return json_decode($body, true); } - public static function serializeData($data): string { + public function serializeData($data): string { return self::encode($data); } diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index c520a78..9a6bcc0 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -11,8 +11,7 @@ use PHPShopify\Http\HttpRequestJson; use PHPShopify\Http\CurlResponse; -abstract class ShopifyResource -{ +abstract class ShopifyResource { /** * HTTP request headers * @@ -107,8 +106,7 @@ abstract class ShopifyResource /** @var ShopifySDK */ protected $sdk; - public function __construct(ShopifySdk $sdk, $id = null, $parentResourceUrl = '') - { + public function __construct(ShopifySdk $sdk, $id = null, $parentResourceUrl = '') { $this->id = $id; $this->sdk = $sdk; $config = $sdk->getConfig(); @@ -132,8 +130,7 @@ public function __construct(ShopifySdk $sdk, $id = null, $parentResourceUrl = '' * * @return ShopifyResource */ - public function __get($childName) - { + public function __get($childName) { return $this->$childName(); } @@ -153,8 +150,7 @@ public function __get($childName) * * @return mixed / ShopifyResource */ - public function __call($name, $arguments) - { + public function __call($name, $arguments) { if (ctype_upper($name[0])) { $childKey = array_search($name, $this->childResource, true); @@ -163,11 +159,8 @@ public function __call($name, $arguments) } $childClassName = !is_numeric($childKey) ? $childKey : $name; - $childClass = self::class . "\\" . $childClassName; - $resourceId = !empty($arguments) ? $arguments[0] : null; - $api = new $childClass($this->sdk, $resourceId, $this->resourceUrl); - return $api; + return $this->sdk->createResource($childClassName, $arguments, $this->resourceUrl); } else { $actionMaps = [ 'post' => $this->customPostActions, @@ -214,8 +207,7 @@ public function __call($name, $arguments) /** * Get the resource name (or the class name) */ - public function getResourceName(): string - { + public function getResourceName(): string { return substr(get_called_class(), strrpos(get_called_class(), '\\') + 1); } @@ -224,8 +216,7 @@ public function getResourceName(): string * * Normally its the same as $resourceKey, when it's different, the specific resource class will override this function */ - public function getResourcePostKey(): string - { + public function getResourcePostKey(): string { return $this->resourceKey; } @@ -234,8 +225,7 @@ public function getResourcePostKey(): string * * Normally its the same as $resourceKey appended with 's', when it's different, the specific resource class will override this function */ - protected function pluralizeKey(): string - { + protected function pluralizeKey(): string { return $this->resourceKey . 's'; } @@ -245,26 +235,23 @@ protected function pluralizeKey(): string * Normally its the same as the pluralized version of the resource key, * when it's different, the specific resource class will override this function */ - protected function getResourcePath(): string - { + protected function getResourcePath(): string { return $this->pluralizeKey(); } /** * Generate the custom url for api request based on the params and custom action (if any) */ - public function generateUrl(array $urlParams = [], ?string $customAction = null): string - { + public function generateUrl(array $urlParams = [], ?string $customAction = null): string { return $this->resourceUrl . ($customAction ? "/{$customAction}" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''); } - public function get(array $urlParams = [], ?string $url = null, $dataKey = null) - { + public function get(array $urlParams = [], ?string $url = null, $dataKey = null) { if (!$url) { $url = $this->generateUrl($urlParams); } - $response = HttpRequestJson::get($url, $this->httpHeaders); + $response = $this->sdk->getHttpRequestJson()->get($url, $this->httpHeaders); if (!$dataKey) { $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey(); @@ -273,8 +260,7 @@ public function get(array $urlParams = [], ?string $url = null, $dataKey = null) return $this->processResponse($response, $dataKey); } - public function each(array $urlParams = [], ?string $url = null, $dataKey = null): \Generator - { + public function each(array $urlParams = [], ?string $url = null, $dataKey = null): \Generator { if (!$url) { $url = $this->generateUrl($urlParams); } @@ -284,7 +270,7 @@ public function each(array $urlParams = [], ?string $url = null, $dataKey = null } while ($url !== null) { - $response = HttpRequestJson::get($url, $this->httpHeaders); + $response = $this->sdk->getHttpRequestJson()->get($url, $this->httpHeaders); $data = $response->getBody(); @@ -298,8 +284,7 @@ public function each(array $urlParams = [], ?string $url = null, $dataKey = null } } - public function count($urlParams = []) - { + public function count($urlParams = []) { if (!$this->countEnabled) { throw new SdkException("Count is not available for " . $this->getResourceName()); } @@ -309,8 +294,7 @@ public function count($urlParams = []) return $this->get([], $url, 'count'); } - public function search($query) - { + public function search($query) { if (!$this->searchEnabled) { throw new SdkException("Search is not available for " . $this->getResourceName()); } @@ -324,8 +308,7 @@ public function search($query) return $this->get([], $url); } - public function post(?array $dataArray, ?string $url = null, bool $wrapData = true) - { + public function post(?array $dataArray, ?string $url = null, bool $wrapData = true) { if (!$url) { $url = $this->generateUrl(); } @@ -334,13 +317,12 @@ public function post(?array $dataArray, ?string $url = null, bool $wrapData = tr $dataArray = $this->wrapData($dataArray); } - $response = HttpRequestJson::post($url, $dataArray, $this->httpHeaders); + $response = $this->sdk->getHttpRequestJson()->post($url, $dataArray, $this->httpHeaders); return $this->processResponse($response, $this->resourceKey); } - public function put(array $dataArray, ?string $url = null, bool $wrapData = true): array - { + public function put(array $dataArray, ?string $url = null, bool $wrapData = true): array { if (!$url) { $url = $this->generateUrl(); } @@ -349,18 +331,17 @@ public function put(array $dataArray, ?string $url = null, bool $wrapData = true $dataArray = $this->wrapData($dataArray); } - $response = HttpRequestJson::put($url, $dataArray, $this->httpHeaders); + $response = $this->sdk->getHttpRequestJson()->put($url, $dataArray, $this->httpHeaders); return $this->processResponse($response, $this->resourceKey); } - public function delete(array $urlParams = [], ?string $url = null): void - { + public function delete(array $urlParams = [], ?string $url = null): void { if (!$url) { $url = $this->generateUrl($urlParams); } - $response = HttpRequestJson::delete($url, $this->httpHeaders); + $response = $this->sdk->getHttpRequestJson()->delete($url, $this->httpHeaders); $response = $this->processResponse($response); if (!is_array($response) || count($response) !== 0) { @@ -368,8 +349,7 @@ public function delete(array $urlParams = [], ?string $url = null): void } } - protected function wrapData(array $dataArray, $dataKey = null): array - { + protected function wrapData(array $dataArray, $dataKey = null): array { if (!$dataKey) { $dataKey = $this->getResourcePostKey(); } @@ -377,8 +357,7 @@ protected function wrapData(array $dataArray, $dataKey = null): array return [$dataKey => $dataArray]; } - protected static function castString($array): string - { + protected static function castString($array): string { if (!is_array($array)) { return (string)$array; } @@ -401,8 +380,7 @@ protected static function castString($array): string * @throws ApiException if the response has an error specified * @throws CurlException if response received with unexpected HTTP code. */ - protected static function validateResponse(CurlResponse $response, $dataKey = null) - { + protected static function validateResponse(CurlResponse $response, $dataKey = null) { $body = $response->getBody(); if ($body === null) { @@ -424,8 +402,7 @@ protected static function validateResponse(CurlResponse $response, $dataKey = nu return $body; } - protected function processResponse(CurlResponse $response, $dataKey = null) - { + protected function processResponse(CurlResponse $response, $dataKey = null) { $body = self::validateResponse($response); if ($dataKey !== null && isset($body[$dataKey])) { @@ -435,11 +412,10 @@ protected function processResponse(CurlResponse $response, $dataKey = null) return $body; } - protected static function getLinks(CurlResponse $response): ?array - { + protected static function getLinks(CurlResponse $response): ?array { $linkHeader = $response->getHeader('link'); - if($linkHeader === null) { + if ($linkHeader === null) { return null; } diff --git a/lib/ShopifyResource/FulfillmentEvent.php b/lib/ShopifyResource/FulfillmentEvent.php index ec1e8fd..3050b5f 100644 --- a/lib/ShopifyResource/FulfillmentEvent.php +++ b/lib/ShopifyResource/FulfillmentEvent.php @@ -9,11 +9,11 @@ class FulfillmentEvent extends ShopifyResource { protected $resourceKey = 'fulfillment_event'; - public function getResourcePath() { + public function getResourcePath(): string { return 'events'; } - public function getResourcePostKey() { + public function getResourcePostKey(): string { return 'event'; } } diff --git a/lib/ShopifyResource/GraphQL.php b/lib/ShopifyResource/GraphQL.php index 32c2678..28172ca 100644 --- a/lib/ShopifyResource/GraphQL.php +++ b/lib/ShopifyResource/GraphQL.php @@ -5,14 +5,13 @@ namespace PHPShopify\ShopifyResource; -use PHPShopify\Http\HttpRequestJson; use PHPShopify\ShopifyResource; use PHPShopify\Exception\ApiException; use PHPShopify\Exception\CurlException; use PHPShopify\Exception\SdkException; class GraphQL extends ShopifyResource { - protected function getResourcePath() { + protected function getResourcePath(): string { return 'graphql'; } @@ -45,14 +44,14 @@ public function query(string $graphQL, ?string $url = null, ?array $variables = $data = $graphQL; } - return $this->processResponse(HttpRequestJson::post($url, $data, $this->httpHeaders)); + return $this->processResponse($this->sdk->getHttpRequestJson()->post($url, $data, $this->httpHeaders)); } /** * @inheritdoc * @throws SdkException */ - public function get($urlParams = [], $url = null, $dataKey = null) { + public function get(array $urlParams = [], ?string $url = null, $dataKey = null) { throw new SdkException("Only POST method is allowed for GraphQL!"); } @@ -60,7 +59,7 @@ public function get($urlParams = [], $url = null, $dataKey = null) { * @inheritdoc * @throws SdkException */ - public function put($dataArray, $url = null, $wrapData = true) { + public function put(array $dataArray, ?string $url = null, bool $wrapData = true): array { throw new SdkException("Only POST method is allowed for GraphQL!"); } @@ -68,7 +67,7 @@ public function put($dataArray, $url = null, $wrapData = true) { * @inheritdoc * @throws SdkException */ - public function delete($urlParams = [], $url = null) { + public function delete(array $urlParams = [], ?string $url = null): void { throw new SdkException("Only POST method is allowed for GraphQL!"); } } diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index a354f3a..8131c69 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -59,7 +59,9 @@ | $data = $shopify->GraphQL->post($graphQL); | */ + use PHPShopify\Exception\SdkException; +use PHPShopify\Http\HttpRequestJson; /** * @property-read ShopifyResource\AbandonedCheckout $AbandonedCheckout @@ -212,6 +214,9 @@ class ShopifySDK { */ private $config = []; + /** @var HttpRequestJson */ + private $httpRequestJson; + /** * List of resources which are only available through a parent resource * @@ -233,7 +238,7 @@ class ShopifySDK { 'UsageCharge' => 'RecurringApplicationCharge' ]; - public function __construct(array $config = []) { + public function __construct(array $config = [], ?HttpRequestJson $httpRequestJson = null) { $config += ['ApiVersion' => self::$defaultApiVersion]; $shopUrl = $config['ShopUrl']; @@ -252,15 +257,25 @@ public function __construct(array $config = []) { $config['ApiUrl'] = "{$adminUrl}api/{$apiVersion}/"; $this->config = $config; - if (isset($config['AllowedTimePerCall'])) { - static::$timeAllowedForEachApiCall = $config['AllowedTimePerCall']; + if ($httpRequestJson === null) { + $httpRequestJson = new HttpRequestJson(); } + + $this->httpRequestJson = $httpRequestJson; } public function getConfig(): array { return $this->config; } + public function getHttpRequestJson(): HttpRequestJson { + return $this->httpRequestJson; + } + + public function createAuthHelper(): AuthHelper { + return new AuthHelper($this->config, $this->httpRequestJson); + } + /** * Return ShopifyResource instance for a resource. * @example $shopify->Product->get(); //Returns all available Products @@ -296,15 +311,30 @@ public function __call($resourceName, $arguments) { throw new SdkException($message); } - $resourceClassName = ShopifyResource::class . "\\{$resourceName}"; + return $this->createResource($resourceName, $arguments); + } - //If first argument is provided, it will be considered as the ID of the resource. - $resourceID = !empty($arguments) ? $arguments[0] : null; + public function createResource(string $name, array $arguments, string $resourceUrl = '') { + $namespaces = [ShopifyResource::class]; - //Initiate the resource object - $resource = new $resourceClassName($this, $resourceID); + if (isset($this->config['ResourceNamespaces'])) { + $namespaces = array_merge($this->config['ResourceNamespaces'], $namespaces); + } + + foreach ($namespaces as $namespace) { + $resourceClassName = "{$namespace}\\{$name}"; + + if (!class_exists($resourceClassName)) { + continue; + } + + //If first argument is provided, it will be considered as the ID of the resource. + $resourceId = $arguments[0] ?? null; + + return new $resourceClassName($this, $resourceId, $resourceUrl); + } - return $resource; + throw new SdkException("ShopifyResource class {$name} not found."); } /** diff --git a/tests/ShopifyResource/CollectionTest.php b/tests/ShopifyResource/CollectionTest.php deleted file mode 100644 index fe3c014..0000000 --- a/tests/ShopifyResource/CollectionTest.php +++ /dev/null @@ -1,8 +0,0 @@ - Date: Mon, 9 Mar 2020 17:27:18 +0000 Subject: [PATCH 24/29] Some poorly implemented but minimal improvements around error handling. --- lib/Exception/ApiException.php | 13 ++++++- lib/Exception/CurlException.php | 2 +- lib/Exception/ShopUnavailableException.php | 6 ++++ lib/Http/CurlRequest.php | 40 +++++++++++++++++++--- lib/ShopifyResource.php | 2 +- 5 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 lib/Exception/ShopUnavailableException.php diff --git a/lib/Exception/ApiException.php b/lib/Exception/ApiException.php index 325c016..cfb5b27 100644 --- a/lib/Exception/ApiException.php +++ b/lib/Exception/ApiException.php @@ -2,5 +2,16 @@ namespace PHPShopify\Exception; -class ApiException extends \Exception { +class ApiException extends SdkException { + public static function factory(string $message, int $status): void { + if ($message === 'Unavailable Shop') { + throw new ShopUnavailableException($message, $status); + } + + if (preg_match('/Exceeded (\d+) calls per second for api client\. Reduce request rates to resume uninterrupted service\./', $message)) { + throw new ResourceRateLimitException($message, $status); + } + + throw new self($message, $status); + } } diff --git a/lib/Exception/CurlException.php b/lib/Exception/CurlException.php index f16c8e4..b40d91a 100644 --- a/lib/Exception/CurlException.php +++ b/lib/Exception/CurlException.php @@ -2,5 +2,5 @@ namespace PHPShopify\Exception; -class CurlException extends \Exception { +class CurlException extends SdkException { } diff --git a/lib/Exception/ShopUnavailableException.php b/lib/Exception/ShopUnavailableException.php new file mode 100644 index 0000000..db529c5 --- /dev/null +++ b/lib/Exception/ShopUnavailableException.php @@ -0,0 +1,6 @@ +getHeader('X-Shopify-Shop-Api-Call-Limit'), 2); - - if (isset($limitHeader[1]) && $limitHeader[0] < $limitHeader[1]) { + $tries++; + $took = (microtime(true) - $start) + (static::RATE_LIMIT_RETRY_DELAY / 1000000); + + /** + * This makes no sense. It can likely ignore this header and use Retry-After if set otherwise through an + * exception. + */ + if ((isset($limitHeader[1]) && $limitHeader[0] < $limitHeader[1]) || + $tries > static::RATE_LIMIT_RETRIES || $took > static::RATE_LIMIT_TIMEOUT) { throw new ResourceRateLimitException($response->getBody()); } diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 9a6bcc0..1a28285 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -396,7 +396,7 @@ protected static function validateResponse(CurlResponse $response, $dataKey = nu if (isset($body['errors'])) { $message = self::castString($body['errors']); - throw new ApiException($message, $response->getStatus()); + ApiException::factory($message, $response->getStatus()); } return $body; From ae1dba5d9941d4fdfdfad6ec83cbd40ded19797a Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 17:38:10 +0000 Subject: [PATCH 25/29] Small fixes and improvements. --- README.md | 80 +++++++++++++++++----------------------- lib/Http/CurlRequest.php | 2 +- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 2d4575b..9f88fdd 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ $config = [ 'Password' => '***YOUR-PRIVATE-API-PASSWORD***' ]; -$shopifyClient = new PHPShopify\ShopifySDK($config); +$shopify = new PHPShopify\ShopifySDK($config); ``` For Third party apps, use the permanent access token. @@ -39,7 +39,7 @@ $config = [ 'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APP***' ]; -$shopifyClient = new PHPShopify\ShopifySDK($config); +$shopify = new PHPShopify\ShopifySDK($config); ``` ##### How to get the permanent access token for a shop? There is a AuthHelper class to help you getting the permanent access token from the shop using oAuth. @@ -53,8 +53,7 @@ $config = [ 'SharedSecret' => '***YOUR-SHARED-SECRET***' ]; -$shopifyClient = new PHPShopify\ShopifySDK($config); -$shopifyClient = new PHPShopify\ShopifySDK($config); +$shopify = new PHPShopify\ShopifySDK($config); ``` 2) Create the authentication request @@ -68,21 +67,15 @@ $scopes = 'read_products,write_products,read_script_tags,write_script_tags'; //$scopes = array('read_products','write_products','read_script_tags', 'write_script_tags'); $redirectUrl = 'https://yourappurl.com/your_redirect_url.php'; -\PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl); -``` - -> If you want the function to return the authentication url instead of auto-redirecting, you can set the argument `$return` (5th argument) to `true`. - -```php -\PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl, null, null, true); +$url = $shopify->createAuthHelper()->createAuthRequest($scopes, $redirectUrl); ``` 3) Get the access token when redirected back to the `$redirectUrl` after app authorization. ```php //your_redirect_url.php -PHPShopify\ShopifySDK::config($config); -$accessToken = \PHPShopify\AuthHelper::getAccessToken(); +$shopify = new PHPShopify\ShopifySDK($config); +$accessToken = $shopifyClient->createAuthHelper()->getAccessToken($_GET); //Now store it in database or somewhere else ``` @@ -97,12 +90,6 @@ $accessToken = \PHPShopify\AuthHelper::createAuthRequest($scopes); #### Get the ShopifySDK Object -```php -$shopify = new PHPShopify\ShopifySDK; -``` - -You can provide the configuration as a parameter while instantiating the object (if you didn't configure already by calling `config()` method) - ```php $shopify = new PHPShopify\ShopifySDK($config); ``` @@ -119,8 +106,8 @@ $products = $shopify->Product->get(); - Get any specific product with ID (GET request) ```php -$productID = 23564666666; -$product = $shopify->Product($productID)->get(); +$productId = 23564666666; +$product = $shopify->Product($productId)->get(); ``` You can also filter the results by using the url parameters (as specified by Shopify API Reference for each specific resource). @@ -128,11 +115,11 @@ You can also filter the results by using the url parameters (as specified by Sho - For example get the list of cancelled orders after a specified date and time (and `fields` specifies the data columns for each row to be rendered) : ```php -$params = array( +$params = [ 'status' => 'cancelled', 'created_at_min' => '2016-06-25T16:15:47-04:00', 'fields' => 'id,line_items,name,total_price' -); +]; $orders = $shopify->Order->get($params); ``` @@ -140,7 +127,7 @@ $orders = $shopify->Order->get($params); - Create a new order (POST Request) ```php -$order = array ( +$order = [ "email" => "foo@example.com", "fulfillment_status" => "unfulfilled", "line_items" => [ @@ -149,7 +136,7 @@ $order = array ( "quantity" => 5 ] ] -); +]; $shopify->Order->post($order); ``` @@ -160,19 +147,19 @@ $shopify->Order->post($order); - Update an order (PUT Request) ```php -$updateInfo = array ( +$updateInfo = [ "fulfillment_status" => "fulfilled", -); +]; -$shopify->Order($orderID)->put($updateInfo); +$shopify->Order($orderId)->put($updateInfo); ``` - Remove a Webhook (DELETE request) ```php -$webHookID = 453487303; +$webHookId = 453487303; -$shopify->Webhook($webHookID)->delete()); +$shopify->Webhook($webHookId)->delete()); ``` @@ -182,14 +169,14 @@ $shopify->Webhook($webHookID)->delete()); - For example, get the images of a product (GET request) ```php -$productID = 23564666666; -$productImages = $shopify->Product($productID)->Image->get(); +$productId = 23564666666; +$productImages = $shopify->Product($productId)->Image->get(); ``` - Add a new address for a customer (POST Request) ```php -$address = array( +$address = [ "address1" => "129 Oak St", "city" => "Ottawa", "province" => "ON", @@ -198,41 +185,41 @@ $address = array( "last_name" => "Lastnameson", "first_name" => "Mother", "country" => "CA", -); +]; -$customerID = 4425749127; +$customerId = 4425749127; -$shopify->Customer($customerID)->Address->post($address); +$shopify->Customer($customerId)->Address->post($address); ``` - Create a fulfillment event (POST request) ```php -$fulfillmentEvent = array( +$fulfillmentEvent = [ "status" => "in_transit" -); +]; -$shopify->Order($orderID)->Fulfillment($fulfillmentID)->Event->post($fulfillmentEvent); +$shopify->Order($orderId)->Fulfillment($fulfillmentId)->Event->post($fulfillmentEvent); ``` - Update a Blog article (PUT request) ```php -$blogID = 23564666666; -$articleID = 125336666; -$updateArtilceInfo = array( +$blogId = 23564666666; +$articleId = 125336666; +$updateArticleInfo = [ "title" => "My new Title", "author" => "Your name", "tags" => "Tags, Will Be, Updated", "body_html" => "

Look, I can even update through a web service.<\/p>", -); -$shopify->Blog($blogID)->Article($articleID)->put($updateArtilceInfo); +]; +$shopify->Blog($blogId)->Article($articleId)->put($updateArticleInfo); ``` - Delete any specific article from a specific blog (DELETE request) ```php -$blogArticle = $shopify->Blog($blogID)->Article($articleID)->delete(); +$blogArticle = $shopify->Blog($blogId)->Article($articleId)->delete(); ``` ### GraphQL *v1.1* @@ -260,7 +247,6 @@ $data = $shopify->GraphQL->post($graphQL); ##### GraphQL Builder This SDK only accepts a GraphQL string as input. You can build your GraphQL from [Shopify GraphQL Builder](https://help.shopify.com/en/api/graphql-admin-api/graphiql-builder) - ### Resource Mapping Some resources are available directly, some resources are only available through parent resources and a few resources can be accessed both ways. It is recommended that you see the details in the related Shopify API Reference page about each resource. Each resource name here is linked to related Shopify API Reference page. > Use the resources only by listed resource map. Trying to get a resource directly which is only available through parent resource may end up with errors. @@ -346,7 +332,7 @@ $productCount = $shopify->Product->count(); - Make an address default for the customer. ```php -$shopify->Customer($customerID)->Address($addressID)->makeDefault(); +$shopify->Customer($customerId)->Address($addressId)->makeDefault(); ``` - Search for customers with keyword "Bob" living in country "United States". diff --git a/lib/Http/CurlRequest.php b/lib/Http/CurlRequest.php index 93b40e3..b703ddb 100644 --- a/lib/Http/CurlRequest.php +++ b/lib/Http/CurlRequest.php @@ -133,7 +133,7 @@ protected function processRequest($ch): CurlResponse { $took = (microtime(true) - $start) + (static::RATE_LIMIT_RETRY_DELAY / 1000000); /** - * This makes no sense. It can likely ignore this header and use Retry-After if set otherwise through an + * This makes no sense. It can likely ignore this header and use Retry-After if set otherwise throw an * exception. */ if ((isset($limitHeader[1]) && $limitHeader[0] < $limitHeader[1]) || From 7d8c238e63649b2f9ae6b1fb180bae5135166ccd Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 18:19:18 +0000 Subject: [PATCH 26/29] Change imaginary brand from Coconut to Pineapple. --- tests/ShopifyResource/SmartCollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ShopifyResource/SmartCollectionTest.php b/tests/ShopifyResource/SmartCollectionTest.php index 759009b..1a4e2f8 100644 --- a/tests/ShopifyResource/SmartCollectionTest.php +++ b/tests/ShopifyResource/SmartCollectionTest.php @@ -12,7 +12,7 @@ class SmartCollectionTest extends TestSimpleResource { [ "column" => "vendor", "relation" => "equals", - "condition" => "Coconut" + "condition" => "Pineapple" ] ] ]; From 7485bfcda2623b3ea9cd37025bdce38a67873edb Mon Sep 17 00:00:00 2001 From: joeyhub Date: Mon, 9 Mar 2020 19:15:46 +0000 Subject: [PATCH 27/29] Use this for config. --- lib/AuthHelper.php | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index 0117c3d..4a98a77 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -71,38 +71,44 @@ public function verifyShopifyRequest(array $data): bool { } /** - * Redirect the user to the authorization page to allow the app access to the shop + * Get the URL to redirected the user to authorize app access to the shop. * * @see https://help.shopify.com/api/guides/authentication/oauth#scopes For allowed scopes * @inheritDoc - * @param string|string[] $scopes Scopes required by app - * @param string[] $options + * @param string|string[] $scope Scopes required by app + * @param string[] $grantOptions */ - public function createAuthRequest( - ?array $scopes, + public function createAuthUrl( + ?array $scope, ?string $redirectUrl, ?string $state = null, - ?array $options = null + ?array $grantOptions = null ): ?string { - assert(is_string($scopes) || is_array($scopes)); + assert(is_string($scope) || is_array($scope)); if ($redirectUrl === null) { $redirectUrl = static::getCurrentUrl(); } - if ($scopes !== null) { - $scopes = join(',', $scopes); + $parameters = [ + 'client_id' => $this->config['ApiKey'], + 'redirect_uri' => $redirectUrl + ]; + + if ($scope !== null) { + $parameters['scope'] = join(',', $scope); } if ($state !== null) { - $state = '&state=' . $state; + $parameters['state'] = $state; } - if ($options !== null) { - $options = '&grant_options[]=' . implode(',', $options); + if ($grantOptions !== null) { + $parameters['grant_options'] = [implode(',', $grantOptions)]; } - return "{$this->config['AdminUrl']}oauth/authorize?client_id={$this->config['ApiKey']}&redirect_uri={$redirectUrl}&scope={$scopes}{$state}{$options}"; + $parameters = http_build_query($parameters); + return "{$this->config['AdminUrl']}oauth/authorize?{$parameters}"; } /** @@ -112,12 +118,12 @@ public function createAuthRequest( public function getAccessToken(array $data): ?string { if($this->verifyShopifyRequest($data)) { $data = [ - 'client_id' => $config['ApiKey'], - 'client_secret' => $config['SharedSecret'], + 'client_id' => $this->config['ApiKey'], + 'client_secret' => $this->config['SharedSecret'], 'code' => $data['code'], ]; - $response = $this->httpRequestJson->post("{$config['AdminUrl']}oauth/access_token", $data); + $response = $this->httpRequestJson->post("{$this->config['AdminUrl']}oauth/access_token", $data); return $response['access_token'] ?? null; } From f76ff7c41d58acf752587eee8a76210cfd77374e Mon Sep 17 00:00:00 2001 From: joeyhub Date: Tue, 10 Mar 2020 16:54:25 +0000 Subject: [PATCH 28/29] Fix grant options. --- lib/AuthHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index 4a98a77..90ccf37 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -96,7 +96,7 @@ public function createAuthUrl( ]; if ($scope !== null) { - $parameters['scope'] = join(',', $scope); + $parameters['scope'] = implode(',', $scope); } if ($state !== null) { @@ -104,7 +104,7 @@ public function createAuthUrl( } if ($grantOptions !== null) { - $parameters['grant_options'] = [implode(',', $grantOptions)]; + $parameters['grant_options[]'] = implode(',', $grantOptions); } $parameters = http_build_query($parameters); From d320c8a8baa05fbba47c734625ecb9374d85e5f6 Mon Sep 17 00:00:00 2001 From: joeyhub Date: Thu, 19 Mar 2020 15:54:40 +0000 Subject: [PATCH 29/29] Delete has a null response. --- lib/ShopifyResource.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 1a28285..b2cfda1 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -344,7 +344,7 @@ public function delete(array $urlParams = [], ?string $url = null): void { $response = $this->sdk->getHttpRequestJson()->delete($url, $this->httpHeaders); $response = $this->processResponse($response); - if (!is_array($response) || count($response) !== 0) { + if ($response !== null) { throw new SdkException('Unexpected API response on delete: ' . HttpRequestJson::encode($response)); } } @@ -380,7 +380,7 @@ protected static function castString($array): string { * @throws ApiException if the response has an error specified * @throws CurlException if response received with unexpected HTTP code. */ - protected static function validateResponse(CurlResponse $response, $dataKey = null) { + protected static function validateResponse(CurlResponse $response) { $body = $response->getBody(); if ($body === null) { @@ -405,8 +405,8 @@ protected static function validateResponse(CurlResponse $response, $dataKey = nu protected function processResponse(CurlResponse $response, $dataKey = null) { $body = self::validateResponse($response); - if ($dataKey !== null && isset($body[$dataKey])) { - return $body[$dataKey]; + if ($dataKey !== null) { + return $body[$dataKey] ?? null; } return $body;