AlgoliaSearch\Index::buildBatch PHP Method

buildBatch() private method

Build a batch request.
private buildBatch ( string $action, array $objects, string $withObjectID, string $objectIDKey = 'objectID' ) : array
$action string the batch action
$objects array the array of objects
$withObjectID string set an 'objectID' attribute
$objectIDKey string the objectIDKey
return array
    private function buildBatch($action, $objects, $withObjectID, $objectIDKey = 'objectID')
    {
        $requests = array();
        foreach ($objects as $obj) {
            $req = array('action' => $action, 'body' => $obj);
            if ($withObjectID && array_key_exists($objectIDKey, $obj)) {
                $req['objectID'] = (string) $obj[$objectIDKey];
            }
            array_push($requests, $req);
        }
        return array('requests' => $requests);
    }