src/API.php
public function batchRequest(array $requests) {
        $data = [];

        foreach ($requests as $request) {
            if (!array_key_exists('method', $request)) {
                throw new BadMethodCallException(
                    'Missing method in one of the sub-requests of this batch request'
                );
            }

            $params = [];

            if (array_key_exists('params', $request)) {
                $params = $request['params'];
            }

            $params['apikey'] = $this->config[self::KEY];

            if (array_key_exists(self::LANGUAGE, $this->config)) {
                $params[self::LANGUAGE] = $this->config[self::LANGUAGE];
            }

            $data[] = [
                'version' => '2.0',
                'method' => $request['method'],
                'params' => $params,
                'id' => $this->genID()
            ];
        }

        $responses = $this->execute($data);

        $results = [];

        foreach ($responses as $response) {
            if (!is_array($response)) {
                throw new RuntimeException(sprintf(
                    'Found invalid result for request in batch: %s',
                    $response
                ));
            }

            $this->evaluateResponse($response);

            $results[] = $response['result'];
        }

        return $results;
    }
public function batchRequest(array $requests) {
        $data = [];

        foreach ($requests as $request) {
            if (!array_key_exists('method', $request)) {
                throw new BadMethodCallException(
                    'Missing method in one of the sub-requests of this batch request'
                );
            }

            $params = [];

            if (array_key_exists('params', $request)) {
                $params = $request['params'];
            }

            $params['apikey'] = $this->config[self::KEY];

            if (array_key_exists(self::LANGUAGE, $this->config)) {
                $params[self::LANGUAGE] = $this->config[self::LANGUAGE];
            }

            $data[] = [
                'version' => '2.0',
                'method' => $request['method'],
                'params' => $params,
                'id' => $this->genID()
            ];
        }

        $responses = $this->execute($data);

        $results = [];

        foreach ($responses as $response) {
            if (!is_array($response)) {
                throw new RuntimeException(sprintf(
                    'Found invalid result for request in batch: %s',
                    $response
                ));
            }

            $this->evaluateResponse($response);

            $results[] = $response['result'];
        }

        return $results;
    }
public function batchRequest ( array $ requests ) { $ data = [ ] ; foreach ( $ requests as $ request ) { if ( ! array_key_exists ( 'method' , $ request ) ) { throw new BadMethodCallException ( 'Missing method in one of the sub-requests of this batch request' ) ; } $ params = [ ] ; if ( array_key_exists ( 'params' , $ request ) ) { $ params = $ request [ 'params' ] ; } $ params [ 'apikey' ] = $ this -> config [ self :: KEY ] ; if ( array_key_exists ( self :: LANGUAGE , $ this -> config ) ) { $ params [ self :: LANGUAGE ] = $ this -> config [ self :: LANGUAGE ] ; } $ data [ ] = [ 'version' => '2.0' , 'method' => $ request [ 'method' ] , 'params' => $ params , 'id' => $ this -> genID ( ) ] ; } $ responses = $ this -> execute ( $ data ) ; $ results = [ ] ; foreach ( $ responses as $ response ) { if ( ! is_array ( $ response ) ) { throw new RuntimeException ( sprintf ( 'Found invalid result for request in batch: %s' , $ response ) ) ; } $ this -> evaluateResponse ( $ response ) ; $ results [ ] = $ response [ 'result' ] ; } return $ results ; }
Performs multiple requests to API at once

@param array $requests Batch requests with 'method' and optional 'params'

@return array Result of request

@throws Exception on error
Performs multiple requests to API at once