Changeset 43
- Timestamp:
- 11/21/06 20:45:41 (2 years ago)
- Files:
-
- trunk/XJConf/DefinedTag.php (modified) (1 diff)
- trunk/XJConf/converters/AbstractObjectValueConverter.php (modified) (2 diffs)
- trunk/XJConf/definitions/AttributeDefinition.php (modified) (12 diffs)
- trunk/XJConf/definitions/CDataDefinition.php (modified) (7 diffs)
- trunk/XJConf/definitions/ChildDefinition.php (modified) (5 diffs)
- trunk/XJConf/definitions/ConstructorDefinition.php (modified) (9 diffs)
- trunk/XJConf/definitions/Definition.php (modified) (5 diffs)
- trunk/XJConf/definitions/FactoryMethodDefinition.php (modified) (10 diffs)
- trunk/XJConf/definitions/TagDefinition.php (modified) (14 diffs)
- trunk/examples/Color.php (modified) (10 diffs)
- trunk/examples/DynamicSetterClass.php (added)
- trunk/examples/TestAttributesRequired.php (modified) (4 diffs)
- trunk/examples/TestDynamicSetters.php (added)
- trunk/examples/xml/defines-dynamic-setters.xml (added)
- trunk/examples/xml/test-dynamic-setters.xml (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/XJConf/DefinedTag.php
r14 r43 249 249 public function getSetterMethod() 250 250 { 251 return $this->tagDef->getSetterMethod( );251 return $this->tagDef->getSetterMethod($this); 252 252 } 253 253 trunk/XJConf/converters/AbstractObjectValueConverter.php
r29 r43 23 23 */ 24 24 protected $className; 25 25 26 26 /** 27 27 * Add all attributes using the appropriate setter methods … … 45 45 46 46 try { 47 $method = $class->getMethod($att->getSetterMethod( ));47 $method = $class->getMethod($att->getSetterMethod($tag)); 48 48 $method->invoke($instance, $val); 49 49 } catch (ReflectionException $re) { trunk/XJConf/definitions/AttributeDefinition.php
r29 r43 85 85 } 86 86 } 87 87 88 88 /** 89 89 * Get the name of the attribute. … … 95 95 return $this->name; 96 96 } 97 97 98 98 /** 99 99 * Get the type of the attribute … … 105 105 return $this->type; 106 106 } 107 107 108 108 /** 109 109 * Convert a value to the defined type … … 143 143 return $instance; 144 144 } 145 145 146 146 /** 147 147 * Get the type of the attribute … … 154 154 return $this->valueConverter->getType(); 155 155 } 156 156 157 157 /** 158 158 * Set the setter method … … 176 176 * @see setSetterMethod() 177 177 */ 178 public function getSetterMethod( )178 public function getSetterMethod(Tag $tag) 179 179 { 180 180 if (null == $this->setter) { … … 184 184 return $this->setter; 185 185 } 186 186 187 187 /** 188 188 * Add a child definition … … 196 196 // attributes can not have any children. 197 197 } 198 198 199 199 /** 200 200 * Checks whether this definition has a specific child condition … … 207 207 return false; 208 208 } 209 209 210 210 /** 211 211 * Returns the first found definition of type $def … … 262 262 return $this->required; 263 263 } 264 264 265 265 /** 266 266 * set if attribute is required … … 272 272 $this->required = $required; 273 273 } 274 274 275 275 /** 276 276 * Get the value converter for this tag … … 283 283 $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 284 284 } 285 285 286 286 return $this->valueConverter; 287 287 } trunk/XJConf/definitions/CDataDefinition.php
r36 r43 52 52 $this->type = $type; 53 53 } 54 54 55 55 /** 56 56 * get the name under which the data will be stored … … 72 72 return $this->type; 73 73 } 74 74 75 75 /** 76 76 * Convert the character data to any type … … 115 115 * @see setSetterMethod() 116 116 */ 117 public function getSetterMethod( )117 public function getSetterMethod(Tag $tag) 118 118 { 119 119 return $this->setter; … … 129 129 // Character data can not have any children. 130 130 } 131 131 132 132 /** 133 133 * Checks whether this definition has a specific child condition … … 140 140 return false; 141 141 } 142 142 143 143 /** 144 144 * Returns the first found definition of type $def … … 164 164 return array(); 165 165 } 166 166 167 167 /** 168 168 * Get the value converter for this character data … … 175 175 $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 176 176 } 177 177 178 178 return $this->valueConverter; 179 179 } trunk/XJConf/definitions/ChildDefinition.php
r21 r43 44 44 return $this->name; 45 45 } 46 46 47 47 /** 48 48 * get the type of the child … … 94 94 * @return null 95 95 */ 96 public function getSetterMethod( )96 public function getSetterMethod(Tag $tag) 97 97 { 98 98 return null; … … 108 108 // Character data can not have any children. 109 109 } 110 110 111 111 /** 112 112 * Checks whether this definition has a specific child condition … … 119 119 return false; 120 120 } 121 121 122 122 /** 123 123 * Returns the first found definition of type $def … … 143 143 } 144 144 145 145 146 146 } 147 147 ?> trunk/XJConf/definitions/ConstructorDefinition.php
r21 r43 21 21 */ 22 22 private $params = array(); 23 23 24 24 /** 25 25 * Get the name under which it will be stored … … 31 31 return '__constructor'; 32 32 } 33 33 34 34 /** 35 35 * get the type of the constructor … … 41 41 return null; 42 42 } 43 43 44 44 /** 45 45 * Convert the constructor. … … 65 65 return null; 66 66 } 67 67 68 68 /** 69 69 * Get the setter method … … 71 71 * @return null 72 72 */ 73 public function getSetterMethod( )73 public function getSetterMethod(Tag $tag) 74 74 { 75 75 return null; … … 85 85 array_push($this->params, $def); 86 86 } 87 87 88 88 /** 89 89 * Checks whether this definition has a specific child condition … … 99 99 } 100 100 } 101 101 102 102 return false; 103 103 } 104 104 105 105 /** 106 106 * Returns the first found definition of type $def … … 116 116 } 117 117 } 118 118 119 119 return null; 120 120 } 121 121 122 122 /** 123 123 * Return all child definitions. … … 149 149 return $childrenNames; 150 150 } 151 151 152 152 /** 153 153 * Get the parameters of the constructor trunk/XJConf/definitions/Definition.php
r21 r43 21 21 */ 22 22 public function getName(); 23 23 24 24 /** 25 25 * Get the type of the definition … … 51 51 * @return string 52 52 */ 53 public function getSetterMethod( );53 public function getSetterMethod(Tag $tag); 54 54 55 55 /** … … 59 59 */ 60 60 public function addChildDefinition(Definition $def); 61 61 62 62 /** 63 63 * Checks whether this definition has a specific child condition … … 67 67 */ 68 68 public function hasChildDefinition($def); 69 69 70 70 /** 71 71 * Returns the first found definition of type $def … … 75 75 */ 76 76 public function getChildDefinition($def); 77 77 78 78 /** 79 79 * Get all child definitions of the definition trunk/XJConf/definitions/FactoryMethodDefinition.php
r22 r43 42 42 $this->name = $name; 43 43 } 44 44 45 45 /** 46 46 * Get the name under which it will be stored … … 52 52 return $this->name; 53 53 } 54 54 55 55 /** 56 56 * get the type of the factory method … … 62 62 return null; 63 63 } 64 64 65 65 /** 66 66 * Convert the factory method. … … 84 84 throw new UnsupportedOperationException(); 85 85 } 86 86 87 87 /** 88 88 * Get the setter method … … 90 90 * @throws UnsupportedOperationException 91 91 */ 92 public function getSetterMethod( )92 public function getSetterMethod(Tag $tag) 93 93 { 94 94 throw new UnsupportedOperationException(); 95 95 } 96 96 97 97 /** 98 98 * Add a new child definition (equals a parameter of the factory method) … … 104 104 array_push($this->params, $def); 105 105 } 106 106 107 107 /** 108 108 * Checks whether this definition has a specific child condition … … 118 118 } 119 119 } 120 120 121 121 return false; 122 122 } 123 123 124 124 /** 125 125 * Returns the first found definition of type $def … … 135 135 } 136 136 } 137 137 138 138 return null; 139 139 } 140 140 141 141 /** 142 142 * Return all child definitions. … … 147 147 return $this->params; 148 148 } 149 149 150 150 /** 151 151 * Get the names of all child elements that are used in … … 168 168 return $childrenNames; 169 169 } 170 170 171 171 /** 172 172 * Get the parameters of the factory method trunk/XJConf/definitions/TagDefinition.php
r36 r43 105 105 $this->setType($type); 106 106 } 107 107 108 108 /** 109 109 * set the name of the value … … 115 115 $this->name = $name; 116 116 } 117 117 118 118 /** 119 119 * get the name of the value … … 135 135 $this->type = $type; 136 136 } 137 137 138 138 /** 139 139 * get the type of the tag … … 145 145 return $this->type; 146 146 } 147 147 148 148 /** 149 149 * Convert the value of the tag. … … 171 171 return $instance; 172 172 } 173 173 174 174 /** 175 175 * Get the type of the tag … … 181 181 return $this->getValueConverter()->getType(); 182 182 } 183 183 184 184 /** 185 185 * Set the setter method … … 197 197 * @return string 198 198 */ 199 public function getSetterMethod( )199 public function getSetterMethod(Tag $tag) 200 200 { 201 201 if (null != $this->setter) { … … 208 208 } 209 209 210 return 'set' . ucfirst($this-> name);210 return 'set' . ucfirst($this->getKey($tag)); 211 211 } 212 212 … … 244 244 } 245 245 } 246 246 247 247 /** 248 248 * Checks whether this definition has a specific child condition … … 259 259 } 260 260 } 261 261 262 262 return false; 263 263 } 264 264 265 265 /** 266 266 * Returns the first found definition of type $def … … 277 277 } 278 278 } 279 279 280 280 return null; 281 281 } 282 282 283 283 /** 284 284 * Return all child definitions. … … 313 313 array_push($this->atts, $att); 314 314 } 315 315 316 316 /** 317 317 * Return list of attributes for this tag … … 381 381 return false; 382 382 } 383 383 384 384 /** 385 385 * Get the value converter for this tag … … 392 392 $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 393 393 } 394 394 395 395 return $this->valueConverter; 396 396 } trunk/examples/Color.php
r27 r43 2 2 /** 3 3 * example class 4 * 4 * 5 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 6 * @author Frank Kleine <frank.kleine@schlund.de> … … 8 8 /** 9 9 * example class 10 * 10 * 11 11 * @package XJConf 12 12 * @subpackage examples … … 50 50 * @var string $name name of the color 51 51 */ 52 public function __construct($name )52 public function __construct($name = null) 53 53 { 54 54 $this->name = $name; 55 55 } 56 56 57 57 /** 58 58 * set the red part … … 64 64 $this->red = $val; 65 65 } 66 66 67 67 /** 68 68 * set the green part … … 74 74 $this->green = $val; 75 75 } 76 76 77 77 /** 78 78 * set the blue part … … 84 84 $this->blue = $val; 85 85 } 86 86 87 87 /** 88 88 * set the title of the color … … 94 94 $this->colorTitle = $title; 95 95 } 96 96 97 97 /** 98 98 * get the rgb value as hex … … 104 104 return '#' . dechex($this->red) . dechex($this->green) . dechex($this->blue); 105 105 } 106 106 107 107 /** 108 108 * return the name of the color … … 114 114 return $this->name; 115 115 } 116 116 117 117 /** 118 118 * return the title of the color … … 124 124 return $this->colorTitle; 125 125 } 126 126 127 127 /** 128 128 * returns string representation 129 * 129 * 130 130 * @return string 131 131 */ trunk/examples/TestAttributesRequired.php
r35 r43 2 2 /** 3 3 * Example that shows the effect of required attributes that have not been set. 4 * 4 * 5 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 6 * @author Frank Kleine <frank.kleine@schlund.de> … … 14 14 /** 15 15 * Example that shows the effect of required attributes that have not been set. 16 * 16 * 17 17 * @package XJConf 18 18 * @subpackage examples … … 24 24 $tagParser = new DefinitionParser(); 25 25 $defs = $tagParser->parse(getcwd() . '/xml/defines-attributes-required.xml'); 26 26 27 27 $conf = new XmlParser(); 28 28 try { … … 32 32 var_dump($color); 33 33 } catch (Exception $e) { 34 echo 'Ca tchedexpected Exception with message: "' . $e->getMessage() . '", showing trace: ';34 echo 'Caught expected Exception with message: "' . $e->getMessage() . '", showing trace: '; 35 35 var_dump($e->getTrace()); 36 36 exit(0); 37 } 37 } 38 38 } 39 39 }
