/** * Sends a cookie. * @param string name of the cookie * @param string value * @param string|int|DateTime expiration time, value 0 means "until the browser is closed" * @param string * @param string * @param bool * @param bool * @return self * @throws XApp_InvalidStateException if HTTP headers have been sent */ public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL) { self::checkHeaders(); setcookie($name, $value, $time ? Nette\DateTime::from($time)->format('U') : 0, $path === NULL ? $this->cookiePath : (string) $path, $domain === NULL ? $this->cookieDomain : (string) $domain, $secure === NULL ? $this->cookieSecure : (bool) $secure, $httpOnly === NULL ? $this->cookieHttpOnly : (bool) $httpOnly); $this->removeDuplicateCookies(); return $this; }
/** * Restricts the search by modified time. * @param string "[operator] [date]" example: >1978-01-23 * @param mixed * @return self */ public function date($operator, $date = NULL) { if (func_num_args() === 1) { // in $operator is predicate if (!preg_match('#^(?:([=<>!]=?|<>)\\s*)?(.+)\\z#i', $operator, $matches)) { throw new Nette\InvalidArgumentException('Invalid date predicate format.'); } list(, $operator, $date) = $matches; $operator = $operator ? $operator : '='; } $date = Nette\DateTime::from($date)->format('U'); return $this->filter(function ($file) use($operator, $date) { return Finder::compare($file->getMTime(), $operator, $date); }); }
/** * Sets the amount of time allowed between requests before the session will be terminated. * @param string|int|DateTime time, value 0 means "until the browser is closed" * @return self */ public function setExpiration($time) { if (empty($time)) { return $this->setOptions(array('gc_maxlifetime' => self::DEFAULT_FILE_LIFETIME, 'cookie_lifetime' => 0)); } else { $time = Nette\DateTime::from($time)->format('U') - time(); return $this->setOptions(array('gc_maxlifetime' => $time, 'cookie_lifetime' => $time)); } }
/** * Sets the expiration of the section or specific variables. * @param string|int|DateTime time, value 0 means "until the browser is closed" * @param mixed optional list of variables / single variable to expire * @return self */ public function setExpiration($time, $variables = NULL) { $this->start(); if (empty($time)) { $time = NULL; $whenBrowserIsClosed = TRUE; } else { $time = Nette\DateTime::from($time)->format('U'); $max = ini_get('session.gc_maxlifetime'); if ($time - time() > $max + 3) { // bulgarian constant trigger_error("The expiration time is greater than the session expiration {$max} seconds", E_USER_NOTICE); } $whenBrowserIsClosed = FALSE; } if ($variables === NULL) { // to entire section $this->meta['']['T'] = $time; $this->meta['']['B'] = $whenBrowserIsClosed; } elseif (is_array($variables)) { // to variables foreach ($variables as $variable) { $this->meta[$variable]['T'] = $time; $this->meta[$variable]['B'] = $whenBrowserIsClosed; } } else { // to variable $this->meta[$variables]['T'] = $time; $this->meta[$variables]['B'] = $whenBrowserIsClosed; } return $this; }