本文整理汇总了PHP中Helpers::jsonEncode方法的典型用法代码示例。如果您正苦于以下问题:PHP Helpers::jsonEncode方法的具体用法?PHP Helpers::jsonEncode怎么用?PHP Helpers::jsonEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Helpers
的用法示例。
在下文中一共展示了Helpers::jsonEncode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createRequest
/**
* @param string Http\Request::GET|POST|...
* @param string path like '/users/:user/repos' where ':user' is substitution
* @param array[name => value] replaces substitutions in $urlPath, the rest is appended as query string to URL
* @param array[name => value] name is case-insensitive
* @param mixed|NULL arrays and objects are encoded to JSON and Content-Type is set
* @return Http\Request
*
* @throws MissingParameterException when substitution is used in URL but parameter is missing
* @throws JsonException when encoding to JSON fails
*/
public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL)
{
$parameters += $this->defaultParameters;
$this->substituteUrlParameters($urlPath, $parameters);
$url = rtrim($this->url, '/') . '/' . trim($urlPath, '/');
if (count($parameters)) {
$url .= '?' . http_build_query($parameters);
}
if ($content !== NULL && (is_array($content) || is_object($content))) {
$headers['Content-Type'] = 'application/json; charset=utf-8';
$content = Helpers::jsonEncode($content);
}
return new Http\Request($method, $url, $headers, $content);
}
示例2: createRequest
/**
* @param string Http\Request::GET|POST|...
* @param string path like '/users/:user/repos' where ':user' is substitution
* @param array[name => value] replaces substitutions in $urlPath, the rest is appended as query string to URL
* @param array[name => value] name is case-insensitive
* @param mixed|NULL arrays and objects are encoded to JSON and Content-Type is set
* @return Http\Request
*
* @throws MissingParameterException when substitution is used in URL but parameter is missing
* @throws JsonException when encoding to JSON fails
*/
public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL)
{
if (stripos($urlPath, $this->url) === 0) {
$urlPath = substr($urlPath, strlen($this->url));
}
if (strpos($urlPath, '{') === FALSE) {
$urlPath = $this->expandColonParameters($urlPath, $parameters, $this->defaultParameters);
} else {
$urlPath = $this->expandUriTemplate($urlPath, $parameters, $this->defaultParameters);
}
$url = rtrim($this->url, '/') . '/' . ltrim($urlPath, '/');
if ($content !== NULL && (is_array($content) || is_object($content))) {
$headers['Content-Type'] = 'application/json; charset=utf-8';
$content = Helpers::jsonEncode($content);
}
return new Http\Request($method, $url, $headers, $content);
}
示例3: processRequestOutput_json
protected function processRequestOutput_json(array $_)
{
return Helpers::jsonEncode($_["result"], 500);
}
示例4: createRequest
/**
* @param string Http\Request::GET|POST|...
* @param string path like '/users/:user/repos' where ':user' is substitution
* @param array[name => value] replaces substitutions in $urlPath, the rest is appended as query string to URL
* @param array[name => value] name is case-insensitive
* @param mixed|NULL arrays and objects are encoded to JSON and Content-Type is set
* @return Http\Request
*
* @throws MissingParameterException when substitution is used in URL but parameter is missing
* @throws JsonException when encoding to JSON fails
*/
public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL)
{
if (stripos($urlPath, $this->url) === 0) {
# Allows non-HTTPS URLs
$baseUrl = $this->url;
$urlPath = substr($urlPath, strlen($this->url));
} elseif (preg_match('#^(https://[^/]+)(/.*)?$#', $urlPath, $m)) {
$baseUrl = $m[1];
$urlPath = isset($m[2]) ? $m[2] : '';
} else {
$baseUrl = $this->url;
}
if (strpos($urlPath, '{') === FALSE) {
$urlPath = $this->expandColonParameters($urlPath, $parameters, $this->defaultParameters);
} else {
$urlPath = $this->expandUriTemplate($urlPath, $parameters, $this->defaultParameters);
}
$url = rtrim($baseUrl, '/') . '/' . ltrim($urlPath, '/');
if ($content !== NULL && (is_array($content) || is_object($content))) {
$headers['Content-Type'] = 'application/json; charset=utf-8';
$content = Helpers::jsonEncode($content);
}
return new Http\Request($method, $url, $headers, $content);
}
示例5: sendRequest_encodeData_json
public function sendRequest_encodeData_json(array $_)
{
return Helpers::jsonEncode($_);
}