Exemplo n.º 1
0
 function test_ResponsePermanentRedirect()
 {
     $response = new Oops_Server_Response();
     $response->redirect('http://www.somewhere.com/', true, true);
     $this->assertTrue($response->isRedirect());
     $this->assertEquals(301, $response->code);
     $this->assertTrue($response->isReady());
 }
Exemplo n.º 2
0
 /**
  * Parses URI into parts, action and extension, also checks spelling using
  * 301 to the right location
  */
 protected function _parseRequest()
 {
     $oopsConfig = $this->_config->oops;
     $parts = explode("/", $this->_request->path);
     $coolparts = array();
     // Let's remove any empty parts. path//to/something/ should be turned
     // into path/to/something
     for ($i = 0, $cnt = count($parts); $i < $cnt; $i++) {
         if (strlen($parts[$i])) {
             $coolparts[] = (string) $oopsConfig->request_anycase ? $parts[$i] : strtolower($parts[$i]);
         }
     }
     if (($cnt = count($coolparts)) != 0) {
         $last = $coolparts[$cnt - 1];
         if (($dotpos = strrpos($last, '.')) !== FALSE) {
             $ext = substr($last, $dotpos + 1);
             if (Oops_Server_View::isValidView($ext) || $oopsConfig->strict_views) {
                 $this->_action = substr($last, 0, $dotpos);
                 $this->_extension = $ext;
                 array_pop($coolparts);
             }
         }
     }
     if (!isset($this->_action)) {
         // action should be index, content-type - php
         $this->_action = $oopsConfig->default_action;
         $this->_extension = $oopsConfig->default_extension;
     }
     // Let's compile the one-and-only expected request_uri for this kind of
     // request
     $expectedPath = sizeof($coolparts) ? '/' . join('/', $coolparts) . '/' : '/';
     if ($this->_action != $oopsConfig->get('default_action') || $this->_extension != $oopsConfig->get('default_extension')) {
         $expectedPath .= "{$this->_action}.{$this->_extension}";
     }
     // If given path mismatch the one-and-only expected one, make a redirect
     // to the expected
     if ($this->_request->path != $expectedPath) {
         $correctRequest = clone $this->_request;
         $correctRequest->path = $expectedPath;
         $this->_response->redirect($correctRequest->getUrl(), true);
         return;
     }
     $this->_uri_parts = $coolparts;
 }