Esempio n. 1
0
 /**
  * constructor initializes options and registers profile listeners according
  * to the set options
  *
  * @error 15201
  * @param null|mixed $options expects optional options
  */
 public function __construct($options = null)
 {
     xapp_init_options($options, $this);
     if (xapp_is_option(self::PROFILE_SQL, $this)) {
         Xapp_Event::listen('xapp.orm.query', function ($sql, $params, $time) {
             foreach ($params as $p) {
                 $sql = preg_replace('/\\?/i', Xapp_Orm::quote($p), $sql, 1);
                 $sql = htmlspecialchars($sql);
             }
             xapp_profile('query', $sql, $time);
         });
     }
     if (xapp_is_option(self::PROFILE_ERROR, $this)) {
         Xapp_Event::listen('xapp.error', function ($e) {
             xapp_profile('error', $e);
         });
     }
     if (xapp_get_option(self::MODE, $this) === 1 || xapp_get_option(self::MODE, $this) === true) {
         Xapp_Event::listen('xapp.shutdown', function () {
             xapp_profile(false);
         });
     }
 }
Esempio n. 2
0
 /**
  * xapp error shortcut function used system wide to redirect errors back to xapp base class if xapp base class is used.
  * this function can be easily overwritten to handle errors thrown by exceptions and internal php errors channeled
  * through xapps internal error handler defined in XAPP_CONF_HANDLE_ERROR. use the the this function in all derived
  * exception classes inheriting from phps native ErrorException class in constructor - see Xapp_Error for example. when
  * implementing your own error handler you can bounce back your errors to this function or overwrite it. if xapp base
  * class is not used with direct error to default error handling defined either via phps set_error_handler function
  * or error_log function and triggered by phps trigger_error function. this functions expects exception as well as
  * errors passed as it there where an exception but only for logging purpose or even act as set_error_handler if needed.
  * when redirecting all errors to console you must load and enable Xapp_Console by defining an external console driver
  * like "firephp" and define XAPP_CONF_HANDLE_ERROR with value "console".
  *
  * overwrite like:
  * <code>
  *      function xapp_error($e, $c = 0, $s = 0, $f = null, $l = null)
  *      {
  *          //your custom code here
  *      }
  * </code>
  *
  * @param   string|Exception|Xapp_Error|array $e expects either string error message, instance of Exception or array
  *          return from phps native function error_get_last
  * @param   int $c expects optional error code
  * @param   int $s expects optional severity
  * @param   null|string $f expects the file where error occurred
  * @param   null|int $l expects the line where error occurred
  * @return  boolean|Xapp_Error returns Xapp_Error instance or false as deault
  */
 function xapp_error($e, $c = 0, $s = XAPP_ERROR_ERROR, $f = null, $l = null)
 {
     if (xapped()) {
         xapp_event('xapp.error', array($e));
         //redirect all errors to console
         if (xapped('Xapp_Console') && (bool) xapp_conf(XAPP_CONF_CONSOLE) && strtolower((string) xapp_conf(XAPP_CONF_HANDLE_ERROR) === 'console')) {
             if ($e instanceof Exception) {
                 xapp_console($e, $e->getMessage(), 'error');
             } else {
                 if (is_array($e) && isset($e['message'])) {
                     xapp_console($e, $e['message'], 'error');
                 } else {
                     $std = new stdClass();
                     $std->message = (string) $e;
                     $std->code = (int) $c;
                     $std->severity = (int) $s;
                     $std->file = (string) $f;
                     $std->line = (int) $l;
                     xapp_console($std, $std->message, 'error');
                 }
             }
             //redirect all error to xapp error handling
         } else {
             if ($e instanceof Xapp_Error) {
                 //do nothing because all has been done already since instance of Xapp_Error can only exists after constructor has
                 //been called and with calling parent constructor and stacking the error all has been done!
             } else {
                 if ($e instanceof Exception) {
                     return Xapp::e($e, (int) $c, (int) $s, $f, $l);
                 } else {
                     if (is_array($e) && isset($e['message'])) {
                         return Xapp::e($e['message'], (int) $e['type'], XAPP_ERROR_ERROR, $e['file'], $e['line']);
                     } else {
                         return Xapp::e((string) $e, (int) $c, (int) $s, $f, $l);
                     }
                 }
             }
         }
     } else {
         xapp_profile('error', $e);
         trigger_error((string) $e, E_USER_ERROR);
     }
     return false;
 }