本文整理汇总了PHP中Nette\Application\Request::isMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::isMethod方法的具体用法?PHP Request::isMethod怎么用?PHP Request::isMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Application\Request
的用法示例。
在下文中一共展示了Request::isMethod方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @return Nette\Application\IResponse
*/
public function run(Application\Request $request)
{
$this->request = $request;
$httpRequest = $this->context->getByType('Nette\\Http\\IRequest');
if (!$httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $httpRequest->getUrl();
$url = $this->context->getService('router')->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
if ($url !== NULL && !$httpRequest->getUrl()->isEqual($url)) {
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
}
$params = $request->getParameters();
if (!isset($params['callback'])) {
throw new Application\BadRequestException("Parameter callback is missing.");
}
$params['presenter'] = $this;
$callback = new Nette\Callback($params['callback']);
$response = $callback->invokeArgs(Application\UI\PresenterComponentReflection::combineArgs($callback->toReflection(), $params));
if (is_string($response)) {
$response = array($response, array());
}
if (is_array($response)) {
if ($response[0] instanceof \SplFileInfo) {
$response = $this->createTemplate('Nette\\Templating\\FileTemplate')->setParameters($response[1])->setFile($response[0]);
} else {
$response = $this->createTemplate('Nette\\Templating\\Template')->setParameters($response[1])->setSource($response[0]);
}
}
if ($response instanceof Nette\Templating\ITemplate) {
return new Responses\TextResponse($response);
} else {
return $response;
}
}
示例2: run
/**
* @param Nette\Application\Request
* @return Nette\Application\IResponse
*/
public function run(Application\Request $request)
{
$this->request = $request;
$httpRequest = $this->context->httpRequest;
if (!$httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $httpRequest->getUrl();
$url = $this->context->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
if ($url !== NULL && !$httpRequest->getUrl()->isEqual($url)) {
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
}
$params = $request->getParams();
if (!isset($params['callback'])) {
return;
}
$params['presenter'] = $this;
$response = callback($params['callback'])->invokeNamedArgs($params);
if (is_string($response)) {
$response = array($response, array());
}
if (is_array($response)) {
if ($response instanceof \SplFileInfo) {
$response = $this->createTemplate('Nette\\Templating\\FileTemplate')->setParams($response[1])->setFile($response[0]);
} else {
$response = $this->createTemplate('Nette\\Templating\\Template')->setParams($response[1])->setSource($response[0]);
}
}
if ($response instanceof Nette\Templating\ITemplate) {
return new Responses\TextResponse($response);
} else {
return $response;
}
}
示例3: run
/**
* @return Nette\Application\IResponse
*/
public function run(Application\Request $request)
{
$this->request = $request;
if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $this->httpRequest->getUrl();
$url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
if ($url !== NULL && !$this->httpRequest->getUrl()->isEqual($url)) {
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
}
$params = $request->getParameters();
if (!isset($params['callback'])) {
throw new Application\BadRequestException('Parameter callback is missing.');
}
$params['presenter'] = $this;
$callback = $params['callback'];
$reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback));
$params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params);
if ($this->context) {
foreach ($reflection->getParameters() as $param) {
if ($param->getClassName()) {
unset($params[$param->getPosition()]);
}
}
$params = Nette\DI\Helpers::autowireArguments($reflection, $params, $this->context);
$params['presenter'] = $this;
}
$response = call_user_func_array($callback, $params);
if (is_string($response)) {
$response = array($response, array());
}
if (is_array($response)) {
list($templateSource, $templateParams) = $response;
$response = $this->createTemplate()->setParameters($templateParams);
if (!$templateSource instanceof \SplFileInfo) {
$response->getLatte()->setLoader(new Latte\Loaders\StringLoader);
}
$response->setFile($templateSource);
}
if ($response instanceof Application\UI\ITemplate) {
return new Responses\TextResponse($response);
} else {
return $response;
}
}
示例4: canonicalize
/**
* Conditional redirect to canonicalized URI.
* @return void
* @throws Nette\Application\AbortException
*/
public function canonicalize()
{
if (!$this->isAjax() && ($this->request->isMethod('get') || $this->request->isMethod('head'))) {
$url = $this->createRequest($this, $this->action, $this->getGlobalState() + $this->request->params, 'redirectX');
if ($url !== NULL && !$this->getHttpRequest()->getUrl()->isEqual($url)) {
$this->sendResponse(new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY));
}
}
}
示例5: run
/**
* @param \Nette\Application\Request $request
* @return \Nette\Application\IResponse
* @throws \Nette\Application\BadRequestException
*/
public function run(Application\Request $request)
{
$this->request = $request;
if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $this->httpRequest->getUrl();
$url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
if ($url !== NULL && !$this->httpRequest->getUrl()->isEqual($url)) {
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
}
$params = $request->getParameters();
if (!isset($params['id'])) {
throw new Application\BadRequestException('Parameter id is missing.');
}
if (NULL === ($item = $this->context->getService('webloader.cache')->getItem(\Nette\Utils\Strings::webalize($params['id'])))) {
return new Responses\TextResponse('');
}
return new \Lohini\WebLoader\WebLoaderResponse($item[WebLoader::CONTENT], $item[WebLoader::CONTENT_TYPE], $item[WebLoader::ETAG]);
}
示例6: canonicalize
/**
* Conditional redirect to canonicalized URI.
* @return void
* @throws Nette\Application\AbortException
*/
public function canonicalize()
{
if (!$this->isAjax() && ($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));
}
}
}
示例7: run
/**
* @param Application\Request $request
*
* @return Application\IResponse
*
* @throws Application\BadRequestException
*/
public function run(Application\Request $request)
{
$this->request = $request;
if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $this->httpRequest->getUrl();
$url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
if ($url !== NULL && !$this->httpRequest->getUrl()->isEqual($url)) {
return new Application\Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
}
$params = $request->getParameters();
if (!isset($params['action'])) {
throw new Application\BadRequestException('Parameter action is missing.');
}
if (!isset($params['id'])) {
throw new Application\BadRequestException('Parameter id is missing.');
}
// calls $this->action<Action>()
if (!($response = $this->tryCall(Application\UI\Presenter::formatActionMethod(Utils\Strings::capitalize($params['action'])), $params))) {
throw new Application\BadRequestException('Action not callable.');
}
return $response;
}
示例8: run
public function run(Request $request)
{
$this->request = $request;
try {
$this->startup();
$this->response = NULL;
if ($this->checkSsl) {
$this->checkSsl();
}
$this->checkApiVersion();
$name = $this->request->presenterName;
$action = isset($this->request->parameters['action']) ? $this->request->parameters['action'] : 'default';
// kontrola dat
if ($request->isMethod('post') || $request->isMethod('put') || $request->isMethod('patch')) {
$this->getRawPostData();
$this->prepareData($name, $action);
}
// kontrola přístupu
if ($this->checkAccess) {
$this->checkAccess($action);
}
$this->despatch($request, $action);
if (!$this->response) {
$this->response = new ApiResponse($this->payload, ApiResponse::S200_OK);
}
} catch (Nette\Application\AbortException $e) {
// pass
} catch (\Exception $e) {
Nette\Diagnostics\Debugger::log($e);
$this->response = NULL;
}
if (!$this->response) {
$this->response = new ApiResponse(array(), ApiResponse::S500_INTERNAL_SERVER_ERROR);
}
if (isset($this->logger)) {
$this->logRequest($request);
}
return $this->response;
}
示例9: run
/**
* @param Request $request
*/
public function run(Request $request)
{
if ($request->isMethod('get') && isset($request->getParameters()[RequestStorage::REQUEST_KEY])) {
$stored = $this->requestStorage->loadRequest($request->getParameters()[RequestStorage::REQUEST_KEY]);
/** @var Request $stored */
if ($stored && $stored->getPresenterName() === $request->getPresenterName()) {
$stored->setFlag(Request::RESTORED, true);
$parameters = $stored->getParameters();
if (isset($request->getParameters()[Presenter::FLASH_KEY])) {
$parameters[Presenter::FLASH_KEY] = $request->getParameters()[Presenter::FLASH_KEY];
} else {
unset($parameters[Presenter::FLASH_KEY]);
}
$stored->setParameters($parameters);
$request = $stored;
}
}
return parent::run($request);
}