My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
Changes to /trunk/mongodb-morph/src/Morph/PropertySet.php
r98 vs. r144 Compare: vs.  Format:
Revision r144
Go to: 
Project members, sign in to write a code review
/trunk/mongodb-morph/src/Morph/PropertySet.php   r98 /trunk/mongodb-morph/src/Morph/PropertySet.php   r144
1 <?php 1 <?php
2 /** 2 /**
3 * @package Morph 3 * @package Morph
4 * @author Jonathan Moss <xirisr@gmail.com> 4 * @author Jonathan Moss <xirisr@gmail.com>
5 * @copyright Jonathan Moss 2009 5 * @copyright Jonathan Moss 2009
6 */ 6 */
7 7
8 /** 8 /**
9 * Object to represent a set of properties 9 * Object to represent a set of properties
10 * 10 *
11 * @package Morph 11 * @package Morph
12 */ 12 */
13 class Morph_PropertySet extends ArrayObject 13 class Morph_PropertySet extends ArrayObject
14 { 14 {
15 15
16 /** 16 /**
17 * Get the value of the specified property within this set 17 * Get the value of the specified property within this set
18 * 18 *
19 * Returns null if $name does not exist in this set 19 * Returns null if $name does not exist in this set
20 * 20 *
21 * @param $name 21 * @param $name
22 * @return mixed 22 * @return mixed
23 */ 23 */
24 public function getPropertyValue($name) 24 public function getPropertyValue($name)
25 { 25 {
26 $value = null; 26 $value = null;
27 if(isset($this[$name])){ 27 if(isset($this[$name])){
28 $value = $this[$name]->getValue(); 28 $value = $this[$name]->getValue();
29 } 29 }
30 return $value; 30 return $value;
31 } 31 }
32 32
33 /** 33 /**
34 * Sets the value of the specified property 34 * Sets the value of the specified property
35 * 35 *
36 * @param $name 36 * @param $name
37 * @param $value 37 * @param $value
38 */ 38 */
39 public function setPropertyValue($name, $value) 39 public function setPropertyValue($name, $value)
40 { 40 {
41 if(isset($this[$name])){ 41 if(isset($this[$name])){
42 $this[$name]->setValue($value); 42 $this[$name]->setValue($value);
43 } 43 }
44 } 44 }
45 45
46 /** 46 /**
47 * Get the raw value for the specified property 47 * Get the raw value for the specified property
48 * 48 *
49 * returns null if $name is not set 49 * returns null if $name is not set
50 * 50 *
51 * @param $name 51 * @param $name
52 * @return mixed 52 * @return mixed
53 */ 53 */
54 public function __getRawPropertyValue($name) 54 public function __getRawPropertyValue($name)
55 { 55 {
56 $value = null; 56 $value = null;
57 if(isset($this[$name])){ 57 if(isset($this[$name])){
58 $value = $this[$name]->__getRawValue(); 58 $value = $this[$name]->__getRawValue();
59 } 59 }
60 return $value; 60 return $value;
61 } 61 }
62 62
63 /** 63 /**
64 * Sets the raw value of the named property 64 * Sets the raw value of the named property
65 * 65 *
66 * 66 *
67 * @param $name 67 * @param $name
68 * @param $value 68 * @param $value
69 */ 69 */
70 public function __setRawPropertyValue($name, $value) 70 public function __setRawPropertyValue($name, $value)
71 { 71 {
72 if(!isset($this[$name])){ 72 if(!isset($this[$name])){
73 $this[$name] = new Morph_Property_Generic($name); 73 $this[$name] = new Morph_Property_Generic($name);
74 } 74 }
75 $this[$name]->__setRawValue($value); 75 $this[$name]->__setRawValue($value);
76 } 76 }
77 77
78 // ARRAY ACCESS FUNCTIONS 78 // ARRAY ACCESS FUNCTIONS
79 79
80 /** 80 /**
81 * Appends the given $object to the collection 81 * Appends the given $object to the collection
82 * 82 *
83 * This function override the parent append to do type checking 83 * This function override the parent append to do type checking
84 * 84 *
85 */ 85 */
86 public function append($object) 86 public function append($object)
87 { 87 {
88 throw new RuntimeException("Appending to PropertySet is not supported"); 88 throw new RuntimeException("Appending to PropertySet is not supported");
89 } 89 }
90 90
91 /** 91 /**
92 * Sets the given offset to the given $object 92 * Sets the given offset to the given $object
93 * 93 *
94 * This function override the parent offsetSet to do type checking 94 * This function override the parent offsetSet to do type checking
95 * 95 *
96 */ 96 */
97 public function offsetSet($offset, $object) 97 public function offsetSet($offset, $object)
98 { 98 {
99 $this->checkType($object); 99 $this->checkType($object);
100 if (empty($offset)) { 100 if (empty($offset)) {
101 throw new RuntimeException("Unnamed properties are not supported"); 101 throw new RuntimeException("Unnamed properties are not supported");
102 } 102 }
103 return parent::offsetSet($offset, $object); 103 return parent::offsetSet($offset, $object);
104 } 104 }
105 105
106 /** 106 /**
107 * Checks that $object is an instance of Morph_Property_Generic 107 * Checks that $object is an instance of Morph_Property_Generic
108 * 108 *
109 * Throws a RuntimeException if not 109 * Throws a RuntimeException if not
110 * 110 *
111 * @param $object 111 * @param $object
112 */ 112 */
113 private function checkType($object){ 113 private function checkType($object)
114 {
115 if (!is_object($object)) {
116 throw new InvalidArgumentException('value if not and object that extends Morph_Property_Generic');
117 }
118
114 if(!($object instanceof Morph_Property_Generic)){ 119 if(!($object instanceof Morph_Property_Generic)){
115 throw new InvalidArgumentException('object of type' . get_class($object) . ' does not extend Morph_Property_Generic'); 120 throw new InvalidArgumentException('object of type' . get_class($object) . ' does not extend Morph_Property_Generic');
116 } 121 }
117 } 122 }
118 } 123 }
Powered by Google Project Hosting