Changeset 14
- Timestamp:
- 08/27/06 18:21:44 (2 years ago)
- Files:
-
- trunk/XJConf/DefinedTag.php (modified) (25 diffs)
- trunk/XJConf/DefinitionParser.php (modified) (11 diffs)
- trunk/XJConf/GenericTag.php (modified) (26 diffs)
- trunk/XJConf/Tag.php (modified) (3 diffs)
- trunk/XJConf/converters/AbstractObjectValueConverter.php (added)
- trunk/XJConf/converters/ArrayValueConverter.php (modified) (3 diffs)
- trunk/XJConf/converters/ConstructorValueConverter.php (added)
- trunk/XJConf/converters/FactoryMethodValueConverter.php (modified) (4 diffs)
- trunk/XJConf/converters/ObjectValueConverter.php (deleted)
- trunk/XJConf/converters/PrimitiveValueConverter.php (modified) (5 diffs)
- trunk/XJConf/converters/ValueConverter.php (modified) (1 diff)
- trunk/XJConf/converters/factories/ConstructorValueConverterFactory.php (added)
- trunk/XJConf/converters/factories/FactoryMethodValueConverterFactory.php (modified) (1 diff)
- trunk/XJConf/converters/factories/ObjectValueConverterFactory.php (deleted)
- trunk/XJConf/converters/factories/PrimitiveValueConverterFactory.php (modified) (1 diff)
- trunk/XJConf/converters/factories/ValueConverterFactoryChain.php (modified) (6 diffs)
- trunk/XJConf/definitions/AttributeDefinition.php (modified) (1 diff)
- trunk/XJConf/definitions/CDataDefinition.php (modified) (5 diffs)
- trunk/XJConf/definitions/ChildDefinition.php (modified) (1 diff)
- trunk/XJConf/definitions/TagDefinition.php (modified) (4 diffs)
- trunk/XJConf/definitions/handler/AttributeDefinitionHandler.php (modified) (5 diffs)
- trunk/XJConf/definitions/handler/TagDefinitionHandler.php (modified) (6 diffs)
- trunk/examples/TestPrimitives.php (modified) (2 diffs)
- trunk/examples/xml/defines-primitives.xml (modified) (1 diff)
- trunk/examples/xml/test-primitives.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/XJConf/DefinedTag.php
r9 r14 2 2 /** 3 3 * Contains data of tag in the default namespace. 4 * 4 * 5 5 * @author Stephan Schmidt <me@schst.net> 6 6 * @author Frank Kleine <frank.kleine@schlund.de> … … 11 11 /** 12 12 * Contains data of tag in the default namespace. 13 * 13 * 14 14 * @package XJConf 15 15 */ … … 19 19 /** 20 20 * name of the tag 21 * 21 * 22 22 * @var string 23 23 */ … … 26 26 /** 27 27 * character data 28 * 28 * 29 29 * @var string 30 30 */ 31 31 private $data = null; 32 32 33 33 /** 34 34 * content of the tag 35 * 35 * 36 36 * @var mixed 37 37 */ 38 38 private $content = null; 39 39 40 40 /** 41 41 * attributes of the tag 42 * 42 * 43 43 * @var array 44 44 */ … … 47 47 /** 48 48 * Children of the tag 49 * 49 * 50 50 * @var array 51 51 */ … … 54 54 /** 55 55 * value of the tag 56 * 56 * 57 57 * @var TagDefinition 58 58 */ 59 59 private $tagDef = null; 60 60 61 61 /** 62 62 * Create a new tag without attributes 63 * 63 * 64 64 * @param name name of the tag 65 65 */ … … 69 69 $this->atts = $atts; 70 70 } 71 71 72 72 /** 73 73 * Get the name of the tag 74 * 74 * 75 75 * @return name of the tag 76 76 */ … … 79 79 return $this->name; 80 80 } 81 81 82 82 /** 83 83 * Set the key 84 * 84 * 85 85 * @param string $key 86 86 */ … … 89 89 $this->key = $key; 90 90 } 91 91 92 92 /** 93 93 * Get the key under which the value will be stored 94 * 94 * 95 95 * @return string 96 96 */ … … 99 99 return $this->tagDef->getKey($this); 100 100 } 101 101 102 102 /** 103 103 * Add text data 104 * 104 * 105 105 * @param string $buf 106 106 * @return int new length of data … … 111 111 return strlen($this->data); 112 112 } 113 113 114 114 /** 115 115 * Get the character data of the tag 116 * 116 * 117 117 * @return character data 118 118 */ … … 124 124 /** 125 125 * Check, whether the tag has a certain attribute 126 * 126 * 127 127 * @param string $name 128 128 * @return boolean … … 135 135 /** 136 136 * get an attribute 137 * 137 * 138 138 * @param string $name name of the attribute 139 139 * @return string value of the attribute … … 144 144 return $this->atts[$name]; 145 145 } 146 146 147 147 return null; 148 148 } 149 149 150 /** 151 * get all attributes 152 * 153 * @return array 154 */ 155 public function getAttributes() 156 { 157 return $this->atts; 158 } 159 150 160 /** 151 161 * Add a new child to this tag. 152 * 162 * 153 163 * @param child child to add 154 164 * @return int number of childs added … … 162 172 /** 163 173 * Get the child with a specific name 164 * 174 * 165 175 * @param string $name 166 176 * @return Tag … … 173 183 } 174 184 } 175 185 176 186 return null; 177 187 } … … 179 189 /** 180 190 * Get all children of the tag 181 * 191 * 182 192 * @return array 183 193 */ … … 189 199 /** 190 200 * Set the content (overrides the character data) 191 * 201 * 192 202 * @param mixed $content 193 203 */ … … 199 209 /** 200 210 * Get the content 201 * 211 * 202 212 * @return mixed 203 213 */ … … 207 217 return $this->content; 208 218 } 209 219 210 220 return $this->getData(); 211 221 } 212 222 213 223 /** 214 224 * Fetch the value 215 * 225 * 216 226 * @return mixed the value of the tag 217 227 */ … … 223 233 /** 224 234 * Get the type of the value 225 * 235 * 226 236 * @param Tag $tag 227 237 * @return string … … 231 241 return $this->tagDef->getValueType($tag); 232 242 } 233 243 234 244 /** 235 245 * Get the setter method 236 * 246 * 237 247 * @return string 238 248 */ … … 241 251 return $this->tagDef->getSetterMethod(); 242 252 } 243 253 244 254 /** 245 255 * Checks, whether the tag supports indexed children 246 * 256 * 247 257 * @return boolean 248 258 */ … … 250 260 { 251 261 return $this->tagDef->supportsIndexedChildren(); 252 } 253 262 } 263 254 264 /** 255 265 * Set the tag definition object used for this tag 256 * 266 * 257 267 * @param TagDefinition $tagDef 258 268 */ … … 261 271 $this->tagDef = $tagDef; 262 272 } 263 273 264 274 /** 265 275 * get the tag definition object used for this tag 266 * 276 * 267 277 * @return TagDefinition 268 278 */ trunk/XJConf/DefinitionParser.php
r9 r14 74 74 /** 75 75 * constructor 76 * 76 * 77 77 * Sets the node types depending on your PHP version using the constants 78 78 * defined by the XMLReader PHP extension. … … 95 95 } 96 96 } 97 97 98 98 /** 99 99 * returns the current namespace … … 105 105 return $this->currentNamespace; 106 106 } 107 107 108 108 /** 109 109 * returns the list of created namespace definitions … … 115 115 return $this->defs; 116 116 } 117 117 118 118 /** 119 119 * returns the definition stack … … 125 125 return $this->defStack; 126 126 } 127 127 128 128 /** 129 129 * initializes the parser … … 154 154 $elementName = $this->reader->localName; 155 155 $attributes = array(); 156 $empty = $this->reader->isEmptyElement; 156 157 if (TRUE == $this->reader->hasAttributes) { 157 158 // go to first attribute … … 165 166 166 167 $this->startElement($nameSpaceURI, $elementName, $attributes); 168 if (true === $empty) { 169 $this->endElement($this->reader->namespaceURI, $this->reader->localName); 170 } 167 171 break; 168 172 … … 200 204 throw new InvalidNamespaceDefinitionException('The <' . self::TAG_NAMESPACE . '> tag is missing the uri attribute.'); 201 205 } 202 206 203 207 // change current namespace to new namespace 204 208 $this->currentNamespace = $atts['uri']; 205 209 return; 206 210 } 207 211 208 212 // create the appropriate definition handler and use this 209 213 // to create the required definition … … 214 218 } 215 219 216 if ($defHandler->needsEnd() == true) {220 // if ($defHandler->needsEnd() == true) { 217 221 array_push($this->defHandlerStack, $defHandler); 218 }222 // } 219 223 } 220 224 … … 224 228 * Fetches the TagDefinition from the stack and 225 229 * adds it to the NamespaceDefinition object. 226 * 230 * 227 231 * @param string $namespaceURI namespace of end tag 228 232 * @param string $sName name of end tag … … 235 239 return; 236 240 } 237 241 238 242 // use definition handler to finalize the definition of the current tag 239 243 $defHandler = array_pop($this->defHandlerStack); trunk/XJConf/GenericTag.php
r9 r14 3 3 * Generic Tag wrapper that can be used by extensions to dynamically add 4 4 * children to other tags. 5 * 5 * 6 6 * @author Stephan Schmidt <me@schst.net> 7 7 */ … … 10 10 * Generic Tag wrapper that can be used by extensions to dynamically add 11 11 * children to other tags. 12 * 12 * 13 13 * @package XJConf 14 14 */ … … 17 17 /** 18 18 * name of the tag 19 * 19 * 20 20 * @var string 21 21 */ … … 23 23 /** 24 24 * character data 25 * 25 * 26 26 * @var string 27 27 */ … … 29 29 /** 30 30 * content of the tag (overrides data) 31 * 31 * 32 32 * @var mixed 33 33 */ … … 35 35 /** 36 36 * attributes of the tag 37 * 37 * 38 38 * @var array 39 39 */ … … 41 41 /** 42 42 * Children of the tag 43 * 43 * 44 44 * @var array 45 45 */ … … 47 47 /** 48 48 * value of the tag 49 * 49 * 50 50 * @var mixed 51 51 */ … … 53 53 /** 54 54 * Key of the tag 55 * 55 * 56 56 * @var string 57 57 */ 58 58 private $key = null; 59 59 60 60 /** 61 61 * Create a new tag with or without attributes 62 * 62 * 63 63 * @param string $name name of the tag 64 64 * @param array $atts optional list of attributes … … 69 69 $this->atts = $atts; 70 70 } 71 71 72 72 /** 73 73 * Get the name of the tag 74 * 74 * 75 75 * @return string 76 76 */ … … 79 79 return $this->name; 80 80 } 81 81 82 82 /** 83 83 * Set the key 84 * 84 * 85 85 * @param string $key 86 86 */ … … 89 89 $this->key = $key; 90 90 } 91 91 92 92 /** 93 93 * Get the key under which the value will be stored 94 * 94 * 95 95 * @return string 96 96 */ … … 99 99 return $this->key; 100 100 } 101 101 102 102 /** 103 103 * Add text data 104 * 104 * 105 105 * @param string $buf 106 106 * @return int new length of data … … 111 111 return strlen($this->data); 112 112 } 113 113 114 114 /** 115 115 * Get the character data of the tag 116 * 116 * 117 117 * @return string 118 118 */ … … 124 124 /** 125 125 * Check, whether the tag has a certain attribute 126 * 126 * 127 127 * @param string $name 128 128 * @return boolean … … 135 135 /** 136 136 * get an attribute 137 * 137 * 138 138 * @param string $name name of the attribute 139 139 * @return string value of the attribute … … 144 144 return $this->atts[$name]; 145 145 } 146 146 147 147 return null; 148 148 } 149 149 150 /** 151 * get all attributes 152 * 153 * @return array 154 */ 155 public function getAttributes() 156 { 157 return $this->atts; 158 } 159 150 160 /** 151 161 * Add a new child to this tag. 152 * 162 * 153 163 * @param Tag $child child to add 154 164 * @return int number of childs added … … 159 169 return count($this->children); 160 170 } 161 171 162 172 /** 163 173 * Get the child with a specific name 164 * 174 * 165 175 * @param string $name 166 176 * @return Tag … … 173 183 } 174 184 } 175 185 176 186 return null; 177 187 } 178 188 179 189 /** 180 190 * Get all children of the tag 181 * 191 * 182 192 * @return array 183 193 */ … … 186 196 return $this->children; 187 197 } 188 198 189 199 /** 190 200 * Set the content (overrides the character data) 191 * 201 * 192 202 * @param mixed $content 193 203 */ … … 199 209 /** 200 210 * Get the content 201 * 211 * 202 212 * @return mixed 203 213 */ … … 207 217 return $this->content; 208 218 } 209 219 210 220 return $this->getData(); 211 221 } 212 222 213 223 /** 214 224 * Fetch the value 215 * 225 * 216 226 * @return mixed the value of the tag 217 227 */ … … 220 230 return $this->value; 221 231 } 222 232 223 233 /** 224 234 * Get the type of the value 225 * 235 * 226 236 * @return string 227 237 */ … … 231 241 return null; 232 242 } 233 243 234 244 if (is_object($this->value) == true) { 235 245 return get_class($this->value); 236 246 } 237 247 238 248 return gettype($this->value); 239 249 } 240 250 241 251 /** 242 252 * Get the setter method … … 252 262 /** 253 263 * Checks, whether the tag supports indexed children 254 * 264 * 255 265 * @return boolean 256 266 */ … … 259 269 return true; 260 270 } 261 271 262 272 /** 263 273 * Set the value of the tag 264 * 274 * 265 275 * @param mixed 266 276 */ trunk/XJConf/Tag.php
r9 r14 2 2 /** 3 3 * Interface for holding tag data. 4 * 4 * 5 5 * @author Stephan Schmidt <me@schst.net> 6 6 * @author Frank Kleine <frank.kleine@schlund.de> … … 15 15 /** 16 16 * Get the name of the tag 17 * 17 * 18 18 * @return name of the tag 19 19 */ 20 20 public function getName(); 21 21 22 22 /** 23 23 * Get the key under which the value will be stored 24 * 24 * 25 25 * @return string 26 26 */ 27 27 public function getKey(); 28 28 29 29 /** 30 30 * Add text data 31 * 31 * 32 32 * @param string $buf 33 33 * @return int new length of data 34 34 */ 35 35 public function addData($buf); 36 36 37 37 /** 38 38 * Get the character data of the tag 39 * 39 * 40 40 * @return character data 41 41 */ 42 42 public function getData(); 43 43 44 44 /** 45 45 * Check, whether the tag has a certain attribute 46 * 46 * 47 47 * @param string $name 48 48 * @return boolean 49 49 */ 50 50 public function hasAttribute($name); 51 51 52 52 /** 53 53 * get an attribute 54 * 54 * 55 55 * @param string $name name of the attribute 56 56 * @return string value of the attribute 57 57 */ 58 58 public function getAttribute($name); 59 59 60 /** 61 * get all attributes 62 * 63 * @return array 64 */ 65 public function getAttributes(); 66 60 67 /** 61 68 * Add a new child to this tag. 62 * 69 * 63 70 * @param child child to add 64 71 * @return int number of childs added 65 72 */ 66 73 public function addChild(Tag $child); 67 74 68 75 /** 69 76 * Get the child with a specific name 70 * 77 * 71 78 * @param string $name 72 79 * @return Tag 73 80 */ 74 81 public function getChild($name); 75 82 76 83 /** 77 84 * Get all children of the tag 78 * 85 * 79 86 * @return array 80 87 */ 81 88 public function getChildren(); 82 89 83 90 /** 84 91 * Set the content (overrides the character data) 85 * 92 * 86 93 * @param mixed $content 87 94 */ 88 95 public function setContent($content); 89 96 90 97 /** 91 98 * Get the content 92 * 99 * 93 100 * @return mixed 94 101 */ 95 102 public function getContent(); 96 103 97 104 /** 98 105 * Fetch the value 99 * 106 * 100 107 * @return mixed the value of the tag 101 108 */ 102 109 public function getConvertedValue(); 103 110 104 111 /** 105 112 * Get the type of the value 106 * 113 * 107 114 * @param Tag $tag 108 115 * @return string … … 112 119 /** 113 120 * Get the setter method 114 * 121 * 115 122 * @return string 116 123 */ 117 124 public function getSetterMethod(); 118 125 119 126 /** 120 127 * Checks, whether the tag supports indexed children 121 * 128 * 122 129 * @return boolean 123 130 */ trunk/XJConf/converters/ArrayValueConverter.php
r12 r14 2 2 /** 3 3 * Converter to convert a value to an array. 4 * 4 * 5 5 * @author Frank Kleine <frank.kleine@schlund.de> 6 6 */ … … 8 8 /** 9 9 * Converter to convert a value to an array. 10 * 10 * 11 11 * @package XJConf 12 12 * @subpackage converters … … 20 20 * @return array the converted value 21 21 */ 22 public function convertValue( $values)22 public function convertValue(Tag $tag, Definition $def) 23 23 { 24 return $values;24 return array(); 25 25 } 26 26 27 27 /** 28 28 * returns the type of the converter 29 * 29 * 30 30 * @return string 31 31 */ trunk/XJConf/converters/FactoryMethodValueConverter.php
r2 r14 15 15 * @var string 16 16 */ 17 private $className; 17 protected $className; 18 18 19 /** 19 20 * name of method to use as factory method … … 21 22 * @var string 22 23 */ 23 pr ivate$methodName;24 24 protected $methodName; 25 25 26 /** 26 27 * constructor 27 * 28 * 28 29 * @param string $className name of class to use 29 30 * @param string $methodName name of method to use … … 42 43 * @throws ValueConversionException 43 44 */ 44 public function convertValue( $values)45 public function convertValue(Tag $tag, Definition $def) 45 46 { 47 /* 46 48 if (class_exists($this->className) == false) { 47 49 throw new ValueConversionException('Class "' . $this->className . '" does not exist.'); 48 50 } 49 51 50 52 try { 51 53 $refClass = new ReflectionClass($this->className); … … 54 56 throw new ValueConversionException('Could not create instance of "' . $this->className . '" using the factory method "' . $this->methodName . '": ' . $re->getMessage()); 55 57 } 56 58 57 59 return $instance; 60 */ 58 61 } 59 62 60 /** 61 * returns the type of the converter 62 * 63 * @return string 63 /** 64 * Get the factory method of the definition, if available 65 * 66 * @param Definition $def 67 * @return FactoryMethodDefinition 64 68 */ 65 public function getType() 66 { 67 return $this->className; 68 } 69 public static function getFactoryMethodDefinition(Definition $def) { 70 foreach ($def->getChildDefinitions() as $child) { 71 if ($child instanceof FactoryMethodDefinition) { 72 return $child; 73 } 74 } 75 return null; 76 } 69 77 } 70 78 ?> trunk/XJConf/converters/PrimitiveValueConverter.php
r2 r14 1 1 <?php 2 2 XJConfLoader::load('converters.ValueConverter', 3 'converters.PrimitiveValueConverter', 3 4 'exceptions.ValueConversionException' 4 5 ); 5 6 /** 6 7 * Converter to convert a value to a primitive type 7 * 8 * 8 9 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 9 10 */ … … 13 14 /** 14 15 * Type of the primitive 15 * 16 * 16 17 * @var string 17 18 */ … … 34 35 * @throws ValueConversionException 35 36 */ 36 public function convertValue($values) 37 { 38 39 if (count($values) > 1) { 40 throw new ValueConversionException('Cannot convert value to primitive type.'); 41 } 42 37 public function convertValue(Tag $tag, Definition $def) { 38 $value = $tag->getData(); 39 43 40 switch ($this->type) { 44 41 case 'boolean': 45 42 case 'bool': 46 return (boolean) $value s[0];43 return (boolean) $value; 47 44 case 'integer': 48 45 case 'int': 49 return (integer) $value s[0];46 return (integer) $value; 50 47 case 'double': 51 return (double) $value s[0];48 return (double) $value; 52 49 case 'float': 53 return (float) $value s[0];50 return (float) $value; 54 51 case 'string': 55 return (string) $value s[0];52 &
