Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / vendor / jcalderonzumba / gastonjs / src / Browser / BrowserCookieTrait.php
1 <?php
2
3 namespace Zumba\GastonJS\Browser;
4
5 use Zumba\GastonJS\Cookie;
6
7 /**
8  * Trait BrowserCookieTrait
9  * @package Zumba\GastonJS\Browser
10  */
11 trait BrowserCookieTrait {
12   /**
13    * Gets the cookies on the browser
14    *
15    * @return Cookie[]
16    */
17   public function cookies() {
18     $cookies = $this->command('cookies');
19     $objCookies = array();
20     foreach ($cookies as $cookie) {
21       $objCookies[$cookie["name"]] = new Cookie($cookie);
22     }
23     return $objCookies;
24   }
25
26   /**
27    * Sets a cookie on the browser, expires times is set in seconds
28    * @param $cookie
29    * @return mixed
30    */
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;
35     }
36     $cookie['value'] = urlencode($cookie['value']);
37     return $this->command('set_cookie', $cookie);
38   }
39
40   /**
41    * Deletes a cookie on the browser if exists
42    * @param $cookieName
43    * @return bool
44    */
45   public function removeCookie($cookieName) {
46     return $this->command('remove_cookie', $cookieName);
47   }
48
49   /**
50    * Clear all the cookies
51    * @return bool
52    */
53   public function clearCookies() {
54     return $this->command('clear_cookies');
55   }
56
57   /**
58    * Enables or disables the cookies con phantomjs
59    * @param bool $enabled
60    * @return bool
61    */
62   public function cookiesEnabled($enabled = true) {
63     return $this->command('cookies_enabled', $enabled);
64   }
65 }