1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20:
21: 22: 23: 24: 25: 26: 27: 28: 29:
30: abstract class LoggerConfigurable {
31:
32:
33: protected function setBoolean($property, $value) {
34: try {
35: $this->$property = LoggerOptionConverter::toBooleanEx($value);
36: } catch (Exception $ex) {
37: $value = var_export($value, true);
38: $this->warn("Invalid value given for '$property' property: [$value]. Expected a boolean value. Property not changed.");
39: }
40: }
41:
42:
43: protected function setInteger($property, $value) {
44: try {
45: $this->$property = LoggerOptionConverter::toIntegerEx($value);
46: } catch (Exception $ex) {
47: $value = var_export($value, true);
48: $this->warn("Invalid value given for '$property' property: [$value]. Expected an integer. Property not changed.");
49: }
50: }
51:
52:
53: protected function setLevel($property, $value) {
54: try {
55: $this->$property = LoggerOptionConverter::toLevelEx($value);
56: } catch (Exception $ex) {
57: $value = var_export($value, true);
58: $this->warn("Invalid value given for '$property' property: [$value]. Expected a level value. Property not changed.");
59: }
60: }
61:
62:
63: protected function setPositiveInteger($property, $value) {
64: try {
65: $this->$property = LoggerOptionConverter::toPositiveIntegerEx($value);
66: } catch (Exception $ex) {
67: $value = var_export($value, true);
68: $this->warn("Invalid value given for '$property' property: [$value]. Expected a positive integer. Property not changed.");
69: }
70: }
71:
72:
73: protected function setFileSize($property, $value) {
74: try {
75: $this->$property = LoggerOptionConverter::toFileSizeEx($value);
76: } catch (Exception $ex) {
77: $value = var_export($value, true);
78: $this->warn("Invalid value given for '$property' property: [$value]. Expected a file size value. Property not changed.");
79: }
80: }
81:
82:
83: protected function setNumeric($property, $value) {
84: try {
85: $this->$property = LoggerOptionConverter::toNumericEx($value);
86: } catch (Exception $ex) {
87: $value = var_export($value, true);
88: $this->warn("Invalid value given for '$property' property: [$value]. Expected a number. Property not changed.");
89: }
90: }
91:
92:
93: protected function setString($property, $value, $nullable = false) {
94: if ($value === null) {
95: if($nullable) {
96: $this->$property= null;
97: } else {
98: $this->warn("Null value given for '$property' property. Expected a string. Property not changed.");
99: }
100: } else {
101: try {
102: $value = LoggerOptionConverter::toStringEx($value);
103: $this->$property = LoggerOptionConverter::substConstants($value);
104: } catch (Exception $ex) {
105: $value = var_export($value, true);
106: $this->warn("Invalid value given for '$property' property: [$value]. Expected a string. Property not changed.");
107: }
108: }
109: }
110:
111:
112: protected function warn($message) {
113: $class = get_class($this);
114: trigger_error("log4php: $class: $message", E_USER_WARNING);
115: }
116: }
117: