~coughphp/coughphp/2.0

« back to all changes in this revision

Viewing changes to design/RAW Getters & Setters.markdown

  • Committer: Anthony Bush
  • Date: 2008-08-23 03:35:08 UTC
  • mfrom: (262.1.18 coughphp-release-1.3)
  • Revision ID: anthony@anthonybush.com-20080823033508-uy4yn5pmio6wcetv
Accept release-1.3 branch changes into trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
RAW Getters & Setters
3
 
=====================
4
 
 
5
 
Should we have them?
6
 
 
7
 
        /**
8
 
         * Returns the specified object for use (raw get).
9
 
         *
10
 
         * @param $objectName - the name of the object to get
11
 
         * @return CoughObject - the requested object
12
 
         * @author Anthony Bush
13
 
         **/
14
 
        protected function rawGetObject($objectName) {
15
 
                if ( ! $this->isObjectLoaded($objectName)) {
16
 
                        $this->loadObject($objectName);
17
 
                }
18
 
                return $this->objects[$objectName];
19
 
        }
20
 
        
21
 
        /**
22
 
         * Calls the get method for the given object name.
23
 
         *
24
 
         * @return void
25
 
         * @author Anthony Bush
26
 
         **/
27
 
        public function getObject($objectName) {
28
 
                $getMethod = 'get' . self::titleCase($objectName) . '_Object';
29
 
                return $this->$getMethod();
30
 
        }
31
 
        
32
 
        /**
33
 
         * Sets the object reference in memory (raw set).
34
 
         * 
35
 
         * This has no effect on the database. For example:
36
 
         * 
37
 
         *     $order->setCustomer($customer);
38
 
         * 
39
 
         * will not change the customer_id on the order. It is simply a way to pass
40
 
         * in pre-instantiated objects so that they do not have to be looked up in
41
 
         * the database.
42
 
         *
43
 
         * @return void
44
 
         * @author Anthony Bush
45
 
         **/
46
 
        protected function rawSetObject($objectName, $object) {
47
 
                if (isset($this->objectDefinitions[$objectName])) {
48
 
                        $this->objects[$objectName] = $object;
49
 
                }
50
 
        }
51
 
        
52
 
        /**
53
 
         * Calls the set method for the given object name.
54
 
         *
55
 
         * @return void
56
 
         * @author Anthony Bush
57
 
         **/
58
 
        public function setObject($objectName, $object) {
59
 
                $setMethod = 'set' . self::titleCase($objectName) . '_Object';
60
 
                $this->$setMethod($object);
61
 
        }
62
 
        
63
 
        /**
64
 
         * Returns the current value of the requested field name.
65
 
         *
66
 
         * @return mixed
67
 
         **/
68
 
        protected function rawGetField($fieldName) {
69
 
                if (isset($this->fields[$fieldName])) {
70
 
                        return ($this->fields[$fieldName]);
71
 
                } else {
72
 
                        return null;
73
 
                }
74
 
        }
75
 
        
76
 
        /**
77
 
         * Calls the get method for the given field name.
78
 
         *
79
 
         * @return mixed
80
 
         * @author Anthony Bush
81
 
         **/
82
 
        public function getField($fieldName) {
83
 
                $getter = 'get' . self::titleCase($fieldName);
84
 
                return $this->$getter();
85
 
        }
86
 
        
87
 
        /**
88
 
         * Sets the current value of $fieldName to $value.
89
 
         * 
90
 
         * @param string $fieldName
91
 
         * @param mixed $value
92
 
         * @return void
93
 
         **/
94
 
        protected function rawSetField($fieldName, $value) {
95
 
                $this->setModifiedField($fieldName);
96
 
                $this->fields[$fieldName] = $value;
97
 
        }
98
 
        
99
 
        /**
100
 
         * Calls the set method for the given field name.
101
 
         *
102
 
         * @return mixed
103
 
         * @author Anthony Bush
104
 
         **/
105
 
        public function setField($fieldName, $value) {
106
 
                $setter = 'set' . self::titleCase($fieldName);
107
 
                return $this->$setter($value);
108
 
        }
109
 
        
 
 
b'\\ No newline at end of file'