/**
  * @param string $filecontent
  *
  * @return CookieCollectionInterface
  */
 public function parseContent(string $filecontent) : CookieCollectionInterface
 {
     $cookies = new CookieCollection();
     foreach (explode("\n", $filecontent) as $line) {
         $line = trim($line);
         $cookieData = array_map('trim', explode("\t", $line, 7));
         if (count($cookieData) !== 7) {
             continue;
         }
         $httpOnly = false;
         $httpOnlyPrefixLength = strlen(self::HTTP_ONLY_PREFIX);
         if (substr($cookieData[0], 0, $httpOnlyPrefixLength) === self::HTTP_ONLY_PREFIX) {
             $cookieData[0] = substr($cookieData[0], $httpOnlyPrefixLength);
             $httpOnly = true;
         } else {
             if ($cookieData[0][0] === '#') {
                 continue;
             }
         }
         $expire = empty($cookieData[4]) ? null : $cookieData[4];
         if (preg_match('#^[0-9]+$#i', $expire)) {
             $expire = new DateTime(date('Y-m-d H:i:s', (int) $expire));
         }
         $cookies->add((new Cookie())->setDomain($cookieData[0])->setHttpOnly($httpOnly)->setFlag(strtolower($cookieData[1]) === 'true')->setPath($cookieData[2])->setSecure(strtolower($cookieData[3]) === 'true')->setExpire($expire)->setName($cookieData[5])->setValue($cookieData[6]));
     }
     return $cookies;
 }
 public function testToArrayAndJson()
 {
     $cookie1 = (new Cookie())->setDomain('domain1.dev')->setName('cookie1')->setValue('bar');
     $cookie2 = (new Cookie())->setDomain('domain1.dev')->setName('cookie2')->setValue('bar');
     $cookie3 = (new Cookie())->setDomain('domain2.dev')->setName('cookie1')->setValue('baz');
     $cookieCollection = new CookieCollection([$cookie1, $cookie2, $cookie3]);
     $collectionToArray = $cookieCollection->toArray();
     $this->assertArrayHasKey($cookie1->getDomain(), $collectionToArray);
     $this->assertArrayHasKey($cookie3->getDomain(), $collectionToArray);
     $this->assertEquals(8, count($collectionToArray[$cookie1->getDomain()][$cookie1->getName()]));
     $this->assertEquals(8, count($collectionToArray[$cookie1->getDomain()][$cookie2->getName()]));
     $this->assertEquals(8, count($collectionToArray[$cookie3->getDomain()][$cookie3->getName()]));
     $this->assertEquals(json_encode($collectionToArray), json_encode($cookieCollection));
 }
 /**
  * @param string|null $domain
  *
  * @return CookieCollectionInterface
  */
 public function getAll(string $domain = null) : CookieCollectionInterface
 {
     if ($domain === null) {
         return $this;
     } else {
         $collection = new CookieCollection();
         if (isset($this->cookies[$domain])) {
             foreach ($this->cookies[$domain] as $cookie) {
                 $collection->add($cookie);
             }
         }
         return $collection;
     }
 }