public function testEncodeJson() { $data = CommonUtils::encodeJson(array('first_key' => 'first_value', 'second-key' => 'second-value')); $this->assertContains('first_key', $data); $this->assertContains('first_value', $data); $this->assertContains('second-key', $data); $this->assertContains('second-value', $data); }
/** * {@inheritdoc } */ public function send() { if ($this->method == AbstractClient::METHOD_GET) { $this->getUrl()->setQueryVariables($this->_parameters); } else { if (in_array($this->method, array(AbstractClient::METHOD_POST, AbstractClient::METHOD_PUT))) { switch ($this->_dataType) { case AbstractClient::DATA_TYPE_JSON: $this->setHeader('Content-Type', 'application/json'); $params = CommonUtils::encodeJson($this->_parameters); break; default: $params[$name] = $this->_parameters; } if ($this->method == AbstractClient::METHOD_POST || $this->method == AbstractClient::METHOD_PUT || $this->method == AbstractClient::METHOD_PATCH) { if ($this->_dataType == AbstractClient::DATA_TYPE_JSON) { $this->setBody($params); } else { $this->addPostParameter($params); } } else { $this->setBody(new \HTTP_Request2_MultipartBody($params, array())); } } } $httpResponse = parent::send(); return new Response($httpResponse); }