public function testQuery() { $request = new Request(['server' => ['REQUEST_URI' => '/vero/asdasd/asdasd?asd=asd']]); $this->assertEquals($request->getQuery('/vero/'), 'asdasd/asdasd'); $request = new Request(['server' => ['REQUEST_URI' => '/vero/index.php/asdasd/asdasd?asd=asd']]); $this->assertEquals($request->getQuery('/vero/', 'index.php/'), 'asdasd/asdasd'); $request = new Request(['server' => ['REQUEST_URI' => '/vero/index.php/']]); $this->assertEquals($request->getQuery('/vero/', 'index.php/'), ''); $request = new Request(['server' => ['REQUEST_URI' => '/vero/']]); $this->assertEquals($request->getQuery('/vero/', 'index.php/'), ''); }
/** * 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; }
/** * {@inheritdoc} */ public function run(Request $req) { $e = $req->param('exception'); if (!$e instanceof \Exception) { throw new \BadMethodCallException('ExceptionHandler Action needs "exception" param in Request!'); } if ($e instanceof Translatable) { $e->translate($this->get('i18n')); } $this->logException($e); $response = $this->response($this->getExceptionResponseBody($e)); if ($e instanceof Exception\NotFound) { $response->headerCode(404); } if ($e instanceof Exception\AccessDenied) { $response->headerCode(403); } return $response; }
/** * Prepare params to set for Request. * * @api * @return array */ protected function getRequestParams(Request $request, $query, $id, $params) { return $params + ['query' => $query, 'action' => $id, 'url' => $this->container->get('router')->url($id, $params)->setGet($request->get())]; }
/** * Create new session. */ public function create(Request $request) { $this->id = TokenGenerator::get(); $this->data['IP'] = $request->ip(); $this->data['UserAgent'] = $request->userAgent(); $this->data['refreshTime'] = time(); $this->data['refreshVisits'] = 0; }
protected function create(Container $c) { return R::createFromGlobals(); }
/** * Register autologed session for currently authorized user. * * @return self */ public function forget(Request $request, Response $response) { if (!$this->autologin) { throw new \BadMethodCallException('To use AutoLogin functionality provide instance of AutologinProvider.'); } if ($key = $request->cookie($this->autologinCookie)) { $response->cookie($this->autologinCookie, '', 1); $this->autologin->delete($key); } return $this; }