Ejemplo n.º 1
0
function pie_init()
{
    //Db::connect('users')->generateModels(PIE_DIR.DS.'plugins'.DS.'users'.DS.'classes');
    //Db::connect('games')->generateModels(PIE_DIR.DS.'plugins'.DS.'games'.DS.'classes');
    Pie::log('To stop logging database queries, change pie/init.php');
    Pie_Config::set('pie', 'handlersBeforeEvent', 'db/query/execute', 'temp_query');
}
Ejemplo n.º 2
0
 static function execute()
 {
     // Fixes for different platforms:
     if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
         // ISAPI 3.0
         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
     }
     // Define a constant
     if (!defined('PIE_CONTROLLER')) {
         define('PIE_CONTROLLER', 'Pie_WebController');
     }
     try {
         Pie::log("Request for " . Pie_Request::url(true));
         Pie_Dispatcher::dispatch();
         $dispatch_result = Pie_Dispatcher::result();
         if (!isset($dispatch_result)) {
             $dispatch_result = 'Ran dispatcher';
         }
         $uri = Pie_Dispatcher::uri();
         $module = $uri->module;
         $action = $uri->action;
         if ($module and $action) {
             $slot_names = Pie_Request::slotNames();
             $requested_slots = empty($slot_names) ? '' : implode(',', array_keys($slot_names));
             Pie::log("~" . ceil(Pie::microtime()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " {$dispatch_result} for {$module}/{$action}" . " ({$requested_slots})");
         } else {
             Pie::log("~" . ceil(Pie::microtime()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " No route for " . $_SERVER['REQUEST_URI']);
         }
     } catch (Exception $exception) {
         Pie::event('pie/exception', compact('exception'));
     }
 }
Ejemplo n.º 3
0
 static function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
 {
     switch ($errno) {
         case E_USER_NOTICE:
             Pie::log($errstr);
             break;
         default:
             self::event('pie/error', compact('errno', 'errstr', 'errfile', 'errline', 'errcontext'));
             break;
     }
 }
Ejemplo n.º 4
0
 static function execute()
 {
     // Fixes for different platforms:
     if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
         // ISAPI 3.0
         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
     }
     // Define a constant
     if (!defined('PIE_CONTROLLER')) {
         define('PIE_CONTROLLER', 'Pie_ActionController');
     }
     try {
         $parts = explode('/', Pie_Request::tail());
         $parts_len = count($parts);
         if ($parts_len >= 1) {
             $module = $parts[0];
         }
         if ($parts_len >= 2) {
             $action = $parts[1];
         }
         // Make sure the 'pie'/'web' config fields are set,
         // otherwise URLs will be formed pointing to the wrong
         // controller script.
         $ar = Pie_Config::get('pie', 'web', 'appRootUrl', null);
         if (!isset($ar)) {
             throw new Pie_Exception_MissingConfig(array('fieldpath' => 'pie/web/appRootUrl'));
         }
         $cs = Pie_Config::get('pie', 'web', 'controllerSuffix', null);
         if (!isset($cs)) {
             throw new Pie_Exception_MissingConfig(array('fieldpath' => 'pie/web/controllerSuffix'));
         }
         // Dispatch the request
         $uri = Pie_Uri::from(compact('module', 'action'));
         Pie_Dispatcher::dispatch($uri);
         $dispatch_result = Pie_Dispatcher::result();
         if (!isset($dispatch_result)) {
             $dispatch_result = 'Ran dispatcher';
         }
         $uri = Pie_Dispatcher::uri();
         $module = $uri->module;
         $action = $uri->action;
         if ($module and $action) {
             $slot_names = Pie_Request::slotNames();
             $requested_slots = empty($slot_names) ? '' : implode(',', array_keys($slot_names));
             Pie::log("~" . ceil(Pie::microtime()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " {$dispatch_result} for {$module}/{$action}" . " ({$requested_slots})");
         } else {
             Pie::log("~" . ceil(Pie::microtime()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " No route for " . $_SERVER['REQUEST_URI']);
         }
     } catch (Exception $exception) {
         Pie::event('pie/exception', compact('exception'));
     }
 }
Ejemplo n.º 5
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})");
}