327b94885d15cead5d1f51e8adc97335e6dbe854
[yaffs-website] / vendor / jcalderonzumba / mink-phantomjs-driver / src / CookieTrait.php
1 <?php
2
3 namespace Zumba\Mink\Driver;
4
5 use Zumba\GastonJS\Cookie;
6
7 /**
8  * Trait CookieTrait
9  * @package Zumba\Mink\Driver
10  */
11 trait CookieTrait {
12
13   /**
14    * Sets a cookie on the browser, if null value then delete it
15    * @param string $name
16    * @param string $value
17    */
18   public function setCookie($name, $value = null) {
19     if ($value === null) {
20       $this->browser->removeCookie($name);
21     }
22     //TODO: set the cookie with domain, not with url, meaning www.aaa.com or .aaa.com
23     if ($value !== null) {
24       $urlData = parse_url($this->getCurrentUrl());
25       $cookie = array("name" => $name, "value" => $value, "domain" => $urlData["host"]);
26       $this->browser->setCookie($cookie);
27     }
28   }
29
30   /**
31    * Gets a cookie by its name if exists, else it will return null
32    * @param string $name
33    * @return string
34    */
35   public function getCookie($name) {
36     $cookies = $this->browser->cookies();
37     foreach ($cookies as $cookie) {
38       if ($cookie instanceof Cookie && strcmp($cookie->getName(), $name) === 0) {
39         return $cookie->getValue();
40       }
41     }
42     return null;
43   }
44
45 }