@@ -382,7 +382,7 @@ private function process(string $method, ?array $query, $data = false)
382382 }
383383 $ result = $ this ->getResponseBody ($ response );
384384 if ($ pager ) {
385- $ page = $ pager ->getPage ($ result , $ request , $ response , $ this , null , $ query );
385+ $ page = $ pager ->getPage ($ result , $ request , $ response , $ this , null , null , $ query );
386386 return Arr::unwrap ($ page ->getEntities (), 1 );
387387 }
388388 return $ result ;
@@ -444,16 +444,18 @@ private function paginate(string $method, ?array $query, $data = false): iterabl
444444 $ request = $ this ->createRequest ($ method , $ query , $ data );
445445 $ request = $ pager ->getFirstRequest ($ request , $ this , $ query );
446446 $ prev = null ;
447+ $ yielded = 0 ;
447448 do {
448449 if ($ request instanceof CurlerPageRequestInterface) {
449450 $ query = $ request ->getQuery () ?? $ query ;
450451 $ request = $ request ->getRequest ();
451452 }
452453 $ response = $ this ->doSendRequest ($ request );
453454 $ result = $ this ->getResponseBody ($ response );
454- $ page = $ pager ->getPage ($ result , $ request , $ response , $ this , $ prev , $ query );
455+ $ page = $ pager ->getPage ($ result , $ request , $ response , $ this , $ prev , $ prev ? $ yielded : null , $ query );
455456 // Use `yield` instead of `yield from` so entities get unique keys
456457 foreach ($ page ->getEntities () as $ entity ) {
458+ $ yielded ++;
457459 yield $ entity ;
458460 }
459461 if (!$ page ->hasNextRequest ()) {
@@ -1209,6 +1211,7 @@ static function ($handle, string $data) use (&$bodyIn): int {
12091211 self ::$ Handle = $ handle ;
12101212 $ resetHandle = false ;
12111213 } else {
1214+ $ handle = self ::$ Handle ;
12121215 $ opt [\CURLOPT_URL ] = (string ) $ uri ;
12131216 $ resetHandle = true ;
12141217 }
@@ -1291,32 +1294,32 @@ static function ($handle, string $data) use (&$bodyIn): int {
12911294
12921295 if ($ resetHandle || !$ transfer ) {
12931296 if ($ resetHandle ) {
1294- curl_reset (self :: $ Handle );
1297+ curl_reset ($ handle );
12951298 $ resetHandle = false ;
12961299 }
12971300 $ opt [\CURLOPT_HTTPHEADER ] = $ headers ->getLines ('%s: %s ' , '%s; ' );
1298- curl_setopt_array (self :: $ Handle , $ opt );
1301+ curl_setopt_array ($ handle , $ opt );
12991302
13001303 if ($ this ->CookiesCacheKey !== null ) {
13011304 // "If the name is an empty string, no cookies are loaded,
13021305 // but cookie handling is still enabled"
1303- curl_setopt (self :: $ Handle , \CURLOPT_COOKIEFILE , '' );
1306+ curl_setopt ($ handle , \CURLOPT_COOKIEFILE , '' );
13041307 /** @var non-empty-string[] */
13051308 $ cookies = $ this ->getCacheInstance ()->getArray ($ this ->CookiesCacheKey );
13061309 if ($ cookies ) {
13071310 foreach ($ cookies as $ cookie ) {
1308- curl_setopt (self :: $ Handle , \CURLOPT_COOKIELIST , $ cookie );
1311+ curl_setopt ($ handle , \CURLOPT_COOKIELIST , $ cookie );
13091312 }
13101313 }
13111314 }
13121315 }
13131316
13141317 $ transfer ++;
13151318
1316- Event::dispatch (new CurlRequestEvent ($ this , self :: $ Handle , $ request ));
1317- $ result = curl_exec (self :: $ Handle );
1319+ Event::dispatch (new CurlRequestEvent ($ this , $ handle , $ request ));
1320+ $ result = curl_exec ($ handle );
13181321 if ($ result === false ) {
1319- throw new CurlErrorException (curl_errno (self :: $ Handle ), $ request , $ this ->getCurlInfo ());
1322+ throw new CurlErrorException (curl_errno ($ handle ), $ request , $ this ->getCurlInfo ());
13201323 }
13211324
13221325 if (
@@ -1336,12 +1339,12 @@ static function ($handle, string $data) use (&$bodyIn): int {
13361339 $ code = (int ) $ split [1 ];
13371340 $ reason = $ split [2 ] ?? null ;
13381341 $ response = new Response ($ code , $ bodyIn , $ headersIn , $ reason , $ version );
1339- Event::dispatch (new CurlResponseEvent ($ this , self :: $ Handle , $ request , $ response ));
1342+ Event::dispatch (new CurlResponseEvent ($ this , $ handle , $ request , $ response ));
13401343
13411344 if ($ this ->CookiesCacheKey !== null ) {
13421345 $ this ->getCacheInstance ()->set (
13431346 $ this ->CookiesCacheKey ,
1344- curl_getinfo (self :: $ Handle , \CURLINFO_COOKIELIST )
1347+ curl_getinfo ($ handle , \CURLINFO_COOKIELIST )
13451348 );
13461349 }
13471350
@@ -1397,7 +1400,7 @@ static function ($handle, string $data) use (&$bodyIn): int {
13971400 $ resetHandle = true ;
13981401 } else {
13991402 curl_setopt (
1400- self :: $ Handle ,
1403+ $ handle ,
14011404 \CURLOPT_URL ,
14021405 // @phpstan-ignore argument.type
14031406 $ opt [\CURLOPT_URL ] = (string ) $ uri ,
0 commit comments