Example #1
0
 public function testFileUrls()
 {
     $testResult = 'file://' . getcwd();
     $url = Url::fromRequest();
     $this->assertEquals($testResult, $url->toString());
     $this->assertEquals(getcwd(), (string) $url);
     $url = Url::fromMagic($testResult);
     $this->assertEquals($testResult, $url->toString());
     $this->assertEquals(getcwd(), (string) $url);
 }
Example #2
0
 /**
  * Redirect
  *
  * This function redirects the client. This is done by issuing
  * a "Location" header and exiting if wanted.  If you set $rfc2616 to true
  * HTTP will output a hypertext note with the location of the redirect.
  *
  * @static
  * @access  public
  * @return  mixed   Returns true on succes (or exits) or false if headers
  *                  have already been sent.
  * @param   string  $url URL where the redirect should go to.
  * @param   bool    $exit Whether to exit immediately after redirection.
  * @param   bool    $rfc2616 Wheter to output a hypertext note where we're
  *                  redirecting to (Redirecting to <a href="...">...</a>.)
  */
 public static function redirect($url, $exit = true, $rfc2616 = false)
 {
     if (headers_sent()) {
         return false;
     }
     $url = \Cx\Core\Routing\Url::fromMagic($url);
     $url = $url->toString();
     // use absolute url
     self::header('Location: ' . $url);
     if ($rfc2616 && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
         printf('Redirecting to: <a href="%s">%s</a>.', $url, $url);
     }
     if ($exit) {
         exit;
     }
     return true;
 }
 /**
  * Resolve
  */
 public function resolve(\Cx\Core\Routing\Url $url, &$continue)
 {
     if (!$this->matches($url)) {
         return $url;
     }
     $continue = $this->getContinueOnMatch();
     $newUrl = \Cx\Core\Routing\Url::fromMagic($this->getRegularExpression()->replace($url->toString()));
     \DBG::log('Redirecting to ' . $newUrl->toString());
     return $newUrl;
 }