Пример #1
0
 private static function shouldAdd($one, $two = false, $three = false, $four = false, $five = false)
 {
     //Controller not initiated yet.
     if (!Controller::getInit()) {
         return false;
     }
     //Some low level utilities only checks if the class exists, not if it is active
     if (!Component::isActive('BackendError')) {
         return false;
     }
     //Busy with something?
     if (self::$adding) {
         if (Controller::$debug) {
             var_dump($one, $two, $three, $four, $five);
             print_stacktrace();
             die('Recursive Backend Errors');
         }
         return false;
     }
     //Probably addBE
     if (!is_string($three) || !file_exists($three)) {
         return true;
     }
     if (Controller::$mode == Controller::MODE_EXECUTE) {
         //Check if the error originated in our realm
         if (stripos(BACKEND_FOLDER, $three) === false && stripos(APP_FOLDER, $three) === false && stripos(WEB_FOLDER, $three) === false && (!defined('SITE_FOLDER') || stripos(SITE_FOLDER, $three) === false)) {
             return false;
         }
     }
     return true;
 }
Пример #2
0
/**
 * Check if the memory is within a certain range of the memory limit. End the script if it's too high.
 */
function check_memory_limit($range = 512, $log = false, $user_message = false, $die = false)
{
    $usage = memory_get_usage(true);
    $limit = return_bytes(ini_get('memory_limit'));
    if ($log) {
        $message = 'Memory Used: ' . $usage / 1024 / 1024 . 'MB / ' . $limit / 1024 / 1024;
        if (!empty($user_message)) {
            $message .= ' <-> ' . $user_message;
        }
        if (is_callable($log)) {
            call_user_func($log, $message);
        } else {
            echo $message . '<br>';
        }
    }
    if ($limit > 0 && $usage > $limit - 1024 * $range) {
        if ($log) {
            $message = 'Running out of memory.';
            if (is_callable($log)) {
                call_user_func($log, $message);
            } else {
                echo $message . '<br>';
            }
        }
        if ($die) {
            $message = 'Aborting Process.';
            if (is_callable($log)) {
                call_user_func($log, $message);
            } else {
                echo $message . '<br>';
            }
            print_stacktrace();
            die(__FILE__ . ', ' . __LINE__);
        }
        return true;
    }
    return false;
}
Пример #3
0
 public static function getTable($table)
 {
     if ($table instanceof DBObject) {
         $table = $table->getSource();
     } else {
         if ($table instanceof Query) {
             //Dont enclose
             return $table->table;
         } else {
             if (is_array($table)) {
                 $tables = array();
                 foreach ($table as $one_table) {
                     $tables[] = self::getTable($one_table);
                 }
                 //Dont enclose
                 return implode(', ', $tables);
             } else {
                 if ($components = Component::getActive()) {
                     if (substr($table, -3) == 'Obj') {
                         $table = substr($table, 0, strlen($table) - 3);
                     }
                     $name = $table . 'Obj';
                     if (class_exists($name, true)) {
                         $table = new $name();
                         $table = $table->getSource();
                     }
                 }
             }
         }
     }
     if (empty($table)) {
         print_stacktrace();
         die;
         throw new Exception('Empty Table for Query');
     }
     return self::enclose($table);
 }
Пример #4
0
 public function __toString()
 {
     $class = get_called_class();
     if (!$class) {
         print_stacktrace();
         return '(Unknown)';
     }
     return $class;
 }
Пример #5
0
 public static function whoops($title = 'Whoops!', $extra = 'Looks like something went wrong...')
 {
     self::$whoopsed = true;
     if (is_array($extra)) {
         $code_hint = array_key_exists('code_hint', $extra) ? $extra['code_hint'] : false;
         $message = array_key_exists('message', $extra) ? $extra['message'] : false;
     } else {
         if (is_numeric($extra)) {
             $code_hint = $extra;
             $message = 'Looks like something went wrong...';
         } else {
             $code_hint = false;
             $message = $extra;
         }
     }
     if (Component::isActive('BackendError')) {
         BackendError::add($title, $message);
     }
     if (is_callable(array(self::$view, 'whoops'))) {
         call_user_func_array(array(self::$view, 'whoops'), array($title, $message, $code_hint));
     } else {
         if (self::$view instanceof View) {
             self::$view->whoops($title, $message, $code_hint);
         }
     }
     if (array_key_exists('debug', self::$query_vars)) {
         var_dump($title, $message);
         print_stacktrace();
     }
 }