Comments (1)
For what it's worth, I've been using something like this as a wrapper.
<?php namespace PayPerClick\Market\Facebook\Data;
use FacebookAds\Cursor;
/**
* Class ReportCursor
*
* @package PayPerClick\Market\Facebook\Data
*/
class ReportCursor implements \Iterator, \Countable, \ArrayAccess {
/**
* @type int
*/
protected $position = 0;
/**
* @type Cursor[]
*/
protected $cursors = [];
/**
* @param Cursor $cursor
*/
public function __construct(Cursor $cursor) {
$cursor->setUseImplicitFetch(false);
$this->cursors[] = $cursor;
}
/**
* @return Cursor
*/
public function getCursor() {
return $this->cursors[ $this->position ];
}
public function current() {
return $this->getCursor()->current()->getData();
}
public function next() {
$this->getCursor()->next();
if ($this->getCursor()->key() === null) {
$this->advanceCursors();
}
}
protected function advanceCursors() {
if ($this->hasCursor($this->position+1)) {
$this->getCursor()->rewind();
$this->position++;
} else if ($this->hasNextPage()) {
$this->fetchNext();
}
}
/**
* @return bool
*/
protected function hasNextPage() {
return $this->getNextPage() !== null;
}
/**
* @return string|null
*/
protected function getNextPage() {
$content = $this->getCursor()->getLastResponse()->getContent();
return isset($content['paging']['next']) ? $content['paging']['next'] : null;
}
/**
* @param int $offset
* @return bool
*/
protected function hasCursor($offset) {
return isset($this->cursors[ $offset ]);
}
protected function fetchNext() {
parse_str(parse_url($this->getNextPage(), PHP_URL_QUERY), $previousParams);
$objectPrototype = clone $this->getCursor()->offsetGet($this->getCursor()->getIndexRight());
$request = $this->getCursor()->getLastResponse()->getRequest()->createClone();
$request->getQueryParams()->offsetSet('offset', $previousParams['offset']);
$this->getCursor()->rewind();
$this->position++;
$this->cursors[ $this->position ] = new Cursor($request->execute(), $objectPrototype);
}
public function key() {
return $this->getCursor()->key();
}
public function valid() {
return $this->getCursor()->valid();
}
public function rewind() {
$this->position = 0;
}
public function offsetExists($offset) {
return $this->getCursor()->offsetExists($offset);
}
public function offsetGet($offset) {
return $this->getCursor()->offsetGet($offset);
}
public function offsetSet($offset, $value) {
$this->getCursor()->offsetSet($offset, $value);
}
public function offsetUnset($offset) {
$this->getCursor()->offsetUnset($offset);
}
public function count() {
return array_reduce($this->cursors, function ($a, $cursor) {
return $a + $cursor->count();
}, 0);
}
}
from facebook-php-business-sdk.
Related Issues (20)
- getDefaultRequestHeaders() is misspelled as getDefaultRequestHeaderds() HOT 1
- PHP 8.1 Deprecation HOT 4
- syntax error, unexpected '|', expecting ';' or '{' HOT 4
- Union types are only allowed since php8 HOT 2
- Exception: field 'id' is required Error HOT 2
- شخص ما أخترق حسابي الشخصي
- Normalizer.php strlen() must be of type string Problem
- Facebook Multi-Language Ads
- Syntax error in FB version v16.0.0 HOT 1
- The AdAccountFields enum does not currently implement the ACCOUNT_STATUS field. HOT 1
- Exception thrown without a stack frame in Unknown on line 0 HOT 1
- How to create a AAA advertisements above version 17
- Fix package installation instructions in README file
- Fff HOT 1
- error
- ad creative Url Tracking Params Update HOT 1
- OpenSSL SSL_connect: Connection reset by peer in connection to graph.facebook.com:443 Error
- Static singletons used everywhere HOT 3
- Incorrect PHPDoc types HOT 2
- Not able to access Business User Insights for multiple users using the Instagram API.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facebook-php-business-sdk.