Exemple #1
0
 /**
  * @param Request $request
  * @return IResponse
  * @throws BadRequestException
  */
 public function run(Request $request)
 {
     $method = strtolower($request->getMethod());
     if (!method_exists($this, $method)) {
         throw new BadRequestException("Method '{$request->getMethod()}' not supported.");
     }
     $response = $this->{$method}($request);
     if (!$response instanceof IResponse) {
         throw new InvalidStateException("Presenter '{$request->getPresenterName()}' did not return any response for method '{$request->getMethod()}'.");
     }
     return $response;
 }
Exemple #2
0
 /**
  * @return string
  */
 public function getAction($fullyQualified = false)
 {
     if ($this->action === null) {
         $method = $this->request->getMethod();
         $this->action = isset(self::$actionMap[$method]) ? self::$actionMap[$method] : strtolower($method);
     }
     return $fullyQualified ? "{$this->request->getPresenterName()}:{$this->action}" : $this->action;
 }
 /**
  * @param Application $sender
  * @param Request $request
  */
 public function onRequest(Application $sender, Request $request)
 {
     $params = $request->getParameters();
     if ($request->getMethod() === Request::FORWARD && empty($params['locale'])) {
         return;
     }
     $this->request = $request;
     if (!$this->translator) {
         return;
     }
     $this->translator->setLocale(NULL);
     $this->translator->getLocale();
     // invoke resolver
 }
 /**
  * @param FormInterface $form
  * @param Request       $request
  */
 public function handleRequest(FormInterface $form, $request = null)
 {
     if (!$request instanceof Request) {
         throw new UnexpectedTypeException($request, 'Nette\\Application\\Request');
     }
     $name = $form->getName();
     if ($name === '') {
         throw new InvalidArgumentException('Forms are not allowed to have an emtpy string as name.');
     }
     $method = $form->getConfig()->getMethod();
     if ($method !== $request->getMethod()) {
         return;
     }
     if ($method === 'GET') {
         $get = $request->getParameters();
         // Don't submit GET requests if the form's name does not exist in the request.
         if (!isset($get[$name])) {
             return;
         }
         $data = $get[$name];
     } else {
         $post = $request->getPost();
         $files = $request->getFiles();
         $default = $form->getConfig()->getCompound() ? [] : null;
         $postData = isset($post[$name]) ? $post[$name] : $default;
         $filesData = isset($files[$name]) ? $files[$name] : $default;
         if (is_array($postData) && is_array($filesData)) {
             $data = array_replace_recursive($postData, $filesData);
         } else {
             $data = $postData ?: $filesData;
         }
         // Don't submit the form if it is not present in the request.
         if (!$data) {
             return;
         }
     }
     $form->submit($data, $method !== 'PATCH');
 }
Exemple #5
0
 /**
  * Returns absolute URL for given resource path
  *
  * @internal
  *
  * @param string resource path
  * @param array of parameters
  *
  * @return string absolute url
  */
 public function link($path = NULL, array $parameters = array())
 {
     $r = new Nette\Application\Request($this->appRequest->getPresenterName(), $this->appRequest->getMethod(), array_merge(array('action' => 'default', self::PARAM_KEY_PATH => ltrim($path, '/')), $parameters));
     return $this->application->getRouter()->constructUrl($r, $this->httpRequest->getUrl());
 }