コード例 #1
0
ファイル: Presenter.php プロジェクト: nakoukal/fakturace
	/**
	 * Initializes $this->globalParams, $this->signal & $this->signalReceiver, $this->action, $this->view. Called by run().
	 * @return void
	 * @throws Nette\Application\BadRequestException if action name is not valid
	 */
	private function initGlobalParameters()
	{
		// init $this->globalParams
		$this->globalParams = array();
		$selfParams = array();

		$params = $this->request->getParameters();
		if ($this->isAjax()) {
			$params += $this->request->getPost();
		}
		if (isset($this->request->post[self::SIGNAL_KEY])) {
			$params[self::SIGNAL_KEY] = $this->request->post[self::SIGNAL_KEY];
		}

		foreach ($params as $key => $value) {
			if (!preg_match('#^((?:[a-z0-9_]+-)*)((?!\d+\z)[a-z0-9_]+)\z#i', $key, $matches)) {
				continue;
			} elseif (!$matches[1]) {
				$selfParams[$key] = $value;
			} else {
				$this->globalParams[substr($matches[1], 0, -1)][$matches[2]] = $value;
			}
		}

		// init & validate $this->action & $this->view
		$this->changeAction(isset($selfParams[self::ACTION_KEY]) ? $selfParams[self::ACTION_KEY] : self::DEFAULT_ACTION);

		// init $this->signalReceiver and key 'signal' in appropriate params array
		$this->signalReceiver = $this->getUniqueId();
		if (isset($selfParams[self::SIGNAL_KEY])) {
			$param = $selfParams[self::SIGNAL_KEY];
			if (!is_string($param)) {
				$this->error('Signal name is not string.');
			}
			$pos = strrpos($param, '-');
			if ($pos) {
				$this->signalReceiver = substr($param, 0, $pos);
				$this->signal = substr($param, $pos + 1);
			} else {
				$this->signalReceiver = $this->getUniqueId();
				$this->signal = $param;
			}
			if ($this->signal == NULL) { // intentionally ==
				$this->signal = NULL;
			}
		}

		$this->loadState($selfParams);
	}
コード例 #2
0
ファイル: Presenter.php プロジェクト: norbe/nette
	/**
	 * Initializes $this->globalParams, $this->signal & $this->signalReceiver, $this->action, $this->view. Called by run().
	 * @return void
	 * @throws Nette\Application\BadRequestException if action name is not valid
	 */
	private function initGlobalParams()
	{
		// init $this->globalParams
		$this->globalParams = array();
		$selfParams = array();

		$params = $this->request->getParams();
		if ($this->isAjax()) {
			$params = $this->request->getPost() + $params;
		}

		foreach ($params as $key => $value) {
			$a = strlen($key) > 2 ? strrpos($key, self::NAME_SEPARATOR, -2) : FALSE;
			if ($a === FALSE) {
				$selfParams[$key] = $value;
			} else {
				$this->globalParams[substr($key, 0, $a)][substr($key, $a + 1)] = $value;
			}
		}

		// init & validate $this->action & $this->view
		$this->changeAction(isset($selfParams[self::ACTION_KEY]) ? $selfParams[self::ACTION_KEY] : self::DEFAULT_ACTION);

		// init $this->signalReceiver and key 'signal' in appropriate params array
		$this->signalReceiver = $this->getUniqueId();
		if (!empty($selfParams[self::SIGNAL_KEY])) {
			$param = $selfParams[self::SIGNAL_KEY];
			$pos = strrpos($param, '-');
			if ($pos) {
				$this->signalReceiver = substr($param, 0, $pos);
				$this->signal = substr($param, $pos + 1);
			} else {
				$this->signalReceiver = $this->getUniqueId();
				$this->signal = $param;
			}
			if ($this->signal == NULL) { // intentionally ==
				$this->signal = NULL;
			}
		}

		$this->loadState($selfParams);
	}
コード例 #3
0
 /**
  * @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');
 }
コード例 #4
0
ファイル: FormComponent.php プロジェクト: Arachne/Forms
 /**
  * Renders only specified fields. Useful for dynamic ajax forms.
  */
 protected function processRender(FormInterface $form, Request $request)
 {
     $presenter = $this->getPresenter();
     if (!$presenter->isAjax()) {
         throw new BadRequestException('The render signal is only allowed in ajax mode.');
     }
     $fields = $request->getPost($this->lookupPath('Nette\\Application\\UI\\Presenter', true) . self::NAME_SEPARATOR . 'fields');
     if (!$fields) {
         throw new BadRequestException('No fields specified for rendering.');
     }
     $form->handleRequest($request);
     if (!$form->isSubmitted()) {
         throw new BadRequestException('The form was not submitted.');
     }
     $view = $this->getView();
     $widgets = [];
     foreach ($fields as $field) {
         // Validate the field identifier for security reasons. A dot in the identifier would be particularly dangerous.
         if (!Strings::match($field, '~^(?:\\[\\w++\\])++$~')) {
             throw new BadRequestException(sprintf('Field identifier "%s" contains unallowed characters.', $field));
         }
         // Skip duplicates. The renderer would return an empty string on second try.
         if (isset($widgets[$field])) {
             continue;
         }
         // Wrap an exception from PropertyAccessor in a BadRequestException.
         try {
             $fieldView = $this->propertyAccessor->getValue($view, $field);
         } catch (ExceptionInterface $e) {
             throw new BadRequestException(sprintf('FormView not found for field identifier "%s".', $field), 0, $e);
         }
         // Render the field widget.
         $widgets[$field] = $this->renderer->searchAndRenderBlock($fieldView, 'widget');
     }
     $this->getPresenter()->sendJson((object) ['widgets' => $widgets]);
 }
コード例 #5
0
ファイル: SignalAuthorizator.php プロジェクト: ark8/security
 /**
  * @param \Ark8\Security\Authorizators\Request $request
  * @return array
  * @throws \Nette\InvalidStateException
  */
 private function getSignal(Request $request)
 {
     $params = $request->getParameters();
     if ($this->httpRequest->isAjax()) {
         $params += $request->getPost();
     } elseif (($tmp = $request->getPost(Presenter::SIGNAL_KEY)) !== NULL) {
         $params[self::SIGNAL_KEY] = $tmp;
     }
     $signal = NULL;
     $signalReceiver = '';
     if (isset($params[Presenter::SIGNAL_KEY])) {
         $param = $params[Presenter::SIGNAL_KEY];
         $pos = strrpos($param, '-');
         if ($pos) {
             $signalReceiver = substr($param, 0, $pos);
             $signal = substr($param, $pos + 1);
         } else {
             $signalReceiver = $this->getUniqueId();
             $signal = $param;
         }
         if ($signal == NULL) {
             // intentionally ==
             $signal = NULL;
         }
     }
     return [$signal, explode('-', $signalReceiver)];
 }
コード例 #6
0
 /**
  * @param Request $request
  */
 protected function handleWebRequest(Request $request)
 {
     $module = $this->getModule($request->getPresenterName());
     $this->client->setAppname($this->appUrl . ($module ? "/{$module}" : ''));
     if ($module === 'Cron') {
         $this->client->backgroundJob(TRUE);
     }
     $params = $request->getParameters() + $request->getPost();
     $this->transactionName = $this->resolveTransactionName($request, $params);
     $this->client->nameTransaction($this->transactionName);
 }