@@ -30,6 +30,11 @@ abstract class Walmart
3030{
3131 public const VERSION = '0.6.3 ' ;
3232
33+ /**
34+ * The base URL for all API requests. This can be overridden in child classes.
35+ */
36+ public const HOST = 'https://marketplace.walmartapis.com ' ;
37+
3338 /**
3439 * The configuration for this client.
3540 * @var Configuration
@@ -46,11 +51,57 @@ abstract class Walmart
4651 * Create a new Walmart client.
4752 *
4853 * @param Configuration $config The configuration for this client.
49- * @param ?string $country The country to use for this client.
54+ * @param bool $clone If false, the configuration object will be used as-is. If true, the
55+ * configuration object will be cloned before use. Default is true.
56+ */
57+ public function __construct (Configuration $ config , protected bool $ clone = true )
58+ {
59+ // We clone $config so that if the same Configuration object is used for multiple API
60+ // instances, the host changes made in the ::contentProvider(), ::marketplace(), and
61+ // ::supplier() methods don't affect the other API instances.
62+ if ($ this ->clone ) {
63+ $ this ->config = clone $ config ;
64+ } else {
65+ $ this ->config = $ config ;
66+ }
67+
68+ $ config ->setHost (static ::HOST );
69+ }
70+
71+ /**
72+ * Return an instance of the Content Provider API provider.
73+ *
74+ * @param Configuration $config
75+ * @param bool $clone
76+ * @return ContentProviderApi
77+ */
78+ public static function contentProvider (Configuration $ config , bool $ clone = true ): ContentProviderApi
79+ {
80+ return new ContentProviderApi ($ config , $ clone );
81+ }
82+
83+ /**
84+ * Return an instance of the Marketplace API provider.
85+ *
86+ * @param Configuration $config
87+ * @param bool $clone
88+ * @return MarketplaceApi
5089 */
51- public function __construct (Configuration $ config)
90+ public static function marketplace (Configuration $ config, bool $ clone = true ): MarketplaceApi
5291 {
53- $ this ->config = $ config ;
92+ return new MarketplaceApi ($ config , $ clone );
93+ }
94+
95+ /**
96+ * Return an instance of the 1P Supplier API provider.
97+ *
98+ * @param Configuration $config
99+ * @param bool $clone
100+ * @return SupplierApi
101+ */
102+ public static function supplier (Configuration $ config , bool $ clone = true ): SupplierApi
103+ {
104+ return new SupplierApi ($ config , $ clone );
54105 }
55106
56107 /**
@@ -84,37 +135,4 @@ public function __call($name, $arguments)
84135 $ apiClass = static ::$ countryApiMap [$ name ][$ this ->config ->getCountry ()];
85136 return new $ apiClass ($ this ->config );
86137 }
87-
88- /**
89- * Return an instance of the Content Provider API provider.
90- *
91- * @param Configuration $config
92- * @return ContentProviderApi
93- */
94- public static function contentProvider (Configuration $ config ): ContentProviderApi
95- {
96- return new ContentProviderApi ($ config );
97- }
98-
99- /**
100- * Return an instance of the 1P Supplier API provider.
101- *
102- * @param Configuration $config
103- * @return SupplierApi
104- */
105- public static function supplier (Configuration $ config ): SupplierApi
106- {
107- return new SupplierApi ($ config );
108- }
109-
110- /**
111- * Return an instance of the Marketplace API provider.
112- *
113- * @param Configuration $config
114- * @return MarketplaceApi
115- */
116- public static function marketplace (Configuration $ config ): MarketplaceApi
117- {
118- return new MarketplaceApi ($ config );
119- }
120138}
0 commit comments