Exemple #1
0
 private function add_cookies(puzzle_message_RequestInterface $request, $value)
 {
     if ($value === true) {
         static $cookie = null;
         if (!$cookie) {
             $cookie = new puzzle_subscriber_Cookie();
         }
         $request->getEmitter()->attach($cookie);
     } elseif (is_array($value)) {
         $request->getEmitter()->attach(new puzzle_subscriber_Cookie(puzzle_cookie_CookieJar::fromArray($value, $request->getHost())));
     } elseif ($value instanceof puzzle_cookie_CookieJarInterface) {
         $request->getEmitter()->attach(new puzzle_subscriber_Cookie($value));
     } elseif ($value !== false) {
         throw new InvalidArgumentException('cookies must be an array, ' . 'true, or a puzzle_cookie_CookieJarInterface object');
     }
 }
Exemple #2
0
 public function addCookieHeader(puzzle_message_RequestInterface $request)
 {
     $values = array();
     $scheme = $request->getScheme();
     $host = $request->getHost();
     $path = $request->getPath();
     foreach ($this->cookies as $cookie) {
         if ($cookie->matchesPath($path) && $cookie->matchesDomain($host) && !$cookie->isExpired() && (!$cookie->getSecure() || $scheme == 'https')) {
             $values[] = $cookie->getName() . '=' . self::getCookieValue($cookie->getValue());
         }
     }
     if ($values) {
         $request->setHeader('Cookie', implode(';', $values));
     }
 }