Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Changed error handling in areas.

* Changed the redirect method to not prepend protocol/hostname/port to the passed url.

Signed-off-by: Jonathan Hedrén <jonathan.hedren@gmail.com>
  • Loading branch information...
commit 86e4242fcf158b6575b3e4b57570b23e2d4fad8f 2 parents 766449a + 5c75268
@jonathanhedren authored
Showing with 41 additions and 34 deletions.
  1. +41 −34 Diesel/Diesel.php
View
75 Diesel/Diesel.php
@@ -390,13 +390,33 @@ private function dispatch()
$nonAreaHelpers = $this->helpers;
$callback();
-
- $this->matchRoute($httpMethod, $pathSegmentsCopy);
+
+ try
+ {
+ $this->matchRoute($httpMethod, $pathSegmentsCopy);
+ }
+ catch(\Exception $e)
+ {
+ // If no onError callback is registered in the area, "reset" everything
+ // and let the global onError callback handle the error.
+ if (!count($this->events['onError']))
+ {
+ $this->routes = $nonAreaRoutes;
+ $this->events = $nonAreaEvents;
+ $this->settings = $nonAreaSettings;
+ $this->helpers = $nonAreaHelpers;
+ }
+
+ $this->handleError($e);
+
+ $this->halted = true;
+ }
$this->routes = $nonAreaRoutes;
$this->events = $nonAreaEvents;
$this->settings = $nonAreaSettings;
$this->helpers = $nonAreaHelpers;
+
break;
}
}
@@ -405,20 +425,25 @@ private function dispatch()
}
catch (Exception $e)
{
- if ($this->settings['throwExceptions'])
- {
- throw $e;
- }
- else
- {
- $this->response->setStatus(500);
- $this->dispatchEvent('onError', $e);
- }
+ $this->handleError($e);
}
$this->response->send();
}
-
+
+ private function handleError(\Exception $e)
+ {
+ if ($this->settings['throwExceptions'])
+ {
+ throw $e;
+ }
+ else
+ {
+ $this->response->setStatus(500);
+ $this->dispatchEvent('onError', $e);
+ }
+ }
+
/**
*
* @param type $httpMethod
@@ -699,29 +724,11 @@ public static function redirect($url, $status = 302)
{
self::halt();
- if (!preg_match('#^(https?)://#', $url))
+ // If the redirect URL doesn't start with a /, we assume that it is
+ // a 'relative' redirect and therefore prepend the application path.
+ if (strpos($url, '/') !== 0 && !preg_match('#^(https?)://#', $url))
{
- $request = self::instance()->request;
-
- $host = (string) $request->getHost();
- $protocol = $request->getProtocol();
- $port = $request->getPort();
- $uri = $protocol . '://' . $host;
-
- if (('http' == $protocol && 80 != $port)
- || ('https' == $protocol && 443 != $port))
- {
- $uri .= ':' . $port;
- }
-
- // If the redirect URL doesn't start with a /, we assume that it is
- // a 'relative' redirect and therefore prepend the application path.
- if (strpos($url, '/') !== 0)
- {
- $url = $request->getApplicationPath() . '/' . $url;
- }
-
- $url = $uri . '/' . ltrim($url, '/');
+ $url = self::instance()->request->getApplicationPath() . '/' . $url;
}
self::instance()->response->setStatus($status)
Please sign in to comment.
Something went wrong with that request. Please try again.