Skip to content

Commit

Permalink
Exception throwing added to Layout helper. RecessFrameworkException a…
Browse files Browse the repository at this point in the history
…dded for throwing exceptions that occur in user code, not framework code.
  • Loading branch information
KrisJordan committed Apr 15, 2009
1 parent bf2d791 commit fc60e23
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
23 changes: 15 additions & 8 deletions recess/recess/diagnostics/Diagnostics.class.php
Expand Up @@ -18,10 +18,7 @@ public static function handleException(Exception $exception) {

if($exception instanceof LibraryException) {
// Special Case for LibraryException to shift front value from stack
$trace = $exception->getTrace();
if(count($trace) > 0)
array_shift($trace);
$exception = new RecessTraceException($exception->getMessage(), $trace);
$exception = new RecessFrameworkException($exception->getMessage(), 1, $exception->getTrace());
}

if($exception instanceof RecessResponseException) {
Expand Down Expand Up @@ -92,12 +89,22 @@ public function getRecessTrace() {
}
}

class RecessTraceException extends RecessErrorException {
class RecessFrameworkException extends RecessErrorException {
public $trace;

public function __construct($message, $trace = array()) {
parent::__construct($message, 0, 0, isset($trace[0]['file']) ? $trace[0]['file'] : '', isset($trace[0]['line']) ? $trace[0]['line'] : 0, array());
protected $shifts;
public function __construct($message, $shifts = 0, $trace = array()) {
if(empty($trace)) {
$trace = debug_backtrace();
}

while($shifts > 0 && !empty($trace)) {
array_shift($trace);
--$shifts;
}

$this->trace = $trace;

parent::__construct($message, 0, 0, isset($trace[0]['file']) ? $trace[0]['file'] : '', isset($trace[0]['line']) ? $trace[0]['line'] : 0, array());
}

public function getRecessTrace() {
Expand Down
6 changes: 3 additions & 3 deletions recess/recess/diagnostics/output/exception_report.php
Expand Up @@ -130,7 +130,7 @@ function printContext($context) {

<head>
<title>Recess! diagnostics! 500 :(</title>
<script type="text/javascript" src="<?php echo $_ENV['url.content']; ?>js/jquery/jquery-1.2.6.js"></script>
<script type="text/javascript" src="<?php echo $_ENV['url.base']; ?>recess/recess/apps/tools/public/js/jquery/jquery-1.2.6.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.callstackdetails').hide();
Expand All @@ -154,9 +154,9 @@ function printContext($context) {
h3 { font-size: 1.1em; line-height: 1.2em; margin-top: 0; margin-bottom: .1em; text-decoration:underline; font-weight: normal;}
#container { text-align: left; background: #fff; position: relative; margin: 0 .5em; border: 1px solid #039;}
#header { background: #003399; height: 120px; }
#logo { height: 120px; vertical-alignment: center; width: 253px; background: url('<?php echo $_ENV['url.content']; ?>images/recess/RecessDiagnostics.png') left no-repeat; margin-left: 20px; display: block; position: absolute; left: 0; }
#logo { height: 120px; vertical-alignment: center; width: 253px; background: url('<?php echo $_ENV['url.base']; ?>recess/recess/apps/tools/public/images/recess/RecessDiagnostics.png') left no-repeat; margin-left: 20px; display: block; position: absolute; left: 0; }
#logo h1 { visibility: hidden; margin: 0; }
#httpCode { height: 120px; width: 253px; vertical-alignment: center; background: url('<?php echo $_ENV['url.content']; ?>images/recess/500.png') right no-repeat; margin-right: 20px; display:block; position: absolute; right: 0;}
#httpCode { height: 120px; width: 253px; vertical-alignment: center; background: url('<?php echo $_ENV['url.base']; ?>recess/recess/apps/tools/public/images/recess/500.png') right no-repeat; margin-right: 20px; display:block; position: absolute; right: 0;}
#httpCode h2 { visibility: hidden; margin: 0; }
#error { margin: 1em; border: 3px solid #c03; background: #fcc; padding: 1em; }
#error h2 { color: #cc0033; }
Expand Down
12 changes: 6 additions & 6 deletions recess/recess/framework/helpers/Layout.class.php
Expand Up @@ -21,7 +21,7 @@ public static function init(AbstractView $view) {

public static function extend($layout) {
if(!empty(self::$extendStack)) {
die('error: can\'t nest extends');
throw new RecessFrameworkException('Nesting extends is not allowed.', 1);
}

array_push(self::$extendStack, $layout);
Expand All @@ -30,11 +30,11 @@ public static function extend($layout) {

public static function block($title) {
if(empty(self::$extendStack)) {
die('error: not extending');
throw new RecessFrameworkException('Blocks are only valid when extending a layout using Layout::extend()', 1);
}

if(!empty(self::$blockStack)) {
die('error: cant nest blocks');
throw new RecessFrameworkException('Nesting blocks is not allowed. You must end a block with Layout::blockEnd() before starting a new block.', 1);
}

array_push(self::$blockStack, $title);
Expand All @@ -43,7 +43,7 @@ public static function block($title) {

public static function blockEnd() {
if(empty(self::$blockStack)) {
die('not in a block!');
throw new RecessFrameworkException('Block end encountered without a preceding Layout::block() to open the block.', 1);
}

$blockName = array_pop(self::$blockStack);
Expand All @@ -62,7 +62,7 @@ public static function blockAssign($title, $value) {

public static function slot($title) {
if(!empty(self::$slotStack)) {
die('can\'t nest slots');
throw new RecessFrameworkException('Nesting slots is not allowed. You must end a slot with Layout::slotEnd() before starting a new slot.', 1);
}

array_push(self::$slotStack, $title);
Expand All @@ -71,7 +71,7 @@ public static function slot($title) {

public static function slotEnd() {
if(empty(self::$slotStack)) {
die('not in a slot');
throw new RecessFrameworkException('Slot end encountered without a preceding Layout::slot() to open the slot.', 1);
}

$slotName = array_pop(self::$slotStack);
Expand Down

0 comments on commit fc60e23

Please sign in to comment.