src/LearnositySdk/Request/DataApi.php
public function requestRecursive($endpoint, $securityPacket, $secret, /* FIXME: array */ $requestPacket = [], $action = null, $callback = null)
    {
        $response = array();

        if (!is_array($requestPacket)) {
            Init::warnDeprecated(
                __CLASS__ . '::' . __FUNCTION__ . ':'
                . ' $requestPacket should be a PHP array.'
            );
        }

        do {
            $request = $this->request($endpoint, $securityPacket, $secret, $requestPacket, $action);
            $data = Json::isJson($request->getBody()) ? json_decode($request->getBody(), true) : $request->getBody();
            if ($data['meta']['status'] === true) {
                if (!empty($callback) && is_callable($callback)) {
                    call_user_func($callback, $data);
                } else {
                    $response = array_merge($response, $data['data']);
                }
            } else {
                throw new Exception(Json::encode($data));
            }
            if (array_key_exists('next', $data['meta']) && !empty($data['data'])) {
                $requestPacket['next'] = $data['meta']['next'];
            } else {
                unset($requestPacket['next']);
            }
        } while (array_key_exists('next', $requestPacket));

        return $response;
    }
public function requestRecursive($endpoint, $securityPacket, $secret, /* FIXME: array */ $requestPacket = [], $action = null, $callback = null)
    {
        $response = array();

        if (!is_array($requestPacket)) {
            Init::warnDeprecated(
                __CLASS__ . '::' . __FUNCTION__ . ':'
                . ' $requestPacket should be a PHP array.'
            );
        }

        do {
            $request = $this->request($endpoint, $securityPacket, $secret, $requestPacket, $action);
            $data = Json::isJson($request->getBody()) ? json_decode($request->getBody(), true) : $request->getBody();
            if ($data['meta']['status'] === true) {
                if (!empty($callback) && is_callable($callback)) {
                    call_user_func($callback, $data);
                } else {
                    $response = array_merge($response, $data['data']);
                }
            } else {
                throw new Exception(Json::encode($data));
            }
            if (array_key_exists('next', $data['meta']) && !empty($data['data'])) {
                $requestPacket['next'] = $data['meta']['next'];
            } else {
                unset($requestPacket['next']);
            }
        } while (array_key_exists('next', $requestPacket));

        return $response;
    }
public function requestRecursive ( $ endpoint , $ securityPacket , $ secret , /* FIXME: array */ $ requestPacket = [ ] , $ action = null , $ callback = null ) { $ response = array ( ) ; if ( ! is_array ( $ requestPacket ) ) { Init :: warnDeprecated ( __CLASS__ . '::' . __FUNCTION__ . ':' . ' $requestPacket should be a PHP array.' ) ; } do { $ request = $ this -> request ( $ endpoint , $ securityPacket , $ secret , $ requestPacket , $ action ) ; $ data = Json :: isJson ( $ request -> getBody ( ) ) ? json_decode ( $ request -> getBody ( ) , true ) : $ request -> getBody ( ) ; if ( $ data [ 'meta' ] [ 'status' ] === true ) { if ( ! empty ( $ callback ) && is_callable ( $ callback ) ) { call_user_func ( $ callback , $ data ) ; } else { $ response = array_merge ( $ response , $ data [ 'data' ] ) ; } } else { throw new Exception ( Json :: encode ( $ data ) ) ; } if ( array_key_exists ( 'next' , $ data [ 'meta' ] ) && ! empty ( $ data [ 'data' ] ) ) { $ requestPacket [ 'next' ] = $ data [ 'meta' ] [ 'next' ] ; } else { unset ( $ requestPacket [ 'next' ] ) ; } } while ( array_key_exists ( 'next' , $ requestPacket ) ) ; return $ response ; }
Makes a recursive request to the data api, dependant on
whether 'next' is returned in the meta object

@param  string  $endpoint       URL to send the request
@param  array   $securityPacket Security details
@param  string  $secret         Private key
@param  array   $requestPacket  Request packet
@param  string  $action         Action for the request
@param  mixed   $callback       Optional callback to execute instead of returning data
@return array                   Array of all data requests or [] or using a callback
Makes a recursive request to the data api dependant on whether next is returned in the meta object