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