Write a wrapper class for working with cookie . The class must contain the following set of functions:
- preservation
- deletion
- editing
- reading
By default, the cookie should be set to 1 year. The class must be implemented in such a way that it is impossible to create more than one instance of the class.
class Cookie { public static function instance() { static $instance = false; if( $instance === false ) { $instance = new static(); } return $instance; } public static function setCookie($key, $value, $time = 31536000) { setcookie($key, $value, time() + $time, '/') ; } public static function getCookie($key) { if ( isset($_COOKIE[$key]) ){ return $_COOKIE[$key]; } return null; } public static function updateCookie($key, $value, $time = 31536000) { if ( isset($_COOKIE[$key]) ){ self::deleteCookie($key); setcookie($key, $value, time() + $time, '/'); } return null; } public static function deleteCookie($key) { if ( isset($_COOKIE[$key]) ){ self::getCookie($key); unset($_COOKIE[$key]); } } }
that's what i did and i can't figure out if i