本文整理汇总了PHP中Nette\Application\Request::hasFlag方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::hasFlag方法的具体用法?PHP Request::hasFlag怎么用?PHP Request::hasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Application\Request
的用法示例。
在下文中一共展示了Request::hasFlag方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canonicalize
/**
* Conditional redirect to canonicalized URI.
* @return void
* @throws Nette\Application\AbortException
*/
public function canonicalize()
{
if (!$this->isAjax() && !$this->request->hasFlag(Application\Request::RESTORED) && ($this->request->isMethod('get') || $this->request->isMethod('head'))) {
try {
$url = $this->createRequest($this, $this->action, $this->getGlobalState() + $this->request->getParameters(), 'redirectX');
} catch (InvalidLinkException $e) {
}
if (isset($url) && !$this->httpRequest->getUrl()->isEqual($url)) {
$this->sendResponse(new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY));
}
}
}
示例2: processSubmit
/**
* Submits the form.
*/
protected function processSubmit(FormInterface $form, Request $request)
{
// Restored request should only render the form, not immediately submit it.
if ($request->hasFlag(Request::RESTORED)) {
return;
}
$form->handleRequest($request);
if (!$form->isSubmitted()) {
throw new BadRequestException('The form was not submitted.');
}
$data = $form->getData();
if ($form->isValid()) {
$this->onSuccess($data, $this);
} else {
$this->onError($data, $this);
}
$this->onSubmit($data, $this);
}
示例3: checkSsl
/**
* Kontroluje SSL
*/
protected function checkSsl()
{
if (!$this->request->hasFlag(Request::SECURED)) {
$this->sendErrorResponse(ApiResponse::S403_FORBIDDEN, static::MESSAGE_SSL_IS_REQUIRED);
}
}
示例4: process
/**
* @return Nette\Application\IResponse
*/
protected function process(Nette\Application\Request $request)
{
// Query output content type -------------------------------------------
// Accept header is comma separated fallback sequence
// @todo sequence should be actually sorted by the degree of specificity
// @todo make support for version options (ie. application/json;version=2)
// see: RESTful Web Services Cookbook page 250
$cTypes = preg_split('/,/', $this->httpRequest->getHeader('Accept'), 0, PREG_SPLIT_NO_EMPTY);
foreach ($cTypes as $cType) {
// We ignore all the options
$cType = preg_replace('/;.*/', '', $cType);
if (strcasecmp($cType, 'text/html') === 0 || strcmp($cType, '*/*') === 0) {
$this->outputContentType = 'text/html';
$this->httpResponse->setContentType('text/html', 'utf-8');
break;
} elseif (strcasecmp($cType, 'application/json') === 0) {
$this->outputContentType = 'application/json';
$this->httpResponse->setContentType('application/json', 'utf-8');
break;
}
}
if ($this->outputContentType === NULL) {
$this->terminateWithError(self::ERROR_INVALID_REQUEST, "Accept header is missing or not satisfiable.", 406);
}
// Process Content-Language header -------------------------------------
// Process Authorization header ----------------------------------------
if (($authHeader = $this->httpRequest->getHeader('Authorization')) !== NULL) {
if (preg_match('/^Bearer\\s([^\\s,;]+)/i', $authHeader, $matches)) {
$tokenHash = $matches[1];
// If connection is not secured return error and invalidate sent token
// just in case
if (!$request->hasFlag(Nette\Application\Request::SECURED) && $this->isInProductionMode()) {
$this->tokenManager->invalidateToken($tokenHash);
$this->terminateWithError(self::ERROR_INVALID_REQUEST, "Secured connection required", 400);
}
if (!$this->attemptLogger->getRemainingAttempts(self::ATTEMPT_IP_TOKEN, $this->httpRequest->getRemoteAddress())) {
$this->terminateWithError(OAuth2ResourceProvider::ERROR_MAXIMUM_ATTEMPTS_EXCEEDED, 'Maximum number of authorization attempts exceeded.', 403);
}
$token = $this->tokenManager->getToken($tokenHash);
if (!$token) {
$this->attemptLogger->logFail(self::ATTEMPT_IP_TOKEN, $this->httpRequest->getRemoteAddress());
$this->httpResponse->addHeader('WWW-Authenticate', 'Bearer realm="' . $this->link() . '"');
$this->terminateWithError(OAuth2ResourceProvider::ERROR_INVALID_GRANT, 'Given authorization token is not valid.', 401);
}
$this->attemptLogger->logSuccess(self::ATTEMPT_IP_TOKEN, $this->httpRequest->getRemoteAddress());
if (isset($token->parameters->userIdentity)) {
$this->user->login(User::AUTHN_METHOD_INVALID, User::AUTHN_SOURCE_ALL, $token->parameters->userIdentity);
}
if (isset($token->parameters->client)) {
$this->client = $token->parameters->client;
}
}
}
// Find request handler ------------------------------------------------
// Gather resource path
$parameters = $request->getParameters();
$resourcePath = isset($parameters[self::PARAM_KEY_PATH]) ? trim($parameters[self::PARAM_KEY_PATH]) : NULL;
if (!$resourcePath) {
$this->terminateWithError(self::ERROR_INVALID_REQUEST, "No resource path given.", 400);
}
// Request router expects leading slash
if ($resourcePath[0] != '/') {
$resourcePath = "/{$resourcePath}";
}
// Request router: find resource handler
try {
/** @var vBuilder\RestApi\Request */
$this->resourceRequest = $handlerRequest = $this->requestRouter->createRequest($this->httpRequest->getMethod(), $resourcePath);
} catch (RequestException $e) {
$this->terminateWithError(self::ERROR_INVALID_REQUEST, $e->getMessage(), $e->getCode() == RequestException::METHOD_NOT_ALLOWED ? 405 : 404);
}
// Request authorization -----------------------------------------------
$handlerMethodAnnotations = $handlerRequest->getMethodReflection()->getAnnotations();
if (!isset($handlerMethodAnnotations['NoAuthorization']) || !$handlerMethodAnnotations['NoAuthorization'][0]) {
if (!$this->client) {
$this->httpResponse->addHeader('WWW-Authenticate', 'Bearer realm="' . $this->link() . '"');
$this->terminateWithError(self::ERROR_UNAUTHORIZED, 'Requested resource requires authorization. Please add Authorization header with correct security token.', 401);
}
}
// Decode POST data ----------------------------------------------------
if ($this->httpRequest->isPost()) {
$cType = $this->httpRequest->getHeader('Content-Type');
if (strcasecmp($cType, 'application/json') === 0) {
try {
$this->postData = Nette\Utils\Json::decode(file_get_contents('php://input'), Nette\Utils\Json::FORCE_ARRAY);
} catch (Nette\Utils\JsonException $e) {
$this->terminateWithError(self::ERROR_INVALID_REQUEST, "Malformed POST data (JSON expected).", 400);
}
} elseif (strcasecmp($cType, 'application/x-www-form-urlencoded') === 0) {
$this->postData = $this->httpRequest->getPost();
} elseif ($cType === NULL) {
$this->terminateWithError(self::ERROR_INVALID_REQUEST, "Missing Content-Type header, which is mandatory for POST requests.", 400);
} else {
$this->terminateWithError(self::ERROR_INVALID_REQUEST, "Request content type of POST data is not supported.", 415);
}
}
// Create resource instance and prepare all dependencies ---------------
//.........这里部分代码省略.........