Ejemplo n.º 1
0
 public function testRemoveExpiredOnUnserialize()
 {
     $dt = new DateTime();
     $dt->setTimezone(new DateTimeZone('UTC'));
     $dt->modify('+2 seconds');
     $this->jar->store(array('name' => 'foo', 'value' => 'bar', 'domain' => '.example.com', 'path' => '/', 'expires' => $dt->format(DateTime::COOKIE)));
     $serialized = serialize($this->jar);
     sleep(2);
     $newJar = unserialize($serialized);
     $this->assertEquals(array(), $newJar->getAll());
 }
Ejemplo n.º 2
0
 /**
  * Adds a cookie to the request
  *
  * If the request does not have a CookieJar object set, this method simply
  * appends a cookie to "Cookie:" header.
  *
  * If a CookieJar object is available, the cookie is stored in that object.
  * Data from request URL will be used for setting its 'domain' and 'path'
  * parameters, 'expires' and 'secure' will be set to null and false,
  * respectively. If you need further control, use CookieJar's methods.
  *
  * @param string $name  cookie name
  * @param string $value cookie value
  *
  * @return   HTTP_Request2
  * @throws   HTTP_Request2_LogicException
  * @see      setCookieJar()
  */
 public function addCookie($name, $value)
 {
     if (!empty($this->cookieJar)) {
         $this->cookieJar->store(array('name' => $name, 'value' => $value), $this->url);
     } else {
         $cookie = $name . '=' . $value;
         if (preg_match(self::REGEXP_INVALID_COOKIE, $cookie)) {
             throw new HTTP_Request2_LogicException("Invalid cookie: '{$cookie}'", HTTP_Request2_Exception::INVALID_ARGUMENT);
         }
         $cookies = empty($this->headers['cookie']) ? '' : $this->headers['cookie'] . '; ';
         $this->setHeader('cookie', $cookies . $cookie);
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Removes subdomains to get the registered domain (the first after top-level)
  *
  * The method will check Public Suffix List to find out where top-level
  * domain ends and registered domain starts. It will remove domain parts
  * to the left of registered one.
  *
  * @param string $domain domain name
  *
  * @return string|bool   registered domain, will return false if $domain is
  *                       either invalid or a TLD itself
  */
 public static function getRegisteredDomain($domain)
 {
     $domainParts = explode('.', ltrim($domain, '.'));
     // load the list if needed
     if (empty(self::$psl)) {
         $path = '@data_dir@' . DIRECTORY_SEPARATOR . 'HTTP_Request2';
         if (0 === strpos($path, '@' . 'data_dir@')) {
             $path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data');
         }
         self::$psl = (include_once $path . DIRECTORY_SEPARATOR . 'public-suffix-list.php');
     }
     if (!($result = self::checkDomainsList($domainParts, self::$psl))) {
         // known TLD, invalid domain name
         return false;
     }
     // unknown TLD
     if (!strpos($result, '.')) {
         // fallback to checking that domain "has at least two dots"
         if (2 > ($count = count($domainParts))) {
             return false;
         }
         return $domainParts[$count - 2] . '.' . $domainParts[$count - 1];
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Removes subdomains to get the registered domain (the first after top-level)
  *
  * The method will check Public Suffix List to find out where top-level
  * domain ends and registered domain starts. It will remove domain parts
  * to the left of registered one.
  *
  * @param string $domain domain name
  *
  * @return string|bool   registered domain, will return false if $domain is
  *                       either invalid or a TLD itself
  */
 public static function getRegisteredDomain($domain)
 {
     $domainParts = explode('.', ltrim($domain, '.'));
     // load the list if needed
     if (empty(self::$psl)) {
         $path = '/Users/lefteriskavadasoffice/Documents/Aptana Studio 3 Workspace/Composer Dependencies for K2v3/vendor/pear-pear.php.net/HTTP_Request2/data' . DIRECTORY_SEPARATOR . 'HTTP_Request2';
         if (0 === strpos($path, '@' . 'data_dir@')) {
             $path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data');
         }
         self::$psl = (include_once $path . DIRECTORY_SEPARATOR . 'public-suffix-list.php');
     }
     if (!($result = self::checkDomainsList($domainParts, self::$psl))) {
         // known TLD, invalid domain name
         return false;
     }
     // unknown TLD
     if (!strpos($result, '.')) {
         // fallback to checking that domain "has at least two dots"
         if (2 > ($count = count($domainParts))) {
             return false;
         }
         return $domainParts[$count - 2] . '.' . $domainParts[$count - 1];
     }
     return $result;
 }
 /**
  * Removes subdomains to get the registered domain (the first after top-level)
  *
  * The method will check Public Suffix List to find out where top-level
  * domain ends and registered domain starts. It will remove domain parts
  * to the left of registered one.
  *
  * @param string $domain domain name
  *
  * @return string|bool   registered domain, will return false if $domain is
  *                       either invalid or a TLD itself
  */
 public static function getRegisteredDomain($domain)
 {
     $domainParts = explode('.', ltrim($domain, '.'));
     // load the list if needed
     if (empty(self::$psl)) {
         $path = 'C:\\Users\\jodrew\\Documents\\_DEV_PROJECTS\\Web\\phpmssqldemo.azurewebsites.net\\phpmssqldemo\\vendor/pear-pear.php.net/HTTP_Request2/data' . DIRECTORY_SEPARATOR . 'HTTP_Request2';
         if (0 === strpos($path, '@' . 'data_dir@')) {
             $path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data');
         }
         self::$psl = (include_once $path . DIRECTORY_SEPARATOR . 'public-suffix-list.php');
     }
     if (!($result = self::checkDomainsList($domainParts, self::$psl))) {
         // known TLD, invalid domain name
         return false;
     }
     // unknown TLD
     if (!strpos($result, '.')) {
         // fallback to checking that domain "has at least two dots"
         if (2 > ($count = count($domainParts))) {
             return false;
         }
         return $domainParts[$count - 2] . '.' . $domainParts[$count - 1];
     }
     return $result;
 }