/**
* Set a new cookie
*
* <code>
*
* cookie::set('mycookie', 'hello', 60);
* // expires in 1 hour
*
* </code>
*
* @param string $key The name of the cookie
* @param string $value The cookie content
* @param int $lifetime The number of minutes until the cookie expires
* @param string $path The path on the server to set the cookie for
* @param string $domain the domain
* @param boolean $secure only sets the cookie over https
* @param boolean $httpOnly avoids the cookie to be accessed via javascript
* @return boolean true: the cookie has been created, false: cookie creation failed
*/
public static function set($key, $value, $lifetime = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true)
{
// convert array values to json
if (is_array($value)) {
$value = a::json($value);
}
// hash the value
$value = static::hash($value) . '+' . $value;
// store that thing in the cookie global
$_COOKIE[$key] = $value;
// store the cookie
return setcookie($key, $value, static::lifetime($lifetime), $path, $domain, $secure, $httpOnly);
}