/** * @param Http\IRequest $httpRequest * @param Http\IResponse $httpResponse */ public function __construct(Http\IRequest $httpRequest, Http\IResponse $httpResponse) { $this->httpRequest = $httpRequest; $this->httpResponse = $httpResponse; if ($this->httpRequest->getQuery(self::SWITCH_PARAM)) { $this->viewType = $this->httpRequest->getQuery(self::SWITCH_PARAM); } else { if ($this->httpRequest->getCookie(self::COOKIE_KEY)) { $this->viewType = $this->httpRequest->getCookie(self::COOKIE_KEY); } } }
/** * @param \DK\Translator\Loaders\Loader|string $pathOrLoader * @param \Nette\Http\IRequest $httpRequest */ public function __construct($pathOrLoader, IRequest $httpRequest = null) { parent::__construct($pathOrLoader); if ($httpRequest !== null) { $this->debugMode = (bool) $httpRequest->getCookie(Panel::COOKIE_DEBUG_KEY); } }
/** * Parses the metadata cookie that our Javascript API set * * @return array */ protected function getMetadataCookie() { $cookieName = $this->config->getMetadataCookieName(); // The cookie value can be wrapped in "-characters so remove them if (!($cookieValue = trim($this->httpRequest->getCookie($cookieName), '"'))) { return array(); } parse_str($cookieValue, $metadata); array_walk($metadata, function (&$value, &$key) { $value = urldecode($value); $key = urldecode($key); }); return $metadata; }
/** * Does session exists for the current request? * @return bool */ public function exists() { return self::$started || $this->request->getCookie($this->getName()) !== NULL; }
/** * Starts and initializes session data. * * @throws Nette\InvalidStateException * @return void */ public function start() { if (self::$started) { return; } $this->configure($this->options); Nette\Diagnostics\Debugger::tryError(); session_start(); if (Nette\Diagnostics\Debugger::catchError($e) && !session_id()) { @session_write_close(); // this is needed throw new Nette\InvalidStateException('session_start(): ' . $e->getMessage(), 0, $e); } self::$started = true; /* structure: __NF: Counter, BrowserKey, Data, Meta, Time DATA: section->variable = data META: section->variable = Timestamp, Browser, Version */ unset($_SESSION['__NT'], $_SESSION['__NS'], $_SESSION['__NM']); // old unused structures // initialize structures $nf =& $_SESSION['__NF']; if (empty($nf)) { // new session $nf = array('C' => 0); } else { $nf['C']++; } // session regenerate every 30 minutes $nfTime =& $nf['Time']; $time = time(); if ($time - $nfTime > self::REGENERATE_INTERVAL) { $this->regenerated = $this->regenerated || isset($nfTime); $nfTime = $time; } // browser closing detection $browserKey = $this->request->getCookie('nette-browser'); if (!$browserKey) { $browserKey = Nette\Utils\Strings::random(); } $browserClosed = !isset($nf['B']) || $nf['B'] !== $browserKey; $nf['B'] = $browserKey; // resend cookie $this->sendCookie(); // process meta metadata if (isset($nf['META'])) { $now = time(); // expire section variables foreach ($nf['META'] as $section => $metadata) { if (is_array($metadata)) { foreach ($metadata as $variable => $value) { if (!empty($value['B']) && $browserClosed || !empty($value['T']) && $now > $value['T'] || isset($nf['DATA'][$section][$variable]) && is_object($nf['DATA'][$section][$variable]) && (isset($value['V']) ? $value['V'] : null) != Nette\Reflection\ClassType::from($nf['DATA'][$section][$variable])->getAnnotation('serializationVersion')) { if ($variable === '') { // expire whole section unset($nf['META'][$section], $nf['DATA'][$section]); continue 2; } unset($nf['META'][$section][$variable], $nf['DATA'][$section][$variable]); } } } } } if ($this->regenerated) { $this->regenerated = false; $this->regenerateId(); } register_shutdown_function(array($this, 'clean')); }
/** * @inheritdoc */ public function getCookie($key, $default = NULL) { return $this->current->getCookie($key, $default); }
public function beforeRender() { $this->template->cssLoaderFile = $this->cssLoaderFile; $this->template->jsLoaderFile = $this->jsLoaderFile; $this->template->fullcss = $this->httpRequest->getCookie('fullcss'); }