/** * Try to set real status of form. * Method is executed only if current status is "created". * * If errors with tokens will be detected exception will be thrown. * * @throws \Vero\UI\Exception * @return self|false */ public function prepare() { if ($this->status != self::CREATED) { return false; } if (($this->useToken || $this->useCSRF) && !$this->session instanceof Session) { throw new \LogicException('If you want to use tokens, instance of Session must be specified!'); } $fun = strtolower($this->method); if ($this->request->method() == $this->method && $this->request->{$fun}($this->name)) { $this->status = self::SENT; // set default values from request data (can by overwritten by setValue()) $this->value = $this->request->{$fun}(); $this->token = $this->request->{$fun}($this->name); // check tokens if ($this->useToken && $this->getBag()->has($this->token)) { throw new Exception('error token', 'global'); } if ($this->useCSRF && $this->request->{$fun}('csrf') != $this->csrf()) { throw new Exception('error csrf', 'global'); } } else { $this->status = self::INIT; $this->token = self::randomToken(); } return $this; }
/** * Find class name for request. * * If Web Controller needs to do something more with request, * this is first method to override. * * @api * @return string|null */ protected function findAction(Request $request) { $router = $this->container->get('router'); $query = $request->getQuery($router->getBase(), $router->getPrefix()); list($id, $class, $params) = $router->match($query, $request->method()); $request->setParams($this->getRequestParams($request, $query, $id, (array) $params)); return $class; }