Exemplo n.º 1
0
 /**
  * @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;
     }
 }
Exemplo n.º 2
0
 /**
  * @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;
     }
 }
Exemplo n.º 3
0
	/**
	 * @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;
		}
	}
Exemplo n.º 4
0
 /**
  * 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));
         }
     }
 }
Exemplo n.º 5
0
 /**
  * @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]);
 }
Exemplo n.º 6
0
 /**
  * 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));
         }
     }
 }
Exemplo n.º 7
0
 /**
  * @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;
 }
Exemplo n.º 8
0
 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;
 }
 /**
  * @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);
 }