Advertisement
Narzew

class.Error.php

Jul 14th, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. <?php
  2.  
  3. #=======================================================================
  4. #**Narzew Script
  5. #**class.Error.php
  6. #**Narzew
  7. #**15.07.2014
  8. #**License: GPL
  9. #=======================================================================
  10. #**This file contains errors interpreting
  11. #=======================================================================
  12. #**PRIVATE VARIABLES: $errors, $error_count
  13. #**STATIC FUNCTIONS:
  14. #**clear - clears the error variables to next use
  15. #**add_error($text) - add an error to $errors variable
  16. #**get_error_count - returns error count
  17. #**get_errors($show_if_zero) - get formated errors string:
  18. #****$show_if_zero(default:false) - show errors if count = 0
  19. #****$print(default:true) - print errors instead of returning
  20. #**has_errors - checks that any errors are added
  21. #=======================================================================
  22.  
  23. class Error {
  24.    
  25.     private static $errors;
  26.     private static $error_count;
  27.  
  28.     static function clear(){
  29.         self::$errors = "";
  30.         self::$error_count = 0;
  31.     }
  32.    
  33.     static function add_error($text){
  34.         self::$errors = self::$errors."<li>".$text."</li>";
  35.         self::$error_count = self::$error_count + 1;
  36.     }
  37.    
  38.     static function get_error_count(){
  39.         return self::$error_count;
  40.     }
  41.    
  42.     static function get_errors($show_if_zero=false,$print=true){
  43.         $tmp_str = "";
  44.         if (self::$error_count == 0){
  45.             if($show_if_zero==true){
  46.                 $tmp_str = "Nie wystąpił żaden błąd";
  47.             } else {
  48.                 if($print == true){
  49.                     echo "";
  50.                 } else {
  51.                     return "";
  52.                 }
  53.             }
  54.         } elseif (self::$error_count == 1){
  55.             $tmp_str = "Wystąpił 1 błąd:\n";
  56.             $tmp_error = self::$error_count;
  57.         } elseif (self::$error_count == 2 || $error_count == 3){
  58.             $tmp_error = self::$error_count;
  59.             $tmp_str = "Wystąpiły $tmp_error  błędy:\n";
  60.         } else {
  61.             $tmp_error = self::$error_count;
  62.             $tmp_str = "Wystąpiło $tmp_error błędów:\n";
  63.         }
  64.         if($tmp_str != ""){
  65.             if($print == true){
  66.                 print $tmp_str.self::$errors;
  67.             } else {
  68.                 return $tmp_str.self::$errors;
  69.             }
  70.         }
  71.     }
  72.    
  73.     static function has_errors(){
  74.         if(self::$error_count == 0){
  75.             return false;
  76.         } else {
  77.             return true;
  78.         }
  79.     }
  80.    
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement