Api/Response.php
public static function create($body)
    {
        if (0 !== strpos($body, static::START_TOKEN)) {
            throw new InvalidArgumentException("Unexpected response body.");
        }
        if (static::END_TOKEN !== substr($body, -strlen(static::END_TOKEN))) {
            throw new InvalidArgumentException("Unexpected response body.");
        }

        $body = substr($body, strlen(static::START_TOKEN), -strlen(static::END_TOKEN));

        $parts = explode('|', trim($body, '|'));
        if (empty($parts)) {
            throw new InvalidArgumentException("Unexpected response body.");
        }

        $response = new static();

        for ($i = 0; $i < count($parts); $i++) {
            list($key, $value) = explode(':', $parts[$i], 2);

            if ($key === Config::RESULT) {
                if (0 < strpos($value, ':')) {
                    list($code, $field) = explode(':', $value, 2);
                } else {
                    $code = $value;
                    $field = 'unknown';
                }
                $response->set(Config::RESULT, $code);
                $response->set(Config::FIELD, $field);
            } else {
                $response->set($key, $value);
            }
        }

        return $response;
    }
public static function create($body)
    {
        if (0 !== strpos($body, static::START_TOKEN)) {
            throw new InvalidArgumentException("Unexpected response body.");
        }
        if (static::END_TOKEN !== substr($body, -strlen(static::END_TOKEN))) {
            throw new InvalidArgumentException("Unexpected response body.");
        }

        $body = substr($body, strlen(static::START_TOKEN), -strlen(static::END_TOKEN));

        $parts = explode('|', trim($body, '|'));
        if (empty($parts)) {
            throw new InvalidArgumentException("Unexpected response body.");
        }

        $response = new static();

        for ($i = 0; $i < count($parts); $i++) {
            list($key, $value) = explode(':', $parts[$i], 2);

            if ($key === Config::RESULT) {
                if (0 < strpos($value, ':')) {
                    list($code, $field) = explode(':', $value, 2);
                } else {
                    $code = $value;
                    $field = 'unknown';
                }
                $response->set(Config::RESULT, $code);
                $response->set(Config::FIELD, $field);
            } else {
                $response->set($key, $value);
            }
        }

        return $response;
    }
public static function create ( $ body ) { if ( 0 !== strpos ( $ body , static :: START_TOKEN ) ) { throw new InvalidArgumentException ( "Unexpected response body." ) ; } if ( static :: END_TOKEN !== substr ( $ body , - strlen ( static :: END_TOKEN ) ) ) { throw new InvalidArgumentException ( "Unexpected response body." ) ; } $ body = substr ( $ body , strlen ( static :: START_TOKEN ) , - strlen ( static :: END_TOKEN ) ) ; $ parts = explode ( '|' , trim ( $ body , '|' ) ) ; if ( empty ( $ parts ) ) { throw new InvalidArgumentException ( "Unexpected response body." ) ; } $ response = new static ( ) ; for ( $ i = 0 ; $ i < count ( $ parts ) ; $ i ++ ) { list ( $ key , $ value ) = explode ( ':' , $ parts [ $ i ] , 2 ) ; if ( $ key === Config :: RESULT ) { if ( 0 < strpos ( $ value , ':' ) ) { list ( $ code , $ field ) = explode ( ':' , $ value , 2 ) ; } else { $ code = $ value ; $ field = 'unknown' ; } $ response -> set ( Config :: RESULT , $ code ) ; $ response -> set ( Config :: FIELD , $ field ) ; } else { $ response -> set ( $ key , $ value ) ; } } return $ response ; }
Creates a response from the given http response body.

@param string $body

@return Response
Creates a response from the given http response body .