Guest User

Untitled

a guest
Nov 9th, 2011
104
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.  * A base class from which all classes which have configurable properties are
  5.  * extended. Provides a generic setter with integrated validation.  
  6.  */
  7. abstract class LoggerBase {
  8.    
  9.     /** Setter function for boolean type. */
  10.     protected function setBoolean($property, $value)
  11.     {
  12.         try {
  13.             $this->$property = LoggerOptionConverter::toBooleanEx($value);
  14.         } catch (Exception $ex) {
  15.             $value = var_export($value, true);
  16.             $propValue = var_export($this->$property, true);
  17.             $this->warn("Invalid value given for '$property' property: [$value]. Expected a boolean value. Property not changed, current value: [$propValue].");
  18.         }
  19.     }
  20.    
  21.     /** Setter function for integer type. */
  22.     protected function setInteger($property, $value)
  23.     {
  24.         try {
  25.             $this->$property = LoggerOptionConverter::toIntegerEx($value);
  26.         } catch (Exception $ex) {
  27.             $value = var_export($value, true);
  28.             $propValue = var_export($this->$property, true);
  29.             $this->warn("Invalid value given for '$property' property: [$value]. Expected an integer. Property not changed, current value: [$propValue].");
  30.         }
  31.     }
  32.    
  33.     /** Setter function for numeric type. */
  34.     protected function setNumeric($property, $value)
  35.     {
  36.         try {
  37.             $this->$property = LoggerOptionConverter::toNumericEx($value);
  38.         } catch (Exception $ex) {
  39.             $value = var_export($value, true);
  40.             $propValue = var_export($this->$property, true);
  41.             $this->warn("Invalid value given for '$property' property: [$value]. Expected a number. Property not changed, current value: [$propValue].");
  42.         }
  43.     }
  44.    
  45.     /** Setter function for string type. */
  46.     protected function setString($property, $value)
  47.     {
  48.         try {
  49.             $this->$property = LoggerOptionConverter::toStringEx($value);
  50.         } catch (Exception $ex) {
  51.             $value = var_export($value, true);
  52.             $propValue = var_export($this->$property, true);
  53.             $this->warn("Invalid value given for '$property' property: [$value]. Expected a string. Property not changed, current value: [$propValue].");
  54.         }
  55.     }
  56.    
  57.     /** Triggers a warning. */
  58.     protected function warn($message)
  59.     {
  60.         $class = get_class($this);
  61.         trigger_error("log4php: $class: $message", E_USER_WARNING);
  62.     }
  63. }
  64.  
  65.  
  66.  
  67. ?>
  68.  
  69.  
Advertisement
Add Comment
Please, Sign In to add comment