Exemplo n.º 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');
     }
 }
Exemplo n.º 2
0
 public function testCanConvertToAndLoadFromArray()
 {
     $jar = new puzzle_cookie_CookieJar(true);
     foreach ($this->getTestCookies() as $cookie) {
         $jar->setCookie($cookie);
     }
     $this->assertCount(3, $jar);
     $arr = $jar->toArray();
     $this->assertCount(3, $arr);
     $newCookieJar = new puzzle_cookie_CookieJar(false, $arr);
     $this->assertCount(3, $newCookieJar);
     $this->assertSame($jar->toArray(), $newCookieJar->toArray());
 }