@@ -27,18 +27,33 @@ class PrerenderClient implements PrerenderClientInterface
2727 /** @var LoggerInterface */
2828 private LoggerInterface $ logger ;
2929
30+ /**
31+ *
32+ * @param Config $prerenderConfigHelper
33+ * @param ClientInterface $client
34+ * @param SerializerInterface $jsonSerializer
35+ * @param LoggerInterface $logger
36+ */
3037 public function __construct (
3138 Config $ prerenderConfigHelper ,
3239 ClientInterface $ client ,
3340 SerializerInterface $ jsonSerializer ,
3441 LoggerInterface $ logger
3542 ) {
3643 $ this ->prerenderConfigHelper = $ prerenderConfigHelper ;
37- $ this ->client = $ client ;
3844 $ this ->jsonSerializer = $ jsonSerializer ;
3945 $ this ->logger = $ logger ;
46+ $ this ->client = $ client ;
47+ $ this ->client ->addHeader ('content-type ' , 'application/json ' );
4048 }
4149
50+ /**
51+ * Call Prerender.io API to recache list of URLs
52+ *
53+ * @param array $urls
54+ * @param int $storeId
55+ * @return void
56+ */
4257 public function recacheUrls (array $ urls , int $ storeId ): void
4358 {
4459 if (!$ this ->prerenderConfigHelper ->isRecacheEnabled ($ storeId )) {
@@ -50,16 +65,19 @@ public function recacheUrls(array $urls, int $storeId): void
5065 return ;
5166 }
5267
53- if (count ($ urls ) > self ::MAX_URLS ) {
54- $ batches = array_chunk ($ urls , self ::MAX_URLS );
55- foreach ($ batches as $ batch ) {
56- $ this ->sendRequest ($ batch , $ token );
57- }
58- } else {
59- $ this ->sendRequest ($ urls , $ token );
68+ $ batches = array_chunk ($ urls , self ::MAX_URLS );
69+ foreach ($ batches as $ batch ) {
70+ $ this ->sendRequest ($ batch , $ token );
6071 }
6172 }
6273
74+ /**
75+ * Sends a JSON POST request to Prerender.io
76+ *
77+ * @param array $urls
78+ * @param string $token
79+ * @return void
80+ */
6381 private function sendRequest (array $ urls , string $ token ): void
6482 {
6583 $ payload = $ this ->jsonSerializer ->serialize (
@@ -68,7 +86,6 @@ private function sendRequest(array $urls, string $token): void
6886 'urls ' => $ urls
6987 ]
7088 );
71- $ this ->client ->addHeader ('content-type ' , 'application/json ' );
7289 try {
7390 $ this ->client ->post (self ::PRERENDER_RECACHE_URL , $ payload );
7491 } catch (\Exception $ e ) {
0 commit comments