Ejemplo n.º 1
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");
 }
Ejemplo n.º 2
0
 /**
  * Empties Request Cookies
  *
  * @return Next\HTTP\Cookies
  *   Cookies Object (Fluent Interface)
  */
 public function clearCookies()
 {
     $this->cookies->clear();
     return $this;
 }