protected function _populate(ResponseInterface $response, $asCollection = true) {
		$models = [];
		$statusCode = $response->getStatusCode();
		$data = $this->_unserializeResponseBody($response);

		// errors
		if($statusCode >= 400) {

			throw new HttpException(
				$statusCode,
				is_string($data) ? $data : $data->message,
				$statusCode
			);
		}

		// array of objects or arrays - probably resource collection
		if(is_array($data)) {
			$models = $this->_createModels($data);
		}
		// collection with data envelope or single element
		if(is_object($data)) {
			if($asCollection) {
				if($this->_collectionEnvelope) {
					$elements = isset($data->{$this->_collectionEnvelope})
						? $data->{$this->_collectionEnvelope}
						: [];
				} else {
					$elements = [];
				}
				if($this->_paginationEnvelope && isset($data->{$this->_paginationEnvelope})) {
					$this->_setPagination(
						$this->_getProps($data->{$this->_paginationEnvelope})
					);
				}
				$models = $this->_createModels($elements);
			} else {
				$models = $this->_createModels([$data])[0];
			}
		}

		return $models;
	}
protected function _populate(ResponseInterface $response, $asCollection = true) {
		$models = [];
		$statusCode = $response->getStatusCode();
		$data = $this->_unserializeResponseBody($response);

		// errors
		if($statusCode >= 400) {

			throw new HttpException(
				$statusCode,
				is_string($data) ? $data : $data->message,
				$statusCode
			);
		}

		// array of objects or arrays - probably resource collection
		if(is_array($data)) {
			$models = $this->_createModels($data);
		}
		// collection with data envelope or single element
		if(is_object($data)) {
			if($asCollection) {
				if($this->_collectionEnvelope) {
					$elements = isset($data->{$this->_collectionEnvelope})
						? $data->{$this->_collectionEnvelope}
						: [];
				} else {
					$elements = [];
				}
				if($this->_paginationEnvelope && isset($data->{$this->_paginationEnvelope})) {
					$this->_setPagination(
						$this->_getProps($data->{$this->_paginationEnvelope})
					);
				}
				$models = $this->_createModels($elements);
			} else {
				$models = $this->_createModels([$data])[0];
			}
		}

		return $models;
	}
protected function _populate ( ResponseInterface $ response , $ asCollection = true ) { $ models = [ ] ; $ statusCode = $ response -> getStatusCode ( ) ; $ data = $ this -> _unserializeResponseBody ( $ response ) ; // errors if ( $ statusCode >= 400 ) { throw new HttpException ( $ statusCode , is_string ( $ data ) ? $ data : $ data -> message , $ statusCode ) ; } // array of objects or arrays - probably resource collection if ( is_array ( $ data ) ) { $ models = $ this -> _createModels ( $ data ) ; } // collection with data envelope or single element if ( is_object ( $ data ) ) { if ( $ asCollection ) { if ( $ this -> _collectionEnvelope ) { $ elements = isset ( $ data -> { $ this -> _collectionEnvelope } ) ? $ data -> { $ this -> _collectionEnvelope } : [ ] ; } else { $ elements = [ ] ; } if ( $ this -> _paginationEnvelope && isset ( $ data -> { $ this -> _paginationEnvelope } ) ) { $ this -> _setPagination ( $ this -> _getProps ( $ data -> { $ this -> _paginationEnvelope } ) ) ; } $ models = $ this -> _createModels ( $ elements ) ; } else { $ models = $ this -> _createModels ( [ $ data ] ) [ 0 ] ; } } return $ models ; }
Unserialize and create models
@param ResponseInterface $response
@param bool $asCollection
@return $this|Model|array|void
@throws HttpException
Unserialize and create models