示例#1
0
 protected static function createScroller(array $config)
 {
     if (empty($config['method'])) {
         return NoScroller::create([]);
     }
     switch ($config['method']) {
         case 'offset':
             return OffsetScroller::create($config);
         case 'response.param':
             return ResponseParamScroller::create($config);
         case 'response.url':
             return ResponseUrlScroller::create($config);
         case 'zendesk.response.url':
             return ZendeskResponseUrlScroller::create($config);
         case 'facebook.response.url':
             return FacebookResponseUrlScroller::create($config);
         case 'pagenum':
             return PageScroller::create($config);
         case 'cursor':
             return CursorScroller::create($config);
         case 'multiple':
             return MultipleScroller::create($config);
         default:
             $method = is_string($config['method']) ? $config['method'] : json_encode($config['method']);
             throw new UserException("Unknown pagination method '{$method}'");
             break;
     }
 }
示例#2
0
 public function testSetState()
 {
     $client = RestClient::create();
     $config = new JobConfig('test', ['endpoint' => 'test']);
     $scroller = new PageScroller(['pageParam' => 'p']);
     $first = $scroller->getFirstRequest($client, $config);
     $second = $scroller->getNextRequest($client, $config, new \stdClass(), ['item']);
     $state = $scroller->getState();
     $newScroller = new PageScroller([]);
     $newScroller->setState($state);
     $third = $newScroller->getNextRequest($client, $config, new \stdClass(), ['item']);
     self::assertEquals(3, $third->getParams()['p']);
 }