private function simulateCpsPagination(PagerInterface $pager, array $result, array $array_search_haystack = null): array
    {
        $array_search_haystack = $array_search_haystack ?? $result;
        // If start key is null let's set it to the first key in the
        // result just like the API would do.
        $start_key = $pager->getStartKey() ?? reset($array_search_haystack);
        $offset = array_search($start_key, $array_search_haystack);
        // Start key has not been found in the response. Apigee Edge with
        // CPS enabled would return an HTTP 404, with error code
        // "keymanagement.service.[ENTITY_TYPE]_doesnot_exist" which would
        // trigger a ClientErrorException. We throw a RuntimeException
        // instead of that because it does not require to construct an
        // API response object.
        if (false === $offset) {
            throw new RuntimeException(sprintf('CPS simulation error: "%s" does not exist.', $start_key));
        }
        // The default pagination limit (aka. "count") on CPS supported
        // listing endpoints varies. When this script was written it was
        // 1000 on two endpoints and 100 on two app related endpoints,
        // namely List Developer Apps and List Company Apps. A
        // developer/company should not have 100 apps, this is
        // the reason why this limit is smaller. Therefore we choose to
        // use 1000 as pagination limit if it has not been set.
        // https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/apiproducts-0
        // https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/developers
        // https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/developers/%7Bdeveloper_email_or_id%7D/apps
        return array_slice($result, $offset, $pager->getLimit() ?: 1000, true);
    }
private function simulateCpsPagination(PagerInterface $pager, array $result, array $array_search_haystack = null): array
    {
        $array_search_haystack = $array_search_haystack ?? $result;
        // If start key is null let's set it to the first key in the
        // result just like the API would do.
        $start_key = $pager->getStartKey() ?? reset($array_search_haystack);
        $offset = array_search($start_key, $array_search_haystack);
        // Start key has not been found in the response. Apigee Edge with
        // CPS enabled would return an HTTP 404, with error code
        // "keymanagement.service.[ENTITY_TYPE]_doesnot_exist" which would
        // trigger a ClientErrorException. We throw a RuntimeException
        // instead of that because it does not require to construct an
        // API response object.
        if (false === $offset) {
            throw new RuntimeException(sprintf('CPS simulation error: "%s" does not exist.', $start_key));
        }
        // The default pagination limit (aka. "count") on CPS supported
        // listing endpoints varies. When this script was written it was
        // 1000 on two endpoints and 100 on two app related endpoints,
        // namely List Developer Apps and List Company Apps. A
        // developer/company should not have 100 apps, this is
        // the reason why this limit is smaller. Therefore we choose to
        // use 1000 as pagination limit if it has not been set.
        // https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/apiproducts-0
        // https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/developers
        // https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/developers/%7Bdeveloper_email_or_id%7D/apps
        return array_slice($result, $offset, $pager->getLimit() ?: 1000, true);
    }
private function simulateCpsPagination ( PagerInterface $ pager , array $ result , array $ array_search_haystack = null ) : array { $ array_search_haystack = $ array_search_haystack ?? $ result ; // If start key is null let's set it to the first key in the // result just like the API would do. $ start_key = $ pager -> getStartKey ( ) ?? reset ( $ array_search_haystack ) ; $ offset = array_search ( $ start_key , $ array_search_haystack ) ; // Start key has not been found in the response. Apigee Edge with // CPS enabled would return an HTTP 404, with error code // "keymanagement.service.[ENTITY_TYPE]_doesnot_exist" which would // trigger a ClientErrorException. We throw a RuntimeException // instead of that because it does not require to construct an // API response object. if ( false === $ offset ) { throw new RuntimeException ( sprintf ( 'CPS simulation error: "%s" does not exist.' , $ start_key ) ) ; } // The default pagination limit (aka. "count") on CPS supported // listing endpoints varies. When this script was written it was // 1000 on two endpoints and 100 on two app related endpoints, // namely List Developer Apps and List Company Apps. A // developer/company should not have 100 apps, this is // the reason why this limit is smaller. Therefore we choose to // use 1000 as pagination limit if it has not been set. // https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/apiproducts-0 // https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/developers // https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/developers/%7Bdeveloper_email_or_id%7D/apps return array_slice ( $ result , $ offset , $ pager -> getLimit ( ) ? : 1000 , true ) ; }
Simulates paginated response on an organization without CPS.

@param \Apigee\Edge\Structure\PagerInterface $pager
Pager.
@param array $result
The non-paginated result returned by the API.
@param array|null $array_search_haystack
Haystack for array_search, the needle is the start key from the pager.
If it is null, then the haystack is the $result.

@return array
The paginated result.
Simulates paginated response on an organization without CPS .