2727
2828class Client extends AbstractClient
2929{
30+ use CallOptionsTrait;
31+
3032 /**
3133 * @var string
3234 */
@@ -42,11 +44,6 @@ class Client extends AbstractClient
4244 */
4345 protected $ sObjectClient ;
4446
45- /**
46- * @var array
47- */
48- protected $ callOptions = [];
49-
5047 public function __construct (AuthProviderInterface $ provider , string $ version = "44.0 " , ?string $ appName = null )
5148 {
5249 if (null !== $ appName ) {
@@ -57,18 +54,8 @@ public function __construct(AuthProviderInterface $provider, string $version = "
5754 $ this ->authProvider = $ provider ;
5855 $ this ->client = $ this ->createHttpClient ();
5956 $ this ->serializer = $ this ->createSerializer ();
60- $ this ->compositeClient = new CompositeClient (
61- $ this ->client ,
62- $ this ->serializer ,
63- $ this ->authProvider ,
64- $ this ->version
65- );
66- $ this ->sObjectClient = new SObject \Client (
67- $ this ->client ,
68- $ this ->serializer ,
69- $ this ->authProvider ,
70- $ this ->version
71- );
57+ $ this ->compositeClient = new CompositeClient ($ this );
58+ $ this ->sObjectClient = new SObject \Client ($ this );
7259 }
7360
7461 /**
@@ -138,6 +125,18 @@ public function limits(): Limits
138125 );
139126 }
140127
128+ /**
129+ * @param string $method
130+ * @param string $path
131+ * @param null $payload
132+ * @param string $responseType
133+ * @param array $headers
134+ * @param int $expectedResponseCode
135+ *
136+ * @return array|\JMS\Serializer\scalar|null|object
137+ * @throws SessionExpiredOrInvalidException
138+ * @throws \GuzzleHttp\Exception\GuzzleException
139+ */
141140 public function apex (
142141 string $ method ,
143142 string $ path ,
@@ -152,22 +151,8 @@ public function apex(
152151 $ body = null !== $ payload ? $ this ->serializer ->serialize ($ payload , 'json ' ) : null ;
153152 $ request = new Request ($ method , '/services/apexrest ' .$ path , $ headers , $ body );
154153
155- $ response = $ this ->client ->request ($ request );
156-
157- try {
158- $ this ->throwErrorIfInvalidResponseCode ($ response , $ expectedResponseCode );
159- } catch (SessionExpiredOrInvalidException $ e ) {
160- return $ this ->apex (
161- $ method ,
162- $ path ,
163- $ payload ,
164- $ responseType ,
165- $ headers ,
166- $ expectedResponseCode
167- );
168- }
169-
170- $ resBody = (string )$ response ->getBody ();
154+ $ response = $ this ->send ($ request , $ expectedResponseCode );
155+ $ resBody = (string )$ response ->getBody ();
171156
172157 if (null !== $ resBody ) {
173158 return $ this ->serializer ->deserialize (
@@ -265,12 +250,12 @@ function (HandlerRegistry $handler) {
265250 return $ builder ->build ();
266251 }
267252
268- protected function authorize (RequestInterface $ request ): RequestInterface
253+ public function authorize (RequestInterface $ request ): RequestInterface
269254 {
270255 return $ request ->withAddedHeader ('Authorization ' , $ this ->authProvider ->authorize ());
271256 }
272257
273- protected function appendSforceCallOptions (RequestInterface $ request ): RequestInterface
258+ public function appendSforceCallOptions (RequestInterface $ request ): RequestInterface
274259 {
275260 $ callOptions = array_reduce (
276261 array_keys ($ this ->callOptions ),
@@ -292,7 +277,7 @@ function (array $carry, $key) {
292277 return $ request ;
293278 }
294279
295- protected function send (RequestInterface $ request , $ expectedStatusCode = 200 )
280+ public function send (RequestInterface $ request , $ expectedStatusCode = 200 )
296281 {
297282 return parent ::send ($ this ->appendSforceCallOptions ($ request ), $ expectedStatusCode );
298283 }
0 commit comments