Example #1
0
/**
 * The default implementation.
 */
function pie_errors($params)
{
    extract($params);
    /**
     * @var Exception $exception
     */
    if (!empty($exception)) {
        Pie_Response::addError($exception);
        $errors = Pie_Response::getErrors();
    }
    $errors_array = Pie_Exception::toArray($errors);
    $exception_array = Pie_Exception::toArray($exception);
    // Simply return the errors, if this was an AJAX request
    if ($is_ajax = Pie_Request::isAjax()) {
        switch (strtolower($is_ajax)) {
            case 'json':
            default:
                $json = json_encode(array('errors' => $errors_array, 'exception' => $exception_array));
                $callback = Pie_Request::callback();
                echo $callback ? "{$callback}({$json})" : $json;
        }
        return;
    }
    // Forward internally, if it was requested
    if (isset($_REQUEST['_pie']['onErrors'])) {
        $uri = Pie_Dispatcher::uri();
        $uri2 = Pie_Uri::from($_REQUEST['_pie']['onErrors']);
        if ($uri !== $uri2) {
            Pie_Dispatcher::forward($uri2);
            return;
            // we don't really need this, but it's here anyway
        }
    }
    if (Pie::eventStack('pie/response')) {
        // Errors happened while rendering response. Just render errors view.
        return Pie::view('pie/errors.php', $params);
    }
    try {
        // Try rendering the response, expecting it to
        // display the errors along with the rest.
        $ob = new Pie_OutputBuffer();
        Pie::event('pie/response', compact('errors', 'exception', 'errors_array', 'exception_array'));
        $ob->endFlush();
    } catch (Exception $exception) {
        $output = $ob->getClean();
        return Pie::event('pie/exception', compact('exception'));
    }
}
Example #2
0
function pie_exception($params)
{
    extract($params);
    /**
     * @var Exception $exception 
     */
    $message = $exception->getMessage();
    $file = $exception->getFile();
    $line = $exception->getLine();
    if ($is_ajax = Pie_Request::isAjax()) {
        // Render a JSON layout for ajax
        switch (strtolower($is_ajax)) {
            case 'json':
            default:
                $json = json_encode(array('errors' => Pie_Exception::toArray(array($exception))));
                $callback = Pie_Request::callback();
                echo "{$callback}({$json})";
        }
    } else {
        if (is_callable(array($exception, 'getTraceAsStringEx'))) {
            $trace_string = $exception->getTraceAsStringEx();
        } else {
            $trace_string = $exception->getTraceAsString();
        }
        if (Pie::textMode()) {
            $result = "{$message}\n" . "in {$file} ({$line})\n" . $trace_string;
        } else {
            if ($exception instanceof Pie_Exception_PhpError or !empty($exception->messageIsHtml)) {
                // do not sanitize $message
            } else {
                $message = Pie_Html::text($message);
            }
            $result = "<h1>{$message}</h1>" . "<h3>in {$file} ({$line})</h3>" . "<pre>" . $trace_string . "</pre>";
        }
        echo $result;
    }
    $app = Pie_Config::get('pie', 'app', null);
    Pie::log("{$app}: Exception in " . ceil(Pie::microtime()) . "ms\n");
    Pie::log("{$message}\n  in {$file} ({$line})");
}
Example #3
0
<?php

class Pie_Exception_MissingRoute extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_MissingRoute', 'Missing route $route_pattern');
Example #4
0
<?php

class Pie_Exception_RequiredField extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_RequiredField', '$field is required');
Example #5
0
<?php

class Pie_Exception_MissingClass extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_MissingClass', 'Missing class $class_name');
Example #6
0
<?php

class Pie_Exception_MissingObject extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_MissingObject', 'Missing object $name');
Example #7
0
<?php

class Pie_Exception_MissingFunction extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_MissingFunction', 'Missing function $function_name');
Example #8
0
<?php

class Pie_Exception_MissingFile extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_MissingFile', 'Missing file $filename');
Example #9
0
<?php

class Pie_Exception_Recursion extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_Recursion', 'Seems we have runaway recursive calls to $function_name');
Example #10
0
<?php

/**
 * @package users
 */
class Users_Exception_WrongPassword extends Pie_Exception
{
}
Pie_Exception::add('Users_Exception_WrongPassword', 'Wrong password for $identifier');
Example #11
0
<?php

class Pie_Exception_TestCaseFailed extends Pie_Exception_TestCase
{
}
Pie_Exception::add('Pie_Exception_TestCaseFailed', 'failed. $message');
Example #12
0
<?php

class Pie_Exception_WrongType extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_WrongType', '$field is the wrong type, expecting $type.');
Example #13
0
<?php

class Pie_Exception_MissingConfig extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_MissingConfig', 'Missing configuration field $fieldpath');
Example #14
0
<?php

class Pie_Exception_MissingRow extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_MissingRow', 'Missing $table with $criteria');
Example #15
0
<?php

/**
 * @package users
 */
class Users_Exception_AlreadyVerified extends Pie_Exception
{
}
Pie_Exception::add('Users_Exception_AlreadyVerified', '$key has already been verified for another user');
Example #16
0
<?php

class Pie_Exception_TestCaseIncomplete extends Pie_Exception_TestCase
{
}
Pie_Exception::add('Pie_Exception_TestCaseIncomplete', 'incomplete. $message');
Example #17
0
<?php

class Pie_Exception_DbQuery extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_DbQuery', 'DbQuery Exception: $message ... Query was: $sql');
Example #18
0
<?php

class Pie_Exception_TestCaseSkipped extends Pie_Exception_TestCase
{
}
Pie_Exception::add('Pie_Exception_TestCaseSkipped', 'skipped. $message');
Example #19
0
<?php

class Pie_Exception_DispatcherForward extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_DispatcherForward', 'Dispatcher is forwarding to $uri', array('Pie_Dispatcher'));
Example #20
0
<?php

/**
 * @package users
 */
class Users_Exception_NotLoggedIn extends Pie_Exception
{
}
Pie_Exception::add('Users_Exception_NotLoggedIn', 'You are not logged in.');
Example #21
0
<?php

class Pie_Exception_MissingPlugin extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_MissingPlugin', 'Missing plugin $plugin');
Example #22
0
<?php

class Pie_Exception_BadUrl extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_BadUrl', 'Bad url $url (the base url is $base_url)');
Example #23
0
<?php

class Pie_Exception_InvalidInput extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_InvalidInput', 'Invalid input encountered in $source');
Example #24
0
 function getTraceAsStringEx()
 {
     $str = parent::getTraceAsString();
     return implode("\n", array_slice(explode("\n", $str), 4));
 }
Example #25
0
<?php

class Pie_Exception_DispatcherErrors extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_DispatcherErrors', 'Dispatcher is displaying errors', array('Pie_Dispatcher'));
Example #26
0
<?php

abstract class Pie_Exception_TestCase extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_TestCase', 'test case exception: $message');
Example #27
0
<?php

/**
 * @package users
 */
class Users_Exception_WrongState extends Pie_Exception
{
}
Pie_Exception::add('Users_Exception_WrongState', '$key is $state');
Example #28
0
<?php

class Pie_Exception_NotArray extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_NotArray', 'Value under $keys is not an array');
Example #29
0
<?php

/**
 * @package users
 */
class Users_Exception_UsernameExists extends Pie_Exception
{
}
Pie_Exception::add('Users_Exception_UsernameExists', 'Someone else has that username');
Example #30
0
<?php

class Pie_Exception_WrongValue extends Pie_Exception
{
}
Pie_Exception::add('Pie_Exception_WrongValue', '$field: expecting $range');