3 namespace Zumba\GastonJS\Browser;
5 use Zumba\GastonJS\Cookie;
8 * Trait BrowserCookieTrait
9 * @package Zumba\GastonJS\Browser
11 trait BrowserCookieTrait {
13 * Gets the cookies on the browser
17 public function cookies() {
18 $cookies = $this->command('cookies');
19 $objCookies = array();
20 foreach ($cookies as $cookie) {
21 $objCookies[$cookie["name"]] = new Cookie($cookie);
27 * Sets a cookie on the browser, expires times is set in seconds
31 public function setCookie($cookie) {
32 //TODO: add error control when the cookie array is not valid
33 if (isset($cookie["expires"])) {
34 $cookie["expires"] = intval($cookie["expires"]) * 1000;
36 $cookie['value'] = urlencode($cookie['value']);
37 return $this->command('set_cookie', $cookie);
41 * Deletes a cookie on the browser if exists
45 public function removeCookie($cookieName) {
46 return $this->command('remove_cookie', $cookieName);
50 * Clear all the cookies
53 public function clearCookies() {
54 return $this->command('clear_cookies');
58 * Enables or disables the cookies con phantomjs
59 * @param bool $enabled
62 public function cookiesEnabled($enabled = true) {
63 return $this->command('cookies_enabled', $enabled);