Esempio n. 1
0
 /**
  * Get registered Cookies
  *
  * @param boolean $asString
  *   If TRUE, instead a Collection, a string of all the cookies will be returned
  *
  * @return Next\Components\Iterator\Lists|Next\HTTP\Headers\Fields\Request\Cookie
  *
  *   <p>
  *     If <strong>$asString</strong> is set to FALSE, the Cookies
  *     Lists Collection will be returned
  *   </p>
  *
  *   <p>
  *     If <strong>$asString</strong> is TRUE, a well formed Request
  *     Cookie Header will be returned
  *   </p>
  */
 public function getCookies($asString = FALSE)
 {
     if ($asString === FALSE) {
         return $this->cookies->getCollection();
     }
     // Is there something to return?
     if ($this->cookies->count() == 0) {
         return NULL;
     }
     // Let's return as string
     $cookieString = NULL;
     $iterator = $this->cookies->getIterator();
     iterator_apply($iterator, function (\Iterator $iterator) use(&$cookieString) {
         $cookieString .= sprintf("%s;", $iterator->current()->getValue());
         return TRUE;
     }, array($iterator));
     return new Cookie(rtrim($cookieString, ";"));
 }
Esempio n. 2
0
 /**
  * Get registered Headers
  *
  * @param boolean $asString
  *   If TRUE, instead a Collection, a string of all the headers will be returned
  *
  * @return Next\Components\Iterator\Lists|string|void
  *
  *   <p>
  *       If <strong>$asString</strong> is set to FALSE, the Headers
  *       Lists Collection will be returned
  *   </p>
  *
  *   <p>
  *       If <strong>$asString</strong> argument is set to FALSE, and
  *       no Headers were defined, nothing is returned
  *   </p>
  *
  *   <p>Otherwise, a string with all Headers will be returned</p>
  */
 public function getHeaders($asString = FALSE)
 {
     if ($asString === FALSE) {
         return $this->headers->getCollection();
     }
     // Is there something to return?
     if ($this->headers->count() == 0) {
         return NULL;
     }
     // Let's return as string
     $headerString = NULL;
     $iterator = $this->headers->getIterator();
     iterator_apply($iterator, function (\Iterator $iterator) use(&$headerString) {
         $current = $iterator->current();
         // Generic Headers are a little different
         if ($current instanceof Generic) {
             $headerString .= sprintf("%s\r\n", $current->getValue());
         } else {
             $headerString .= sprintf("%s: %s\r\n", $current->getName(), $current->getValue());
         }
         return TRUE;
     }, array($iterator));
     return rtrim($headerString, "\r\n");
 }