Example #1
0
/**
 * check datetime string if valid. see xapp_is_date for more explanations since
 * the this function does the same only with datetime values
 *
 * @param null|string $datetime expects datetime string to be checked for validity
 * @param bool $strict expects boolean value to check against xapp config datetime format
 * @return bool
 */
function xapp_is_datetime($datetime = null, $strict = false)
{
    if ($datetime !== null) {
        if ((bool) $strict) {
            return (bool) @strptime($datetime, xapp_conf(XAPP_CONF_DATETIME_FORMAT));
        } else {
            return (bool) @strtotime((string) $datetime);
        }
    }
    return false;
}
Example #2
0
 /**
  * xapps php error handling function called be phps native set_error_handler function passes
  * all parameters to class constructor to be send constructed as Xapp_Error instance to be send
  * to error logging or console.
  *
  * @static
  * @error 10507
  * @param int $code expects error code
  * @param string $message expects the error message
  * @param null|string $file expects file name where error occured
  * @param null|int $line expects line number where error occured
  * @return bool false
  * @throws Xapp_Error
  */
 public static function errorHandler($code = 0, $message = "", $file = null, $line = null)
 {
     if ((int) xapp_conf(XAPP_CONF_DEV_MODE) === 2 && stripos($message, 'missing argument') !== false) {
         throw new self($message, E_USER_ERROR, XAPP_ERROR_WARNING);
     } else {
         if ((int) $code == E_RECOVERABLE_ERROR) {
             throw new self($message, E_USER_ERROR, XAPP_ERROR_ERROR);
         } else {
             xapp_error(new self($message, $code, XAPP_ERROR_ERROR, $file, $line));
         }
     }
     return false;
 }
Example #3
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;
 }