You are here

trait BrowserCookieTrait in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/jcalderonzumba/gastonjs/src/Browser/BrowserCookieTrait.php \Zumba\GastonJS\Browser\BrowserCookieTrait

Trait BrowserCookieTrait @package Zumba\GastonJS\Browser

Hierarchy

File

vendor/jcalderonzumba/gastonjs/src/Browser/BrowserCookieTrait.php, line 11

Namespace

Zumba\GastonJS\Browser
View source
trait BrowserCookieTrait {

  /**
   * Gets the cookies on the browser
   *
   * @return Cookie[]
   */
  public function cookies() {
    $cookies = $this
      ->command('cookies');
    $objCookies = array();
    foreach ($cookies as $cookie) {
      $objCookies[$cookie["name"]] = new Cookie($cookie);
    }
    return $objCookies;
  }

  /**
   * Sets a cookie on the browser, expires times is set in seconds
   * @param $cookie
   * @return mixed
   */
  public function setCookie($cookie) {

    //TODO: add error control when the cookie array is not valid
    if (isset($cookie["expires"])) {
      $cookie["expires"] = intval($cookie["expires"]) * 1000;
    }
    $cookie['value'] = urlencode($cookie['value']);
    return $this
      ->command('set_cookie', $cookie);
  }

  /**
   * Deletes a cookie on the browser if exists
   * @param $cookieName
   * @return bool
   */
  public function removeCookie($cookieName) {
    return $this
      ->command('remove_cookie', $cookieName);
  }

  /**
   * Clear all the cookies
   * @return bool
   */
  public function clearCookies() {
    return $this
      ->command('clear_cookies');
  }

  /**
   * Enables or disables the cookies con phantomjs
   * @param bool $enabled
   * @return bool
   */
  public function cookiesEnabled($enabled = true) {
    return $this
      ->command('cookies_enabled', $enabled);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BrowserCookieTrait::clearCookies public function Clear all the cookies
BrowserCookieTrait::cookies public function Gets the cookies on the browser
BrowserCookieTrait::cookiesEnabled public function Enables or disables the cookies con phantomjs
BrowserCookieTrait::removeCookie public function Deletes a cookie on the browser if exists
BrowserCookieTrait::setCookie public function Sets a cookie on the browser, expires times is set in seconds