Changeset 21
- Timestamp:
- 08/28/06 17:45:30 (2 years ago)
- Files:
-
- trunk/XJConf/definitions/AttributeDefinition.php (modified) (11 diffs)
- trunk/XJConf/definitions/CDataDefinition.php (modified) (5 diffs)
- trunk/XJConf/definitions/ChildDefinition.php (modified) (4 diffs)
- trunk/XJConf/definitions/ConstructorDefinition.php (modified) (6 diffs)
- trunk/XJConf/definitions/Definition.php (modified) (3 diffs)
- trunk/XJConf/definitions/FactoryMethodDefinition.php (modified) (6 diffs)
- trunk/XJConf/definitions/TagDefinition.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/XJConf/definitions/AttributeDefinition.php
r14 r21 1 1 <?php 2 /** 3 * Definition container of an attribute. 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 */ 2 8 XJConfLoader::load('converters.factories.ValueConverterFactoryChain', 3 9 'definitions.Definition', … … 17 23 * - Whether the attribute is required, or not 18 24 * 19 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 25 * @package XJConf 26 * @subpackage definitions 20 27 */ 21 28 class AttributeDefinition implements Definition 22 29 { 23 24 30 /** 25 31 * name of the attribute … … 28 34 */ 29 35 private $name = null; 30 31 36 /** 32 37 * Type of the attribute … … 35 40 */ 36 41 private $type = null; 37 38 42 /** 39 43 * Name of the setter method … … 42 46 */ 43 47 private $setter = null; 44 45 48 /** 46 49 * Default value … … 49 52 */ 50 53 private $defaultValue = null; 51 52 54 /** 53 55 * Whether the attribute is required … … 56 58 */ 57 59 private $required = false; 58 59 60 /** 60 61 * Converter used to convert the attribute … … 84 85 } 85 86 } 86 87 /** 88 * Set the default value for the attribute. 89 * 90 * @param defaultValue default value that will be used, if a tag does not provide the attribute 91 * @see getDefault() 92 */ 93 public function setDefault($defaultValue) 94 { 95 $this->defaultValue = $defaultValue; 96 } 97 98 /** 99 * Get the default value of the attribute. 100 * 101 * @return string 102 * @see setDefault() 103 */ 104 public function getDefault() 105 { 106 return $this->defaultValue; 107 } 108 109 /** 110 * returns whether the attribute is required or not 111 * 112 * @return boolean 113 */ 114 public function isRequired() 115 { 116 return $this->required; 117 } 118 /** 119 * set if attribute is required 120 * 121 * @param boolean $required 122 */ 123 public function setRequired($required) 124 { 125 $this->required = $required; 126 } 127 128 /** 129 * Set the setter method 130 * 131 * If no setter method is specified, the standard 132 * name "setAttributename()" will be used instead. 133 * 134 * @param string $setter name of the setter method 135 * @see getSetterMethod() 136 */ 137 public function setSetterMethod($setter) 138 { 139 $this->setter = $setter; 140 } 141 142 /** 143 * Get the name of the setter method that should be used 144 * to set the attribute value in the parent container 87 88 /** 89 * Get the name of the attribute. 145 90 * 146 91 * @return string 147 * @see setSetterMethod() 148 */ 149 public function getSetterMethod() 150 { 151 if (null == $this->setter) { 152 return 'set' . ucfirst($this->name); 153 } 154 155 return $this->setter; 156 } 157 158 /** 159 * Get the name of the attribute. 92 */ 93 public function getName() 94 { 95 return $this->name; 96 } 97 98 /** 99 * Get the type of the attribute 160 100 * 161 101 * @return string 162 102 */ 163 public function getName()164 {165 return $this->name;166 }167 168 /**169 * Get the type of the attribute170 *171 * @param Tag $tag172 * @return string173 */174 public function getValueType(Tag $tag)175 {176 return $this->valueConverter->getType();177 }178 179 /**180 * Get the type of the attribute181 *182 * @return string183 */184 103 public function getType() 185 104 { 186 105 return $this->type; 187 106 } 188 107 189 108 /** 190 109 * Convert a value to the defined type … … 211 130 if (null == $value) { 212 131 if ($this->isRequired() == true) { 213 throw new MissingAttributeException( "The attribute '" + this.name + "' is required for the tag '" + tag.getName() + "'.");132 throw new MissingAttributeException('The attribute "' . $this->getName() . '" is required for the tag "' . $tag->getName() . '".'); 214 133 } 215 134 … … 224 143 return $instance; 225 144 } 226 145 146 /** 147 * Get the type of the attribute 148 * 149 * @param Tag $tag 150 * @return string 151 */ 152 public function getValueType(Tag $tag) 153 { 154 return $this->valueConverter->getType(); 155 } 156 157 /** 158 * Set the setter method 159 * 160 * If no setter method is specified, the standard 161 * name "setAttributename()" will be used instead. 162 * 163 * @param string $setter name of the setter method 164 * @see getSetterMethod() 165 */ 166 public function setSetterMethod($setter) 167 { 168 $this->setter = $setter; 169 } 170 171 /** 172 * Get the name of the setter method that should be used 173 * to set the attribute value in the parent container 174 * 175 * @return string 176 * @see setSetterMethod() 177 */ 178 public function getSetterMethod() 179 { 180 if (null == $this->setter) { 181 return 'set' . ucfirst($this->getName()); 182 } 183 184 return $this->setter; 185 } 186 187 /** 188 * Add a child definition 189 * 190 * Attributes can not have any children. 191 * 192 * @param Definition $def 193 */ 194 public function addChildDefinition(Definition $def) 195 { 196 // attributes can not have any children. 197 } 198 199 /** 200 * Checks whether this definition has a specific child condition 201 * 202 * @param string $def 203 * @return boolean true if definition has a specific child condition, else false 204 */ 205 public function hasChildDefinition($def) 206 { 207 return false; 208 } 209 210 /** 211 * Returns the first found definition of type $def 212 * 213 * @param string $def 214 * @return Definition 215 */ 216 public function getChildDefinition($def) 217 { 218 return null; 219 } 220 221 /** 222 * Return all child definitions. 223 * 224 * Currently, it is not possible to add any child 225 * definitions to an attribute 226 * 227 * @return array 228 */ 229 public function getChildDefinitions() { 230 return array(); 231 } 232 233 /** 234 * Set the default value for the attribute. 235 * 236 * @param string $defaultValue default value that will be used, if a tag does not provide the attribute 237 * @see getDefault() 238 */ 239 public function setDefault($defaultValue) 240 { 241 $this->defaultValue = $defaultValue; 242 } 243 244 /** 245 * Get the default value of the attribute. 246 * 247 * @return string 248 * @see setDefault() 249 */ 250 public function getDefault() 251 { 252 return $this->defaultValue; 253 } 254 255 /** 256 * returns whether the attribute is required or not 257 * 258 * @return boolean 259 */ 260 public function isRequired() 261 { 262 return $this->required; 263 } 264 265 /** 266 * set if attribute is required 267 * 268 * @param boolean $required 269 */ 270 public function setRequired($required) 271 { 272 $this->required = $required; 273 } 274 227 275 /** 228 276 * Get the value converter for this tag … … 232 280 private function getValueConverter() 233 281 { 234 if ( $this->valueConverter == null) {282 if (null == $this->valueConverter) { 235 283 $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 236 284 } 285 237 286 return $this->valueConverter; 238 }239 240 /**241 * Add a child definition242 *243 * Attributes can not have any children.244 *245 * @param Definition $def246 */247 public function addChildDefinition(Definition $def)248 {249 // attributes can not have any children.250 }251 252 /**253 * Return all child definitions.254 *255 * Currently, it is not possible to add any child256 * definitions to an attribute257 *258 * @return array259 */260 public function getChildDefinitions() {261 return array();262 287 } 263 288 } trunk/XJConf/definitions/CDataDefinition.php
r14 r21 52 52 $this->type = $type; 53 53 } 54 55 /** 56 * get the name under which the data will be stored 57 * 58 * @return string 59 */ 60 public function getName() 61 { 62 return 'data'; 63 } 64 65 /** 66 * get the type of the data 67 * 68 * @return string 69 */ 70 public function getType() 71 { 72 return $this->type; 73 } 74 75 /** 76 * Convert the character data to any type 77 * 78 * @param Tag $tag 79 * @return mixed concerted value 80 */ 81 public function convertValue(Tag $tag) 82 { 83 $instance = $this->getValueConverter()->convertValue($tag, $this); 84 return $instance; 85 } 86 87 /** 88 * Get the type of the cdata 89 * 90 * @param Tag $tag 91 * @return string 92 */ 93 public function getValueType(Tag $tag) { 94 return $this->getValueConverter()->getType(); 95 } 54 96 55 97 /** … … 78 120 } 79 121 80 /**122 /** 81 123 * Character data cannot have any child definitions 82 124 * … … 87 129 // Character data can not have any children. 88 130 } 89 131 132 /** 133 * Checks whether this definition has a specific child condition 134 * 135 * @param string $def 136 * @return boolean true if definition has a specific child condition, else false 137 */ 138 public function hasChildDefinition($def) 139 { 140 return false; 141 } 142 90 143 /** 91 * Convert the character data to any type144 * Returns the first found definition of type $def 92 145 * 93 * @param Tag $tag94 * @return mixed concerted value 146 * @param string $def 147 * @return Definition 95 148 */ 96 public function convertValue(Tag $tag)149 public function getChildDefinition($def) 97 150 { 98 $instance = $this->getValueConverter()->convertValue($tag, $this); 99 return $instance; 151 return null; 100 152 } 101 102 /**103 * get the name under which the data will be stored104 *105 * @return string106 */107 public function getName()108 {109 return 'data';110 }111 112 /**113 * Get the type of the cdata114 *115 * @param Tag $tag116 * @return string117 */118 public function getValueType(Tag $tag) {119 return $this->getValueConverter()->getType();120 }121 122 /**123 * get the type of the data124 *125 * @return string126 */127 public function getType()128 {129 return $this->type;130 }131 153 132 154 /** … … 138 160 * @return array 139 161 */ 140 public function getChildDefinitions() { 162 public function getChildDefinitions() 163 { 141 164 return array(); 142 165 } 143 166 144 167 /** 145 168 * Get the value converter for this character data … … 149 172 private function getValueConverter() 150 173 { 151 if ( $this->valueConverter == null) {174 if (null == $this->valueConverter) { 152 175 $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 153 176 } trunk/XJConf/definitions/ChildDefinition.php
r14 r21 43 43 { 44 44 return $this->name; 45 } 46 47 /** 48 * get the type of the child 49 * 50 * @return string 51 */ 52 public function getType() 53 { 54 return null; 45 55 } 46 56 … … 98 108 // Character data can not have any children. 99 109 } 110 111 /** 112 * Checks whether this definition has a specific child condition 113 * 114 * @param string $def 115 * @return boolean true if definition has a specific child condition, else false 116 */ 117 public function hasChildDefinition($def) 118 { 119 return false; 120 } 121 122 /** 123 * Returns the first found definition of type $def 124 * 125 * @param string $def 126 * @return Definition 127 */ 128 public function getChildDefinition($def) 129 { 130 return null; 131 } 100 132 101 133 /** … … 105 137 * definitions to a child 106 138 * 107 * @return array139 * @return array 108 140 */ 109 141 public function getChildDefinitions() { … … 111 143 } 112 144 113 /** 114 * get the type of the child 115 * 116 * @return string 117 */ 118 public function getType() 119 { 120 return null; 121 } 145 122 146 } 123 147 ?> trunk/XJConf/definitions/ConstructorDefinition.php
r6 r21 1 1 <?php 2 /** 3 * Definition for the constructor of a class 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 */ 2 8 XJConfLoader::load('definitions.Definition'); 3 9 /** 4 10 * Definition for the constructor of a class 5 11 * 6 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 12 * @package XJConf 13 * @subpackage definitions 7 14 */ 8 15 class ConstructorDefinition implements Definition … … 14 21 */ 15 22 private $params = array(); 16 23 17 24 /** 18 * Add a new child definition (equals a parameter of the constructor)19 *20 * @param Definition $def21 */22 public function addChildDefinition(Definition $def)25 * Get the name under which it will be stored 26 * 27 * @return string 28 */ 29 public function getName() 23 30 { 24 array_push($this->params, $def);31 return '__constructor'; 25 32 } 26 33 27 34 /** 28 * Get the parametersof the constructor29 *30 * @return array 31 */32 public function getParams()33 {34 return $this->params;35 }36 37 /**35 * get the type of the constructor 36 * 37 * @return string 38 */ 39 public function getType() 40 { 41 return null; 42 } 43 44 /** 38 45 * Convert the constructor. 39 46 * … … 48 55 } 49 56 50 /**51 * Get the name under which it will be stored52 *53 * @return string54 */55 public function getName()56 {57 return '__constructor';58 }59 60 57 /** 61 58 * Get the type of the constructor … … 68 65 return null; 69 66 } 70 67 71 68 /** 72 69 * Get the setter method … … 77 74 { 78 75 return null; 76 } 77 78 /** 79 * Add a new child definition (equals a parameter of the constructor) 80 * 81 * @param Definition $def 82 */ 83 public function addChildDefinition(Definition $def) 84 { 85 array_push($this->params, $def); 86 } 87 88 /** 89 * Checks whether this definition has a specific child condition 90 * 91 * @param string $def 92 * @return boolean true if definition has a specific child condition, else false 93 */ 94 public function hasChildDefinition($def) 95 { 96 foreach ($this->params as $param) { 97 if (get_class($param) == $def) { 98 return true; 99 } 100 } 101 102 return false; 103 } 104 105 /** 106 * Returns the first found definition of type $def 107 * 108 * @param string $def 109 * @return Definition 110 */ 111 public function getChildDefinition($def) 112 { 113 foreach ($this->params as $param) { 114 if (get_class($param) == $def) { 115 return $param; 116 } 117 } 118 119 return null; 120 } 121 122 /** 123 * Return all child definitions. 124 * 125 * @return array 126 */ 127 public function getChildDefinitions() { 128 return $this->params; 79 129 } 80 130 … … 99 149 return $childrenNames; 100 150 } 101 151 102 152 /** 103 * Return all child definitions.153 * Get the parameters of the constructor 104 154 * 105 * @return array155 * @return array 106 156 */ 107 public function getChildDefinitions() { 157 public function getParams() 158 { 108 159 return $this->params; 109 160 } 110 111 /**112 * get the type of the constructor113 *114 * @return string115 */116 public function getType()117 {118 return null;119 }120 161 } 121 162 ?> trunk/XJConf/definitions/Definition.php
r6 r21 1 1 <?php 2 2 /** 3 * Interface for tag and attribute definitions 3 * Interface for tag and attribute definitions. 4 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 */ 8 /** 9 * Interface for tag and attribute definitions. 10 * 11 * @package XJConf 12 * @subpackage definitions 6 13 */ 7 14 interface Definition … … 14 21 */ 15 22 public function getName(); 23 24 /** 25 * Get the type of the definition 26 * 27 * @return string 28 */ 29 public function getType(); 16 30 17 31 /** … … 42 56 * Add a child definition of any type 43 57 * 44 * @param Definition def58 * @param Definition $def 45 59 */ 46 60 public function addChildDefinition(Definition $def); 47 61 48 62 /** 49 * Get the type of the definition63 * Checks whether this definition has a specific child condition 50 64 * 51 * @return string 65 * @param string $def 66 * @return boolean true if definition has a specific child condition, else false 52 67 */ 53 public function getType(); 54 55 /** 68 public function hasChildDefinition($def); 69 70 /** 71 * Returns the first found definition of type $def 72 * 73 * @param string $def 74 * @return Definition 75 */ 76 public function getChildDefinition($def); 77 78 /** 56 79 * Get all child definitions of the definition 57 80 * 58 * @return array81 * @return array 59 82 */ 60 83 public function getChildDefinitions(); trunk/XJConf/definitions/FactoryMethodDefinition.php
r6 r21 1 1 <?php 2 /** 3 * FactoryMethodDefinition 4 * 5 * @author Stephan Schmidt <me@schst.net> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 */ 2 8 XJConfLoader::load('definitions.Definition', 3 9 'exceptions.UnsupportedOperationException' … … 9 15 * is used to create an instance. 10 16 * 11 * @author Stephan Schmidt <me@schst.net> 17 * @package XJConf 18 * @subpackage definitions 12 19 */ 13 20 class FactoryMethodDefinition implements Definition … … 35 42 $this->name = $name; 36 43 } 37 38 /** 39 * Get the parameters of the factory method 40 * 41 * @return array 42 */ 43 public function getParams() 44 { 45 return $this->params; 46 } 47 48 /** 49 * Add a new child definition (equals a parameter of the factory method) 50 * 51 * @param Definition $def 52 */ 53 public function addChildDefinition(Definition $def) 54 { 55 array_push($this->params, $def); 56 } 57 58 /** 44 45 /** 59 46 * Get the name under which it will be stored 60 47 * … … 65 52 return $this->name; 66 53 } 67 54 55 /** 56 * get the type of the factory method 57 * 58 * @return string 59 */ 60 public function getType() 61 { 62 return null; 63 } 64 68 65 /** 69 66 * Convert the factory method. … … 87 84 throw new UnsupportedOperationException(); 88 85 } 89 90 /**86 87 /** 91 88 * Get the setter method 92 89 * … … 97 94 throw new UnsupportedOperationException(); 98 95 } 99 96 97 /** 98 * Add a new child definition (equals a parameter of the factory method) 99 * 100 * @param Definition $def 101 */ 102 public function addChildDefinition(Definition $def) 103 { 104 array_push($this->params, $def); 105 } 106 107 /** 108 * Checks whether this definition has a specific child condition 109 * 110 * @param string $def 111 * @return boolean true if definition has a specific child condition, else false 112 */ 113 public function hasChildDefinition($def) 114 { 115 foreach ($this->params as $param) { 116 if (get_class($param) == $def) { 117 return true; 118 } 119 } 120 121 return false; 122 } 123 124 /** 125 * Returns the first found definition of type $def 126 * 127 * @param string $def 128 * @return Definition 129 */ 130 public function getChildDefinition($def) 131 { 132 foreach ($this->params as $param) { 133 if (get_class($param) == $def) { 134 return $param; 135 } 136 } 137 138 return null; 139 } 140 100 141 /** 101 142 * Return all child definitions. 102 143 * 103 * @return array144 * @return array 104 145 */ 105 146 public function getChildDefinitions() { 106 147 return $this->params; 107 148 } 108 109 /**110 * get the typeof the factory method111 *112 * @return string 113 */114 public function getType()115 {116 return null;117 }149 150 /** 151 * Get the parameters of the factory method 152 * 153 * @return array 154 */ 155 public function getParams() 156 { 157 return $this->params; 158 } 118 159 } 119 160 ?> trunk/XJConf/definitions/TagDefinition.php
r14 r21 105 105 $this->setType($type); 106 106 } 107 108 /** 109 * set the name of the value 110 * 111 * @param string $name 112 */ 113 public function setName($name) 114 { 115 $this->name = $name; 116 } 117 118 /** 119 * get the name of the value 120 * 121 * @return string 122 */ 123 public function getName() 124 { 125 return $this->name; 126 } 107 127 108 128 /** … … 115 135 $this->type = $type; 116 136 } 117 118 /** 119 * Add a new child definition 120 * 121 * Possible definitions are: 122 * - AttributeDefinition 123 * - ConstructorDefinition 124 * - FactoryMethodDefinition 125 * - CDataDefinition 126 * 127 * @param Definition $def 128 */ 129 public function addChildDefinition(Definition $def) 130 { 131 if ($def instanceof AttributeDefinition) { 132 $this->addAttribute($def); 133 return; 134 } 135 136 if ($def instanceof FactoryMethodDefinition) { 137 $this->factoryMethod = $def; 138 return; 139 } 140 141 if ($def instanceof ConstructorDefinition) { 142 $this->constructor = $def; 143 return; 144 } 145 146 if ($def instanceof CDataDefinition) { 147 $this->cdata = $def; 148 return; 149 } 150 } 151 152 /** 153 * Add an attribute to the tag 154 * 155 * @param AttributeDefinition $att 156 */ 157 public function addAttribute(AttributeDefinition $att) 158 { 159 array_push($this->atts, $att); 160 } 161 162 public function getAttributes() { 163 return $this->atts; 164 } 165 166 /** 167 * set the name of the value 168 * 169 * @param string $name 170 */ 171 public function setName($name) 172 { 173 $this->name = $name; 174 } 175 176 /** 177 * Set the name of the tag 178 * 179 * @param name 180 */ 181 public function setTagName($name) 182 { 183 $this->tagName = $name; 184 } 185 186 /** 187 * Set the attribute that will be used as key. 188 * 189 * @return name of the value 190 */ 191 public function setKeyAttribute($att) 192 { 193 $this->name = '__attribute'; 194 $this->nameAttribute = $att; 195 } 196 197 /** 198 * get the name of the value 137 138 /** 139 * get the type of the tag 199 140 * 200 141 * @return string 201 142 */ 202 public function getName()203 {204 return $this->name;205 }206 207 /**208 * get the name of the tag209 *210 * @return string211 */212 public function getTagName()213 {214 return $this->tagName;215 }216 217 /**218 * get the name of the tag219 *220 * @return string221 */222 public function getKey(DefinedTag $tag)223 {224 if ('__attribute' == $this->name) {225 return $tag->getAttribute($this->nameAttribute);226 }227 228 return $this->name;229
