<?php


namespace CMSMSExt;


use CMSMSExt\core\TSingleton;

class Cookies
{
  use TSingleton;
  
  public function setCookie($name, $value = null, $expire = null, $path = null, $domain = null, $secure = null, $httponly = null)
  {
    return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
  }
  
  /**
   * Retrieve a cookie by name
   * @param string $name
   * @return string|boolean false for failure
   */
  public function getCookie($name)
  {
    if(isset($_COOKIE) && \is_array($_COOKIE) && \array_key_exists($name, $_COOKIE) )
    {
      return $_COOKIE[$name];
    }
    return false;
  }
  
  /**
   * Unset a cookie by name
   * @param string $name
   * @return boolean
   */
  public function unsetCookie($name)
  {
    if(false !== $this->getCookie($name) )
    {
      setcookie($name, '', 1);
      return true;
    }
    return false;
  }
}

?>