Beispiel #1
0
 /**
  * Redirect
  *
  * This method prepares the response object to return an HTTP Redirect response
  * to the client.
  *
  * @param string $url    The redirect destination
  * @param int    $status The redirect HTTP status code
  * @api
  */
 public function redirect($url, $status = 302)
 {
     $this->setStatus($status);
     $this->headers->set('Location', $url);
 }
Beispiel #2
0
 /**
  * Delete HTTP cookie header
  *
  * This method will construct and set the HTTP `Set-Cookie` header to invalidate
  * a client-side HTTP cookie. If a cookie with the same name (and, optionally, domain)
  * is already set in the HTTP response, it will also be removed. Slim uses this method
  * instead of PHP's native `setcookie` method. This allows more control of the HTTP header
  * irrespective of PHP's native implementation's dependency on PHP versions.
  *
  * This method accepts the \Slim\Http\Headers object by reference as its
  * first argument; this method directly modifies this object instead of
  * returning a value.
  *
  * @param \Slim\Interfaces\Http\HeadersInterface $headers
  * @param string                                 $name
  * @param array                                  $value
  * @api
  */
 public function deleteHeader(HeadersInterface &$headers, $name, $value = array())
 {
     $crumbs = $headers->has('Set-Cookie') ? explode("\n", $headers->get('Set-Cookie')) : array();
     $cookies = array();
     foreach ($crumbs as $crumb) {
         if (isset($value['domain']) && $value['domain']) {
             $regex = sprintf('@%s=.*domain=%s@', urlencode($name), preg_quote($value['domain']));
         } else {
             $regex = sprintf('@%s=@', urlencode($name));
         }
         if (preg_match($regex, $crumb) === 0) {
             $cookies[] = $crumb;
         }
     }
     if (!empty($cookies)) {
         $headers->set('Set-Cookie', implode("\n", $cookies));
     } else {
         $headers->remove('Set-Cookie');
     }
     $this->setHeader($headers, $name, array_merge(array('value' => '', 'path' => null, 'domain' => null, 'expires' => time() - 100), $value));
 }
 /**
  * Retrieves a comma-separated string of the values for a single header.
  *
  * This method returns all of the header values of the given
  * case-insensitive header name as a string concatenated together using
  * a comma.
  *
  * NOTE: Not all header values may be appropriately represented using
  * comma concatenation. For such headers, use getHeader() instead
  * and supply your own delimiter when concatenating.
  *
  * If the header does not appear in the message, this method MUST return
  * an empty string.
  *
  * @param string $name Case-insensitive header field name.
  * @return string A string of values as provided for the given header
  *    concatenated together using a comma. If the header does not appear in
  *    the message, this method MUST return an empty string.
  */
 public function getHeaderLine($name)
 {
     return implode(',', $this->headers->get($name, []));
 }
Beispiel #4
0
 /**
  * Get User Agent
  *
  * @return string|null
  * @api
  */
 public function getUserAgent()
 {
     return $this->headers->get('HTTP_USER_AGENT');
 }