/** * @inheritdoc */ public function getQuery($key = NULL, $default = NULL) { if (func_num_args() === 0) { return $this->current->getQuery(); } return $this->current->getQuery($key, $default); }
/** * Parse data for input * @return array * * @throws BadRequestException */ protected function parseData() { $postQuery = (array) $this->httpRequest->getPost(); $urlQuery = (array) $this->httpRequest->getQuery(); $requestBody = $this->parseRequestBody(); return array_merge($urlQuery, $requestBody, $postQuery); }
/** * Send JSONP response to output * @param IRequest $httpRequest * @param IResponse $httpResponse * @throws \Drahak\Restful\InvalidArgumentException */ public function send(IRequest $httpRequest, IResponse $httpResponse) { $httpResponse->setContentType($this->contentType ? $this->contentType : 'application/javascript', 'UTF-8'); $data = array(); $data['response'] = $this->data; $data['status'] = $httpResponse->getCode(); $data['headers'] = $httpResponse->getHeaders(); $callback = $httpRequest->getQuery('jsonp') ? Strings::webalize($httpRequest->getQuery('jsonp'), NULL, FALSE) : ''; echo $callback . '(' . $this->mapper->stringify($data, $this->isPrettyPrint()) . ');'; }
/** * Get all parameters * @return array */ public function getParameters() { if (!$this->data) { if ($this->request->getQuery()) { $this->data = $this->request->getQuery(); } else { if ($this->request->getPost()) { $this->data = $this->request->getPost(); } else { $this->data = $this->parseRequest(file_get_contents('php://input')); } } } return $this->data; }
/** * CLI commands run from app/console.php * * Maps HTTP request to a Request object. * @return Nette\Application\Request|NULL */ public function match(Nette\Http\IRequest $httpRequest) { $this->loadLocales(); $urlPath = new Services\UrlPath($httpRequest); $urlPath->setPredefinedLocales($this->locales); /** @var Url $urlEntity */ $urlEntity = $this->loadUrlEntity($urlPath->getPath(true)); if ($urlEntity === null) { // no route found $this->onUrlNotFound($urlPath); return null; } if ($urlEntity->getActualUrlToRedirect() === null) { $presenter = $urlEntity->getPresenter(); $internal_id = $urlEntity->getInternalId(); $action = $urlEntity->getAction(); } else { $presenter = $urlEntity->getActualUrlToRedirect()->getPresenter(); $internal_id = $urlEntity->getActualUrlToRedirect()->getInternalId(); $action = $urlEntity->getActualUrlToRedirect()->getAction(); } $params = $httpRequest->getQuery(); $params['action'] = $action; $params['locale'] = $urlPath->getLocale(); $this->urlParametersConverter->in($urlEntity, $params); // todo if ($internal_id !== null) { $params['internal_id'] = $internal_id; } return new Nette\Application\Request($presenter, $httpRequest->getMethod(), $params, $httpRequest->getPost(), $httpRequest->getFiles()); }
/** * Maps HTTP request to a Request object. * @return Nette\Application\Request|NULL */ public function match(Nette\Http\IRequest $httpRequest) { if ($httpRequest->getUrl()->getPathInfo() !== '') { return NULL; } // combine with precedence: get, (post,) defaults $params = $httpRequest->getQuery(); $params += $this->defaults; if (!isset($params[self::PRESENTER_KEY]) || !is_string($params[self::PRESENTER_KEY])) { return NULL; } $presenter = $this->module . $params[self::PRESENTER_KEY]; unset($params[self::PRESENTER_KEY]); return new Application\Request( $presenter, $httpRequest->getMethod(), $params, $httpRequest->getPost(), $httpRequest->getFiles(), array(Application\Request::SECURED => $httpRequest->isSecured()) ); }
/** * Maps HTTP request to a Request object. * * @param Nette\Http\IRequest $httpRequest * @return Request|NULL */ public function match(Nette\Http\IRequest $httpRequest) { $relativeUrl = trim($httpRequest->getUrl()->relativeUrl, "/"); $path = trim($httpRequest->getUrl()->path, "/"); if ($relativeUrl == "") { $target = $this->defaultRoute; $this->currentTarget->setCurrentTarget($this->targetDao->findTarget($target->presenter, $target->action, $target->id)); } elseif ($relativeUrl == "sitemap.xml") { $target = new Target("Seo:Meta", "sitemap"); } elseif ($relativeUrl == "robots.txt") { $target = new Target("Seo:Meta", "robots"); } elseif (substr($relativeUrl, 0, 6) == "google" && $this->settingsDao->getWebmasterToolsName() == $relativeUrl) { $target = new Target("Seo:Meta", "googleWebmasterTools"); } else { $route = $this->routeDao->findRouteBySlug($relativeUrl, TRUE); if (!$route) { $route = $this->routeDao->findRouteBySlug($path, TRUE); if (!$route) { return NULL; } } $this->currentTarget->setCurrentTarget($route->getTarget()); $target = new Target($route->target->targetPresenter, $route->target->targetAction, $route->target->targetId); } $params = array(); $params["action"] = $target->action; if ($target->id) { $params["id"] = $target->id; } $params += $httpRequest->getQuery(); return new Request($target->presenter, $httpRequest->getMethod(), $params, $httpRequest->getPost(), $httpRequest->getFiles(), array(Request::SECURED => $httpRequest->isSecured())); }
/** * @param Http\Request $request * @return array */ private function parse(Http\IRequest $request) { $params = array_merge($request->getPost(), $request->getQuery()); if ($this->parser !== null) { $parsed = $this->parser->parse($request->getRawBody()); $params = array_merge($params, $parsed); } return $params; }
/** * @param string $key * @param mixed $default * @return mixed|null */ protected function getRequest($key, $default = NULL) { if ($value = $this->httpRequest->getPost($key)) { return $value; } if ($value = $this->httpRequest->getQuery($key)) { return $value; } return $default; }
/** * Maps HTTP request to a Request object. * @return array|NULL */ public function match(Nette\Http\IRequest $request) { if ($request->getUrl()->getPathInfo() !== '') { return NULL; } // combine with precedence: get, (post,) defaults $params = $request->getQuery(); $params += $this->defaults; return $params; }
/** * @param Nette\Http\IRequest $httpRequest * @param Nette\Http\IResponse $httpResponse * @throws \Nette\Application\BadRequestException */ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse) { $httpResponse->setContentType($this->contentType); $httpResponse->setExpiration(FALSE); $callback = $httpRequest->getQuery(self::$callbackName); if (is_null($callback)) { throw new \Nette\Application\BadRequestException("Invalid JSONP request."); } echo $callback . "(" . Nette\Utils\Json::encode($this->payload) . ")"; }
/** * Is pretty print enabled * @param IRequest $request * @return boolean */ protected function isPrettyPrint() { $prettyPrintKey = $this->request->getQuery($this->prettyPrintKey); if ($prettyPrintKey === 'false') { return FALSE; } if ($prettyPrintKey === 'true') { return TRUE; } return $this->prettyPrint; }
/** * Create paginator * @param int|null $offset * @param int|null $limit * @return Paginator * * @throws InvalidStateException */ protected function createPaginator($offset = NULL, $limit = NULL) { $offset = $this->request->getQuery('offset', $offset); $limit = $this->request->getQuery('limit', $limit); if ($offset === NULL || $limit === NULL) { throw new InvalidStateException('To create paginator add offset and limit query parameter to request URL'); } $paginator = new Paginator(); $paginator->setItemsPerPage($limit); $paginator->setPage(floor($offset / $limit) + 1); return $paginator; }
/** * Get prederred method * @param IRequest $request * @return string */ protected function getPreferredMethod(IRequest $request) { $method = $request->getMethod(); $isPost = $method === IRequest::POST; $header = $request->getHeader(self::OVERRIDE_HEADER); $param = $request->getQuery(self::OVERRIDE_PARAM); if ($header && $isPost) { return $header; } if ($param && $isPost) { return $param; } return $request->getMethod(); }
/** * Signal for receive a response from gateway. */ public function handleResponse() { $data = $this->httpRequest->isMethod(IRequest::POST) ? $this->httpRequest->getPost() : $this->httpRequest->getQuery(); $response = NULL; try { $response = $this->client->receiveResponse($data); } catch (Csob\Exception $e) { if ($response === NULL && $e instanceof Csob\ExceptionWithResponse) { $response = $e->getResponse(); } $this->onError($this, $e, $response); return; } $this->onResponse($this, $response); }
/** * Maps HTTP request to a Request object. * * @return AppRequest|NULL */ public function match(HttpRequest $httpRequest) { $url = $httpRequest->getUrl(); $slug = rtrim(substr($url->getPath(), strrpos($url->getScriptPath(), '/') + 1), '/'); foreach ($this->tableOut as $destination2 => $slug2) { if ($slug === rtrim($slug2, '/')) { $destination = $destination2; break; } } if (!isset($destination)) { return NULL; } $params = $httpRequest->getQuery(); $pos = strrpos($destination, ':'); $presenter = substr($destination, 0, $pos); $params['action'] = substr($destination, $pos + 1); return new AppRequest($presenter, $httpRequest->getMethod(), $params, $httpRequest->getPost(), $httpRequest->getFiles(), array(AppRequest::SECURED => $httpRequest->isSecured())); }
public function match(IRequest $httpRequest) { $url = $httpRequest->getUrl(); $basePath = Strings::replace($url->getBasePath(), '/\\//', '\\/'); $cleanPath = Strings::replace($url->getPath(), "/^" . $basePath . "/"); $path = Strings::replace($this->_getPath(), '/\\//', '\\/'); $pathRexExp = empty($path) ? "/^.+\$/" : "/^" . $path . "\\/.*\$/"; if (!Strings::match($cleanPath, $pathRexExp)) { return; } $params = $httpRequest->getQuery(); // Get presenter action if (!isset($params['action']) || empty($params['action'])) { $params['action'] = $this->_detectAction($httpRequest); } $frags = explode('/', Strings::replace($cleanPath, '/^' . $path . '\\//')); $resource = Strings::firstUpper($frags[0]); // Set 'id' parameter if not custom action if (isset($frags[1]) && $this->_isApiAction($params['action'])) { $params['id'] = $frags[1]; } return new Request(empty($this->module) ? $resource : $this->module . ':' . $resource, $httpRequest->getMethod(), $params); }
/** * @param Nette\Http\IRequest $httpRequest * @return Request|null */ public function match(Nette\Http\IRequest $httpRequest) { $url = $httpRequest->getUrl(); $path = substr($url->path, strlen($url->basePath)); if (in_array($path, $this->options[self::IGNORE_URL])) { return NULL; } if ($action = $this->source->toAction($url)) { $params = array_merge($httpRequest->getQuery(), $action->getParameters()); $presenter = $action->getPresenter(); $params['action'] = $action->getAction(); // presenter not set from ISource, load from parameters or default presenter if (!mb_strlen($presenter)) { if (isset($params['presenter']) && $params['presenter']) { $presenter = $params['presenter']; } else { return NULL; } } unset($params['presenter']); return new Request($presenter, $httpRequest->getMethod(), $params, $httpRequest->getPost(), $httpRequest->getFiles()); } return NULL; }
/** * Gets the switch param value from the query string (GET header) * * @return string */ public function getSwitchParamValue() { return $this->httpRequest->getQuery(self::SWITCH_PARAM, self::VIEW_FULL); }
Nette\InvalidArgumentException("Argument must be array or string in format Presenter:action, '$defaults' given.");}$defaults=array(self::PRESENTER_KEY=>substr($defaults,0,$a),'action'=>$a===strlen($defaults)-1?Application\UI\Presenter::DEFAULT_ACTION:substr($defaults,$a+1));}if(isset($defaults[self::MODULE_KEY])){$this->module=$defaults[self::MODULE_KEY].':';unset($defaults[self::MODULE_KEY]);}$this->defaults=$defaults;$this->flags=$flags;}function match(Nette\Http\IRequest$httpRequest){if($httpRequest->getUrl()->getPathInfo()!==''){return NULL;}$params=$httpRequest->getQuery();$params+=$this->defaults;if(!isset($params[self::PRESENTER_KEY])){throw new Nette\InvalidStateException('Missing presenter.');}$presenter=$this->module.$params[self::PRESENTER_KEY];unset($params[self::PRESENTER_KEY]);return new Application\Request($presenter,$httpRequest->getMethod(),$params,$httpRequest->getPost(),$httpRequest->getFiles(),array(Application\Request::SECURED=>$httpRequest->isSecured()));}function
/** * @param IRequest $request * * @return string */ protected function detectMethod(IRequest $request) { $requestMethod = $request->getMethod(); if ($requestMethod !== 'POST') { return $request->getMethod(); } $method = $request->getHeader(self::METHOD_OVERRIDE_HTTP_HEADER); if (isset($method)) { return Strings::upper($method); } $method = $request->getQuery(self::METHOD_OVERRIDE_QUERY_PARAM); if (isset($method)) { return Strings::upper($method); } return $requestMethod; }
function match(Nette\Http\IRequest $httpRequest) { if ($httpRequest->getUrl()->getPathInfo() !== '') { return NULL; } $params = $httpRequest->getQuery(); $params += $this->defaults; if (!isset($params[self::PRESENTER_KEY])) { throw new Nette\InvalidStateException('Missing presenter.'); } $presenter = $this->module . $params[self::PRESENTER_KEY]; unset($params[self::PRESENTER_KEY]); return new Application\Request($presenter, $httpRequest->getMethod(), $params, $httpRequest->getPost(), $httpRequest->getFiles(), array(Application\Request::SECURED => $httpRequest->isSecured())); }
/** * @return bool */ public function isTest() { return (bool) $this->request->getQuery('test', FALSE); }
/** * @param Nette\Http\IRequest $request * @param null|float $click_lat * @param null|float $click_lon * @return Nette\Database\Table\Selection */ public function getClickQueryByMode(Nette\Http\IRequest $request, $click_lat = null, $click_lon = null) { if (!$click_lat && !$click_lon) { $click_lat = doubleval($request->getQuery("click_lat")); $click_lon = doubleval($request->getQuery("click_lon")); } $mapCoords = new Coords($request->getQuery("map_lat1"), $request->getQuery("map_lat2"), $request->getQuery("map_lon1"), $request->getQuery("map_lon2")); $lat1 = doubleval($click_lat) - self::CLICK_POINT_CIRCLE_RADIUS * $mapCoords->getDeltaLat(); $lat2 = doubleval($click_lat) + self::CLICK_POINT_CIRCLE_RADIUS * $mapCoords->getDeltaLat(); $lon1 = doubleval($click_lon) - self::CLICK_POINT_CIRCLE_RADIUS * $mapCoords->getDeltaLon(); $lon2 = doubleval($click_lon) + self::CLICK_POINT_CIRCLE_RADIUS * $mapCoords->getDeltaLon(); $requestCoords = new Coords($lat1, $lat2, $lon1, $lon2); switch ($request->getQuery("mode")) { case WifiPresenter::MODE_SEARCH: $params = array(); if ($request->getQuery("ssidmac")) { if (MyUtils::isMacAddress($request->getQuery("ssidmac"))) { $params['mac'] = urldecode($request->getQuery("ssidmac")); } else { $params["ssid"] = $request->getQuery("ssidmac"); } } if ($request->getQuery("channel") != null && $request->getQuery("channel") != "") { $params['channel'] = intval($request->getQuery("channel")); } if ($request->getQuery("security") != null && $request->getQuery("security") != "") { $params['sec'] = intval($request->getQuery("security")); } if ($request->getQuery("source") != null && $request->getQuery("source") != "") { $params['id_source'] = intval($request->getQuery("source")); } $sql = $this->getSearchQuery($requestCoords, $params); break; case WifiPresenter::MODE_ONE: $params['ssid'] = $request->getQuery('ssid'); $sql = $this->getSearchQuery($requestCoords, $params); break; default: $sql = $this->getNetsRangeQuery($requestCoords); } $sql->select("*,SQRT(POW(latitude-?,2)+POW(longitude-?,2)) AS distance ", doubleval($click_lat), doubleval($click_lon)); $sql->order("distance"); return $sql; }
/** * Returns GET data * * @return array */ public function getGetData() { return $this->httpRequest->getQuery(); }
public function __construct(MerchantConfig $config = NULL, Nette\Http\IRequest $request, Nette\Application\LinkGenerator $linkGenerator) { $this->request = $request; parent::__construct($config, $this->request->getQuery()); $this->linkGenerator = $linkGenerator; }
/** * Maps HTTP request to a Request object. * @return array|NULL */ public function match(Nette\Http\IRequest $request) { // combine with precedence: mask (params in URL-path), fixity, query, (post,) defaults // 1) URL MASK $url = $request->getUrl(); $re = $this->re; if ($this->type === self::HOST) { $host = $url->getHost(); $path = '//' . $host . $url->getPath(); $parts = ip2long($host) ? [$host] : array_reverse(explode('.', $host)); $re = strtr($re, ['/%basePath%/' => preg_quote($url->getBasePath(), '#'), '%tld%' => preg_quote($parts[0], '#'), '%domain%' => preg_quote(isset($parts[1]) ? "{$parts['1']}.{$parts['0']}" : $parts[0], '#'), '%sld%' => preg_quote(isset($parts[1]) ? $parts[1] : '', '#'), '%host%' => preg_quote($host, '#')]); } elseif ($this->type === self::RELATIVE) { $basePath = $url->getBasePath(); if (strncmp($url->getPath(), $basePath, strlen($basePath)) !== 0) { return NULL; } $path = (string) substr($url->getPath(), strlen($basePath)); } else { $path = $url->getPath(); } if ($path !== '') { $path = rtrim(rawurldecode($path), '/') . '/'; } if (!($matches = Strings::match($path, $re))) { // stop, not matched return NULL; } // assigns matched values to parameters $params = []; foreach ($matches as $k => $v) { if (is_string($k) && $v !== '') { $params[$this->aliases[$k]] = $v; } } // 2) CONSTANT FIXITY foreach ($this->metadata as $name => $meta) { if (!isset($params[$name]) && isset($meta['fixity']) && $meta['fixity'] !== self::OPTIONAL) { $params[$name] = NULL; // cannot be overwriten in 3) and detected by isset() in 4) } } // 3) QUERY if ($this->xlat) { $params += self::renameKeys($request->getQuery(), array_flip($this->xlat)); } else { $params += $request->getQuery(); } // 4) APPLY FILTERS & FIXITY foreach ($this->metadata as $name => $meta) { if (isset($params[$name])) { if (!is_scalar($params[$name])) { } elseif (isset($meta[self::FILTER_TABLE][$params[$name]])) { // applies filterTable only to scalar parameters $params[$name] = $meta[self::FILTER_TABLE][$params[$name]]; } elseif (isset($meta[self::FILTER_TABLE]) && !empty($meta[self::FILTER_STRICT])) { return NULL; // rejected by filterTable } elseif (isset($meta[self::FILTER_IN])) { // applies filterIn only to scalar parameters $params[$name] = call_user_func($meta[self::FILTER_IN], (string) $params[$name]); if ($params[$name] === NULL && !isset($meta['fixity'])) { return NULL; // rejected by filter } } } elseif (isset($meta['fixity'])) { $params[$name] = $meta[self::VALUE]; } } if (isset($this->metadata[NULL][self::FILTER_IN])) { $params = call_user_func($this->metadata[NULL][self::FILTER_IN], $params); if ($params === NULL) { return NULL; } } return $params; }
/** * Maps HTTP request to a Request object. * @return Nette\Application\Request|NULL */ public function match(Nette\Http\IRequest $httpRequest) { // combine with precedence: mask (params in URL-path), fixity, query, (post,) defaults // 1) URL MASK $url = $httpRequest->getUrl(); $re = $this->re; if ($this->type === self::HOST) { $host = $url->getHost(); $path = '//' . $host . $url->getPath(); $host = ip2long($host) ? array($host) : array_reverse(explode('.', $host)); $re = strtr($re, array('/%basePath%/' => preg_quote($url->getBasePath(), '#'), '%tld%' => preg_quote($host[0], '#'), '%domain%' => preg_quote(isset($host[1]) ? "{$host['1']}.{$host['0']}" : $host[0], '#'))); } elseif ($this->type === self::RELATIVE) { $basePath = $url->getBasePath(); if (strncmp($url->getPath(), $basePath, strlen($basePath)) !== 0) { return NULL; } $path = (string) substr($url->getPath(), strlen($basePath)); } else { $path = $url->getPath(); } if ($path !== '') { $path = rtrim($path, '/') . '/'; } if (!($matches = Strings::match($path, $re))) { // stop, not matched return NULL; } // deletes numeric keys, restore '-' chars $params = array(); foreach ($matches as $k => $v) { if (is_string($k) && $v !== '') { $params[str_replace('___', '-', $k)] = $v; // trick } } // 2) CONSTANT FIXITY foreach ($this->metadata as $name => $meta) { if (isset($params[$name])) { //$params[$name] = $this->flags & self::CASE_SENSITIVE === 0 ? strtolower($params[$name]) : */$params[$name]; // strtolower damages UTF-8 } elseif (isset($meta['fixity']) && $meta['fixity'] !== self::OPTIONAL) { $params[$name] = NULL; // cannot be overwriten in 3) and detected by isset() in 4) } } // 3) QUERY if ($this->xlat) { $params += self::renameKeys($httpRequest->getQuery(), array_flip($this->xlat)); } else { $params += $httpRequest->getQuery(); } // 4) APPLY FILTERS & FIXITY foreach ($this->metadata as $name => $meta) { if (isset($params[$name])) { if (!is_scalar($params[$name])) { } elseif (isset($meta[self::FILTER_TABLE][$params[$name]])) { // applies filterTable only to scalar parameters $params[$name] = $meta[self::FILTER_TABLE][$params[$name]]; } elseif (isset($meta[self::FILTER_TABLE]) && !empty($meta[self::FILTER_STRICT])) { return NULL; // rejected by filterTable } elseif (isset($meta[self::FILTER_IN])) { // applies filterIn only to scalar parameters $params[$name] = call_user_func($meta[self::FILTER_IN], (string) $params[$name]); if ($params[$name] === NULL && !isset($meta['fixity'])) { return NULL; // rejected by filter } } } elseif (isset($meta['fixity'])) { $params[$name] = $meta[self::VALUE]; } } if (isset($this->metadata[NULL][self::FILTER_IN])) { $params = call_user_func($this->metadata[NULL][self::FILTER_IN], $params); if ($params === NULL) { return NULL; } } // 5) BUILD Request if (!isset($params[self::PRESENTER_KEY])) { throw new Nette\InvalidStateException('Missing presenter in route definition.'); } elseif (!is_string($params[self::PRESENTER_KEY])) { return NULL; } if (isset($this->metadata[self::MODULE_KEY])) { if (!isset($params[self::MODULE_KEY])) { throw new Nette\InvalidStateException('Missing module in route definition.'); } $presenter = $params[self::MODULE_KEY] . ':' . $params[self::PRESENTER_KEY]; unset($params[self::MODULE_KEY], $params[self::PRESENTER_KEY]); } else { $presenter = $params[self::PRESENTER_KEY]; unset($params[self::PRESENTER_KEY]); } return new Application\Request($presenter, $httpRequest->getMethod(), $params, $httpRequest->getPost(), $httpRequest->getFiles(), array(Application\Request::SECURED => $httpRequest->isSecured())); }
/** * @param Nette\Http\IRequest $request * @return string */ public function resolveMethod(Nette\Http\IRequest $request) { if (!empty($request->getHeader('X-HTTP-Method-Override'))) { return Strings::upper($request->getHeader('X-HTTP-Method-Override')); } if ($method = Strings::upper($request->getQuery('__apiRouteMethod'))) { if (isset($this->actions[$method])) { return $method; } } return Strings::upper($request->getMethod()); }