protected function decodeNewLineEncodedResponse($responseString, $requestQuery, array $forceArray = array())
    {
        // Splitting response body
        $parts = explode(chr(10), $responseString);

        // Getting the status
        $status = trim($parts[0]);

        $responseArray = [];

        // Valid answer?
        if (is_numeric($status)) {
            // Successful?
            if ($status != '0') {
                $responseArray['errorCode']    = $status;
                $responseArray['errorMessage'] = trim($parts[1]);
            } else {
                $responseArray['errorCode']    = $status;

                $partCount = count($parts);
                for ($i = 1; $i < $partCount; $i++) {
                    $tmp = preg_split('/[\s\t]+/', $parts[$i], 2);

                    $key   = trim($tmp[0]);
                    $value = trim($tmp[1]);

                    // if key already exists, open new array dimension
                    if (isset($responseArray[$key])) {
                        if (!is_array($responseArray[$key])) {
                            $tmpValue              = $responseArray[$key];
                            $responseArray[$key]   = array();
                            $responseArray[$key][] = $tmpValue;
                            $responseArray[$key][] = $value;
                        } else {
                            $responseArray[$key][] = $value;
                        }
                    } else {
                        // Just save
                        $responseArray[$key] = $value;
                    }
                }
            }
        } else {
            $responseArray['errorCode']    = '';
            $responseArray['errorMessage'] = trim($responseString);
        }

        foreach ($forceArray as $value) {
            if (isset($responseArray[$value]) && !is_array($responseArray[$value])) {
                $responseArray[$value] = array($responseArray[$value]);
            }
        }

        $responseArray['responseString'] = $responseString;
        $responseArray['requestQuery']   = $requestQuery;

        return $responseArray;
    }
protected function decodeNewLineEncodedResponse($responseString, $requestQuery, array $forceArray = array())
    {
        // Splitting response body
        $parts = explode(chr(10), $responseString);

        // Getting the status
        $status = trim($parts[0]);

        $responseArray = [];

        // Valid answer?
        if (is_numeric($status)) {
            // Successful?
            if ($status != '0') {
                $responseArray['errorCode']    = $status;
                $responseArray['errorMessage'] = trim($parts[1]);
            } else {
                $responseArray['errorCode']    = $status;

                $partCount = count($parts);
                for ($i = 1; $i < $partCount; $i++) {
                    $tmp = preg_split('/[\s\t]+/', $parts[$i], 2);

                    $key   = trim($tmp[0]);
                    $value = trim($tmp[1]);

                    // if key already exists, open new array dimension
                    if (isset($responseArray[$key])) {
                        if (!is_array($responseArray[$key])) {
                            $tmpValue              = $responseArray[$key];
                            $responseArray[$key]   = array();
                            $responseArray[$key][] = $tmpValue;
                            $responseArray[$key][] = $value;
                        } else {
                            $responseArray[$key][] = $value;
                        }
                    } else {
                        // Just save
                        $responseArray[$key] = $value;
                    }
                }
            }
        } else {
            $responseArray['errorCode']    = '';
            $responseArray['errorMessage'] = trim($responseString);
        }

        foreach ($forceArray as $value) {
            if (isset($responseArray[$value]) && !is_array($responseArray[$value])) {
                $responseArray[$value] = array($responseArray[$value]);
            }
        }

        $responseArray['responseString'] = $responseString;
        $responseArray['requestQuery']   = $requestQuery;

        return $responseArray;
    }
protected function decodeNewLineEncodedResponse ( $ responseString , $ requestQuery , array $ forceArray = array ( ) ) { // Splitting response body $ parts = explode ( chr ( 10 ) , $ responseString ) ; // Getting the status $ status = trim ( $ parts [ 0 ] ) ; $ responseArray = [ ] ; // Valid answer? if ( is_numeric ( $ status ) ) { // Successful? if ( $ status != '0' ) { $ responseArray [ 'errorCode' ] = $ status ; $ responseArray [ 'errorMessage' ] = trim ( $ parts [ 1 ] ) ; } else { $ responseArray [ 'errorCode' ] = $ status ; $ partCount = count ( $ parts ) ; for ( $ i = 1 ; $ i < $ partCount ; $ i ++ ) { $ tmp = preg_split ( '/[\s\t]+/' , $ parts [ $ i ] , 2 ) ; $ key = trim ( $ tmp [ 0 ] ) ; $ value = trim ( $ tmp [ 1 ] ) ; // if key already exists, open new array dimension if ( isset ( $ responseArray [ $ key ] ) ) { if ( ! is_array ( $ responseArray [ $ key ] ) ) { $ tmpValue = $ responseArray [ $ key ] ; $ responseArray [ $ key ] = array ( ) ; $ responseArray [ $ key ] [ ] = $ tmpValue ; $ responseArray [ $ key ] [ ] = $ value ; } else { $ responseArray [ $ key ] [ ] = $ value ; } } else { // Just save $ responseArray [ $ key ] = $ value ; } } } } else { $ responseArray [ 'errorCode' ] = '' ; $ responseArray [ 'errorMessage' ] = trim ( $ responseString ) ; } foreach ( $ forceArray as $ value ) { if ( isset ( $ responseArray [ $ value ] ) && ! is_array ( $ responseArray [ $ value ] ) ) { $ responseArray [ $ value ] = array ( $ responseArray [ $ value ] ) ; } } $ responseArray [ 'responseString' ] = $ responseString ; $ responseArray [ 'requestQuery' ] = $ requestQuery ; return $ responseArray ; }
Decodes a responseString, separated by new lines and returns an response array

@param string $responseString
@param string $requestQuery
@param array  $forceArray

@return array
Decodes a responseString separated by new lines and returns an response array