本文整理汇总了PHP中Json::getErrorCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Json::getErrorCode方法的具体用法?PHP Json::getErrorCode怎么用?PHP Json::getErrorCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Json
的用法示例。
在下文中一共展示了Json::getErrorCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setBody
/**
* Set body.
*
* @param mixed $body
* @return self
*/
public final function setBody($body) : self
{
switch ($this->contentType) {
// handle xml @todo
case ContentType::XML:
break;
// handle json
// handle json
case ContentType::JSON:
$json = new Json($body);
// simply check for pretty print
$app = app();
if (is_in($app->request->params->get['pp'], ['1', 'true'])) {
$body = $json->encode(JSON_PRETTY_PRINT);
} else {
$body = $json->encode();
}
if ($json->hasError()) {
throw new JsonException($json->getErrorMessage(), $json->getErrorCode());
}
break;
// handle html
// handle html
case ContentType::HTML:
// check for page title
if ($pageTitle = get_global('page.title')) {
$body = preg_replace('~<title>(.*?)</title>~s', '<title>' . html_encode($pageTitle) . '</title>', $body, 1);
}
// check page description
if ($pageDescription = get_global('page.description')) {
$body = preg_replace('~<meta\\s+name="description"\\s+content="(.*?)">~', '<meta\\s+name="description"\\s+content="' . html_encode($pageDescription) . '">', $body, 1);
}
break;
}
// can gzip?
if (!empty($this->gzipOptions)) {
$this->gzip->setData($body);
if ($this->gzip->isDataMinlenOK()) {
$body = $this->gzip->encode();
$this->setHeader('Vary', 'Accept-Encoding');
$this->setHeader('Content-Encoding', 'gzip');
}
}
// content length
$this->setContentLength(strlen($body));
$this->body = $body;
return $this;
}
示例2: setBody
/**
* Set body.
* @param any $body
* @return self
*/
public final function setBody($body) : self
{
switch ($this->body->content->getType()) {
case BodyContent::TYPE_XML:
// @todo
break;
case BodyContent::TYPE_JSON:
$json = new Json($body);
$body = $json->encode();
if ($json->hasError()) {
throw new JsonException($json->getErrorMessage(), $json->getErrorCode());
}
break;
}
// gzip
if (!empty($this->gzipOptions)) {
$this->gzip->setData($body);
if ($this->gzip->checkDataMinlen()) {
$body = $this->gzip->encode();
$this->setHeader('Vary', 'Accept-Encoding');
$this->setHeader('Content-Encoding', 'gzip');
}
}
$this->body->content->setData($body);
$this->body->content->setLength(strlen($body));
return $this;
}