1: <?php
2: /**
3: * This is the Base Class for ALL classes in the system. It provides
4: * proper error handling of property getters and setters. It also
5: * provides the OverrideAttribute functionality.
6: */
7: abstract class QBaseClass {
8: /**
9: * Override method to perform a property "Get"
10: * This will get the value of $strName
11: * All inhereted objects that call __get() should always fall through
12: * to calling parent::__get() in a try/catch statement catching
13: * for CallerExceptions.
14: *
15: * @param string $strName Name of the property to get
16: *
17: * @throws QUndefinedPropertyException
18: * @return mixed the returned property
19: */
20: public function __get($strName) {
21: $objReflection = new ReflectionClass($this);
22: throw new QUndefinedPropertyException("GET", $objReflection->getName(), $strName);
23: }
24:
25: /**
26: * Override method to perform a property "Set"
27: * This will set the property $strName to be $mixValue
28: * All inhereted objects that call __set() should always fall through
29: * to calling parent::__set() in a try/catch statement catching
30: * for CallerExceptions.
31: *
32: * @param string $strName Name of the property to set
33: * @param string $mixValue New value of the property
34: *
35: * @throws QUndefinedPropertyException
36: * @return mixed the property that was set
37: */
38: public function __set($strName, $mixValue) {
39: $objReflection = new ReflectionClass($this);
40: throw new QUndefinedPropertyException("SET", $objReflection->getName(), $strName);
41: }
42:
43: public function __call($strName, $arguments)
44: {
45: $objReflection = new ReflectionClass($this);
46: throw new QUndefinedMethodException($objReflection->getName(), $strName);
47: }
48:
49:
50: /**
51: * This allows you to set any properties, given by a name-value pair list
52: * in mixOverrideArray.
53: * Each item in mixOverrideArray needs to be either a string in the format
54: * of Property=Value or an array in the format of array(Property => Value).
55: * OverrideAttributes() will basically call
56: * $this->Property = Value for each string element in the array.
57: * Value can be surrounded by quotes... but this is optional.
58: *
59: * @param $mixOverrideArray
60: *
61: * @throws QCallerException
62: * @throws Exception|QCallerException
63: * @return void
64: */
65: public final function OverrideAttributes($mixOverrideArray) {
66: // Iterate through the OverrideAttribute Array
67: if ($mixOverrideArray) foreach ($mixOverrideArray as $mixOverrideItem) {
68: if (is_array($mixOverrideItem)) {
69: foreach ($mixOverrideItem as $strKey=>$mixValue)
70: // Apply the override
71: try {
72: $this->__set($strKey, $mixValue);
73: } catch (QCallerException $objExc) {
74: $objExc->IncrementOffset();
75: throw $objExc;
76: }
77: } else {
78: // Extract the Key and Value for this OverrideAttribute
79: $intPosition = strpos($mixOverrideItem, "=");
80: if ($intPosition === false)
81: throw new QCallerException(sprintf("Improperly formatted OverrideAttribute: %s", $mixOverrideItem));
82: $strKey = substr($mixOverrideItem, 0, $intPosition);
83: $mixValue = substr($mixOverrideItem, $intPosition + 1);
84:
85: // Ensure that the Value is properly formatted (unquoted, single-quoted, or double-quoted)
86: if (substr($mixValue, 0, 1) == "'") {
87: if (substr($mixValue, strlen($mixValue) - 1) != "'")
88: throw new QCallerException(sprintf("Improperly formatted OverrideAttribute: %s", $mixOverrideItem));
89: $mixValue = substr($mixValue, 1, strlen($mixValue) - 2);
90: } else if (substr($mixValue, 0, 1) == '"') {
91: if (substr($mixValue, strlen($mixValue) - 1) != '"')
92: throw new QCallerException(sprintf("Improperly formatted OverrideAttribute: %s", $mixOverrideItem));
93: $mixValue = substr($mixValue, 1, strlen($mixValue) - 2);
94: }
95:
96: // Apply the override
97: try {
98: $this->__set($strKey, $mixValue);
99: } catch (QCallerException $objExc) {
100: $objExc->IncrementOffset();
101: throw $objExc;
102: }
103: }
104: }
105: }
106: }