Example #1
0
 /**
  * Redirects a response to another location
  * 
  * @access public
  * @param string $uri Either a full or partial URI
  * @param string $status Status code to issue prior to redirecting, typically 302
  * @param boolean $die Flag that tells the method whether to issue a die() after the redirect
  * @return void
  */
 public function redirect($uri, $status = '302', $die = true)
 {
     /**
      * Get the registry object setup
      */
     require_once 'Registry.php';
     $registry = Spark_Registry::getInstance();
     // If this is a full URL use it as is except clean up the string
     if (strpos($uri, '://') !== false) {
         $href = str_replace(array("\r", "\n"), '', $uri);
     } else {
         /**
          * We only need one request object, so if it is already set get it, 
          * otherwise, get the one that is set.
          */
         if ($registry->has('_request')) {
             $request = $registry->get('_request');
         } else {
             require_once 'Request.php';
             $request = Spark_Request::getInstance();
             $registry->set('_request', $request);
         }
         $href = $request->uri('url') . '/' . $uri;
     }
     // Clear out the output buffer
     while (@ob_end_clean()) {
     }
     // Save the session if there is one to save
     $registry->get('_session')->__destruct();
     // Set the redirect status code
     $this->setStatusCode($status);
     // Set the location header
     $this->setHeader('Location', $href);
     // Set the body to nothing
     $this->body = null;
     // Send the headers and return the content of the body
     $this->send();
     // if we are on autodie kill it here
     if ($die) {
         die;
     }
 }
Example #2
0
 /**
  * Gets the singleton instance for this object
  * 
  * @access public
  * @static
  * @return Spark_Request
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }