Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * A base class from which all classes which have configurable properties are
- * extended. Provides a generic setter with integrated validation.
- */
- abstract class LoggerBase {
- /** Setter function for boolean type. */
- protected function setBoolean($property, $value)
- {
- try {
- $this->$property = LoggerOptionConverter::toBooleanEx($value);
- } catch (Exception $ex) {
- $value = var_export($value, true);
- $propValue = var_export($this->$property, true);
- $this->warn("Invalid value given for '$property' property: [$value]. Expected a boolean value. Property not changed, current value: [$propValue].");
- }
- }
- /** Setter function for integer type. */
- protected function setInteger($property, $value)
- {
- try {
- $this->$property = LoggerOptionConverter::toIntegerEx($value);
- } catch (Exception $ex) {
- $value = var_export($value, true);
- $propValue = var_export($this->$property, true);
- $this->warn("Invalid value given for '$property' property: [$value]. Expected an integer. Property not changed, current value: [$propValue].");
- }
- }
- /** Setter function for numeric type. */
- protected function setNumeric($property, $value)
- {
- try {
- $this->$property = LoggerOptionConverter::toNumericEx($value);
- } catch (Exception $ex) {
- $value = var_export($value, true);
- $propValue = var_export($this->$property, true);
- $this->warn("Invalid value given for '$property' property: [$value]. Expected a number. Property not changed, current value: [$propValue].");
- }
- }
- /** Setter function for string type. */
- protected function setString($property, $value)
- {
- try {
- $this->$property = LoggerOptionConverter::toStringEx($value);
- } catch (Exception $ex) {
- $value = var_export($value, true);
- $propValue = var_export($this->$property, true);
- $this->warn("Invalid value given for '$property' property: [$value]. Expected a string. Property not changed, current value: [$propValue].");
- }
- }
- /** Triggers a warning. */
- protected function warn($message)
- {
- $class = get_class($this);
- trigger_error("log4php: $class: $message", E_USER_WARNING);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment