inst_set($name, $value, $expiry, $path, $domain, $secure, $httpOnly); } /** * Get a cookie variable */ static function get($name) { return self::get_inst()->inst_get($name); } static function forceExpiry($name, $path = null, $domain = null) { return self::get_inst()->inst_forceExpiry($name, $path, $domain); } static function set_report_errors($reportErrors) { return self::get_inst()->inst_set_report_errors($reportErrors); } static function report_errors() { return self::get_inst()->inst_report_errors(); } protected function inst_set($name, $value, $expiry = 90, $path = null, $domain = null, $secure = false, $httpOnly = false) { if(!headers_sent($file, $line)) { $expiry = $expiry > 0 ? time()+(86400*$expiry) : $expiry; $path = ($path) ? $path : Director::baseURL(); setcookie($name, $value, $expiry, $path, $domain, $secure, $httpOnly); } else { if(self::$report_errors) { user_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING); } } } protected function inst_get($name) { return isset($_COOKIE[$name]) ? $_COOKIE[$name] : null; } protected function inst_forceExpiry($name, $path = null, $domain = null) { if(!headers_sent($file, $line)) { self::set($name, null, -20, $path, $domain); } } protected function inst_set_report_errors($reportErrors) { self::$report_errors = $reportErrors; } protected function report_errors() { return self::$report_errors; } }