本文整理汇总了PHP中Bluz\Proxy\Request::getAccept方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getAccept方法的具体用法?PHP Request::getAccept怎么用?PHP Request::getAccept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bluz\Proxy\Request
的用法示例。
在下文中一共展示了Request::getAccept方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
break;
case 501:
$title = __("Not Implemented");
$description = __("The server does not understand or does not support the HTTP method");
break;
case 503:
$title = __("Service Unavailable");
$description = __("The server is currently unable to handle the request due to a temporary overloading");
Response::setHeader('Retry-After', '600');
break;
default:
$title = __("Internal Server Error");
$description = __("An unexpected error occurred with your request. Please try again later");
break;
}
// check CLI or HTTP request
if (Request::isHttp()) {
// simple AJAX call, accept JSON
if (Request::getAccept(['application/json'])) {
$this->useJson();
Messages::addError($description);
return null;
}
// dialog AJAX call, accept HTML
if (!Request::isXmlHttpRequest()) {
$this->useLayout('small.phtml');
}
}
Layout::title($title);
return ['error' => $title, 'description' => $description];
};
示例2:
$description = __("The server does not understand or does not support the HTTP method");
break;
case 503:
$title = __("Service Unavailable");
$description = __("The server is currently unable to handle the request due to a temporary overloading");
Response::setHeader('Retry-After', '600');
break;
default:
$title = __("Internal Server Error");
$description = __("An unexpected error occurred with your request. Please try again later");
break;
}
// check CLI or HTTP request
if (Request::isHttp()) {
// simple AJAX call, accept JSON
if (Request::getAccept() == Request::ACCEPT_JSON) {
$this->useJson();
Messages::addError($message);
return $view;
}
// dialog AJAX call, accept HTML
if (!Request::isXmlHttpRequest()) {
$this->useLayout('small.phtml');
}
}
Layout::title($title);
$view->error = $title;
$view->description = $description;
if (getenv('BLUZ_DEBUG') && $message != '') {
$view->message = $message;
}
示例3: checkAccept
/**
* Check `Accept`
*
* @throws NotAcceptableException
*/
public function checkAccept()
{
// all ok for CLI
if (PHP_SAPI == 'cli') {
return;
}
$allowAccept = $this->getReflection()->getAccept();
// some controllers hasn't @accept tag
if (!$allowAccept) {
// but by default allow just HTML output
$allowAccept = [Request::TYPE_HTML, Request::TYPE_ANY];
}
// get Accept with high priority
$accept = Request::getAccept($allowAccept);
// some controllers allow any type (*/*)
// and client doesn't send Accept header
if (in_array(Request::TYPE_ANY, $allowAccept) && !$accept) {
// all OK, controller should realize logic for response
return;
}
// some controllers allow just selected types
// choose MIME type by browser accept header
// filtered by controller @accept
// switch statement for this logic
switch ($accept) {
case Request::TYPE_ANY:
case Request::TYPE_HTML:
// HTML response with layout
break;
case Request::TYPE_JSON:
// JSON response
$this->template = null;
break;
default:
throw new NotAcceptableException();
}
}
示例4: preProcess
/**
* Pre process
*
* @return void
* @throws ApplicationException
*/
protected function preProcess()
{
Router::process();
// disable Layout for XmlHttpRequests
if (Request::isXmlHttpRequest()) {
$this->layoutFlag = false;
}
// switch to JSON response based on Accept header
if (Request::getAccept([Request::TYPE_HTML, Request::TYPE_JSON]) == Request::TYPE_JSON) {
$this->layoutFlag = false;
Response::switchType('JSON');
}
}
示例5: forbidden
/**
* Denied access
* @param ForbiddenException $exception
* @return \Bluz\Controller\Controller|null
*/
public function forbidden(ForbiddenException $exception)
{
if (AuthProxy::getIdentity()) {
$message = Translator::translate("You don't have permissions to access this page");
} else {
$message = Translator::translate("You don't have permissions, please sign in");
}
// for AJAX and API calls (over JSON)
$jsonOrApi = Request::isXmlHttpRequest() || Request::getAccept([Request::TYPE_HTML, Request::TYPE_JSON]) == Request::TYPE_JSON;
// for guest, for requests
if (!AuthProxy::getIdentity() && !$jsonOrApi) {
// save URL to session and redirect make sense if presentation is null
Session::set('rollback', Request::getUri()->__toString());
// add error notice
Messages::addError($message);
// redirect to Sign In page
$url = Router::getUrl('users', 'signin');
return $this->redirect($url);
} else {
return $this->error(new ForbiddenException($message, 403, $exception));
}
}