Changeset 3007
- Timestamp:
- 10/10/08 15:58:22 (3 months ago)
- Location:
- branches/felix-testing-implementation
- Files:
-
- 6 modified
-
. (modified) (1 prop)
-
CHANGELOG (modified) (1 diff)
-
src/config/AgaviConfigHandlersConfigHandler.class.php (modified) (6 diffs)
-
src/config/AgaviTestSuitesConfigHandler.class.php (modified) (1 diff)
-
src/config/util/dom/AgaviXmlConfigDomElement.class.php (modified) (17 diffs)
-
src/validator/AgaviValidationManager.class.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/felix-testing-implementation
- Property svnmerge-integrated changed from /branches/1.0:1-2892,2894-2984,2987-2988,2990-2998 to /branches/1.0:1-2892,2894-2984,2987-2988,2990-3006
-
branches/felix-testing-implementation/CHANGELOG
r2992 r3007 4 4 1.0.0 beta 4 (October ??, 2008) 5 5 ------------------------------- 6 7 CHG: Change singular/plural handling in AgaviXmlConfigDomElement convenience methods (#878) (David) 6 8 7 9 FIX: XInclude failure leads to corrupt exception error message (#877) (David) -
branches/felix-testing-implementation/src/config/AgaviConfigHandlersConfigHandler.class.php
r2785 r3007 23 23 * 24 24 * @author Dominik del Bondio <ddb@bitxtender.com> 25 * @author Noah Fontes <noah.fontes@bitextender.com> 26 * @author David Zülke <david.zuelke@bitextender.com> 25 27 * @copyright Authors 26 28 * @copyright The Agavi Project … … 49 51 * @author Dominik del Bondio <ddb@bitxtender.com> 50 52 * @author Noah Fontes <noah.fontes@bitextender.com> 53 * @author David Zülke <david.zuelke@bitextender.com> 51 54 * @since 0.11.0 52 55 */ … … 60 63 61 64 foreach($document->getConfigurationElements() as $configuration) { 62 if(!$configuration->has Children('handlers')) {65 if(!$configuration->has('handlers')) { 63 66 continue; 64 67 } 65 68 66 69 // let's do our fancy work 67 foreach($configuration->get Children('handlers') as $handler) {70 foreach($configuration->get('handlers') as $handler) { 68 71 $pattern = $handler->getAttribute('pattern'); 69 72 … … 76 79 AgaviXmlConfigParser::STAGE_COMPILATION => array(), 77 80 ); 78 if($handler->has Children('transformations')) {79 foreach($handler->get Children('transformations') as $transformation) {81 if($handler->has('transformations')) { 82 foreach($handler->get('transformations') as $transformation) { 80 83 $path = AgaviToolkit::literalize($transformation->getValue()); 81 84 $for = $transformation->getAttribute('for', AgaviXmlConfigParser::STAGE_SINGLE); … … 122 125 ), 123 126 ); 124 if($handler->has Children('validations')) {125 foreach($handler->get Children('validations') as $validation) {127 if($handler->has('validations')) { 128 foreach($handler->get('validations') as $validation) { 126 129 $path = AgaviToolkit::literalize($validation->getValue()); 127 130 $type = null; … … 158 161 } 159 162 160 public function guessValidationType($path) 163 /** 164 * Convenience method to quickly guess the type of a validation file using its 165 * file extension. 166 * 167 * @param string The path to the file. 168 * 169 * @return string An AgaviXmlConfigParser::VALIDATION_TYPE_* const value. 170 * 171 * @throws AgaviException If the type could not be determined. 172 * 173 * @author David Zülke <david.zuelke@bitextender.com> 174 * @since 1.0.0 175 */ 176 protected function guessValidationType($path) 161 177 { 162 178 switch(pathinfo($path, PATHINFO_EXTENSION)) { -
branches/felix-testing-implementation/src/config/AgaviTestSuitesConfigHandler.class.php
r2850 r3007 58 58 // loop over <configuration> elements 59 59 foreach($document->getConfigurationElements() as $configuration) { 60 foreach($configuration->get Children('suites') as $current) {60 foreach($configuration->get('suites') as $current) { 61 61 $suite = array('class' => $current->getAttribute('class', 'AgaviTestSuite')); 62 62 $suite['testfiles'] = array(); 63 foreach($current->get Children('testfiles') as $file) {63 foreach($current->get('testfiles') as $file) { 64 64 $suite['testfiles'][] = $file->textContent; 65 65 } -
branches/felix-testing-implementation/src/config/util/dom/AgaviXmlConfigDomElement.class.php
r2946 r3007 4 4 { 5 5 /** 6 * Overloaded method for accessing child nodes. Does the pluralizing etc, and 7 * provides convenient access through a potentially set default namespace. 8 * 9 * @param string The child element name. 10 * 11 * @return mixed A DOMNodeList or an AgaviXmlConfigDomElement. 12 * 13 * @author David Zülke <dz@bitxtender.com> 14 * @since 1.0.0 15 */ 16 public function __get($name) { 17 // TODO: add {namespace}element support 18 // should look into the default ns, IMO. otherwise, you gotta use getChild() 19 // must use singular/plural handling 20 } 21 22 public function __isset($name) { 23 // TODO: add {namespace}element support 24 // should look into the default ns, IMO. otherwise, you gotta use hasChild() 25 } 26 6 * __toString() magic method, returns the element value. 7 * 8 * @see AgaviXmlConfigDomElement::getValue() 9 * 10 * @return string The element value. 11 * 12 * @author David Zülke <david.zuelke@bitextender.com> 13 * @since 1.0.0 14 */ 27 15 public function __toString() 28 16 { … … 30 18 } 31 19 20 /** 21 * Returns the element name. 22 * 23 * @return string The element name. 24 * 25 * @author David Zülke <david.zuelke@bitextender.com> 26 * @since 1.0.0 27 */ 32 28 public function getName() 33 29 { … … 37 33 } 38 34 35 /** 36 * Returns the element value. 37 * 38 * @return string The element value. 39 * 40 * @author David Zülke <david.zuelke@bitextender.com> 41 * @since 1.0.0 42 */ 39 43 public function getValue() 40 44 { … … 50 54 * @return Iterator An iterator. 51 55 * 52 * @author David Zülke <d z@bitxtender.com>56 * @author David Zülke <david.zuelke@bitextender.com> 53 57 * @since 1.0.0 54 58 */ … … 64 68 } 65 69 70 /** 71 * Retrieve singular form of given element name. 72 * This does special splitting only of the last part of the name if the name 73 * of the element contains hyphens, underscores or dots. 74 * 75 * @param string The element name to singularize. 76 * 77 * @return string The singularized element name. 78 * 79 * @author Noah Fontes <noah.fontes@bitextender.com> 80 * @since 1.0.0 81 */ 66 82 protected function singularize($name) 67 83 { 84 // TODO: shouldn't this be static? 68 85 $names = preg_split('#([_\-\.])#', $name, -1, PREG_SPLIT_DELIM_CAPTURE); 69 86 $names[count($names) - 1] = AgaviInflector::singularize(end($names)); … … 72 89 73 90 /** 91 * Convenience method to retrieve child elements of the given name. 92 * Accepts singular or plural forms of the name, and will detect and handle 93 * parent containers with plural names properly. 94 * 95 * @param string The name of the element(s) to check for. 96 * @param string The namespace URI. If null, the document default 97 * namespace will be used. If an empty string, no namespace 98 * will be used. 99 * 100 * @return DOMNodeList A list of the child elements. 101 * 102 * @author David Zülke <david.zuelke@bitextender.com> 103 * @since 1.0.0 104 */ 105 public function get($name, $namespaceUri = null) 106 { 107 return $this->getChildren($name, $namespaceUri, true); 108 } 109 110 /** 111 * Convenience method to check if there are child elements of the given name. 112 * Accepts singular or plural forms of the name, and will detect and handle 113 * parent containers with plural names properly. 114 * 115 * @param string The name of the element(s) to check for. 116 * @param string The namespace URI. If null, the document default 117 * namespace will be used. If an empty string, no namespace 118 * will be used. 119 * 120 * @return bool True if one or more child elements with the given name 121 * exist, false otherwise. 122 * 123 * @author David Zülke <david.zuelke@bitextender.com> 124 * @since 1.0.0 125 */ 126 public function has($name, $namespaceUri = null) 127 { 128 return $this->hasChildren($name, $namespaceUri, true); 129 } 130 131 /** 74 132 * Count the number of child elements with a given name. 75 133 * … … 78 136 * namespace will be used. If an empty string, no namespace 79 137 * will be used. 138 * @param bool Whether or not to apply automatic singular/plural 139 * handling that skips plural container elements. 80 140 * 81 141 * @return int The number of child elements with the given name. 82 142 * 83 143 * @author Noah Fontes <noah.fontes@bitextender.com> 84 * @since 1.0.0 85 */ 86 public function countChildren($name, $namespaceUri = null) 87 { 88 // check for child elements(!) using XPath 89 // if arg is true, then only check for elements from our default namespace 144 * @author David Zülke <david.zuelke@bitextender.com> 145 * @since 1.0.0 146 */ 147 public function countChildren($name, $namespaceUri = null, $pluralMagic = false) 148 { 149 // if arg is null, then only check for elements from our default namespace 150 // if namespace uri is null, use default ns. if empty string, use no ns 90 151 $namespaceUri = ($namespaceUri === null ? $this->ownerDocument->getDefaultNamespaceUri() : $namespaceUri); 91 $singularName = $this->singularize($name); 92 93 $xpath = $this->ownerDocument->getXpath(); 94 if($namespaceUri) { 95 return (int)$xpath->evaluate(sprintf('count(child::*[local-name() = "%2$s" and namespace-uri() = "%3$s"]) + count(child::*[local-name() = "%1$s" and namespace-uri() = "%3$s"]/*[local-name() = "%2$s" and namespace-uri() = "%3$s"])', $name, $singularName, $namespaceUri), $this); 152 153 // init our vars 154 $query = ''; 155 $singularName = null; 156 157 if($pluralMagic) { 158 // we always assume that we either get plural names, or the singular of the singular is not different from the singular :) 159 $singularName = $this->singularize($name); 160 if($namespaceUri) { 161 $query = 'count(child::*[local-name() = "%2$s" and namespace-uri() = "%3$s"]) + count(child::*[local-name() = "%1$s" and namespace-uri() = "%3$s"]/*[local-name() = "%2$s" and namespace-uri() = "%3$s"])'; 162 } else { 163 $query = 'count(%1$s/%2$s) + count(%2$s)'; 164 } 96 165 } else { 97 return (int)$xpath->evaluate(sprintf('count(%2$s) + count(%1$s/%2$s)', $name, $singularName), $this); 98 } 166 if($namespaceUri) { 167 $query = 'count(child::*[local-name() = "%1$s" and namespace-uri() = "%3$s"])'; 168 } else { 169 $query = 'count(%1$s)'; 170 } 171 } 172 173 return (int)$this->ownerDocument->getXpath()->evaluate(sprintf($query, $name, $singularName, $namespaceUri), $this); 99 174 } 100 175 … … 107 182 * namespace will be used. If an empty string, no namespace 108 183 * will be used. 184 * @param bool Whether or not to apply automatic singular/plural 185 * handling that skips plural container elements. 109 186 * 110 187 * @return bool True if one or more child elements with the given name … … 112 189 * 113 190 * @author Noah Fontes <noah.fontes@bitextender.com> 114 * @since 1.0.0 115 */ 116 public function hasChildren($name, $namespaceUri = null) 117 { 118 return $this->countChildren($name, $namespaceUri) !== 0; 191 * @author David Zülke <david.zuelke@bitextender.com> 192 * @since 1.0.0 193 */ 194 public function hasChildren($name, $namespaceUri = null, $pluralMagic = false) 195 { 196 return $this->countChildren($name, $namespaceUri, $pluralMagic) !== 0; 119 197 } 120 198 … … 126 204 * namespace will be used. If an empty string, no namespace 127 205 * will be used. 206 * @param string Whether or not to apply pluralization magic in selects. 207 * @param bool Whether or not to apply automatic singular/plural 208 * handling that skips plural container elements. 128 209 * 129 210 * @return DOMNodeList A list of the child elements. 130 211 * 131 212 * @author Noah Fontes <noah.fontes@bitextender.com> 132 * @ since 1.0.0133 * /134 public function getChildren($name, $namespaceUri = null)135 {136 // check for child elements(!) using XPath137 // if arg is true, then only check for elements from our default namespace213 * @author David Zülke <david.zuelke@bitextender.com> 214 * @since 1.0.0 215 */ 216 public function getChildren($name, $namespaceUri = null, $pluralMagic = false) 217 { 218 // if arg is null, then only check for elements from our default namespace 138 219 // if namespace uri is null, use default ns. if empty string, use no ns 139 220 $namespaceUri = ($namespaceUri === null ? $this->ownerDocument->getDefaultNamespaceUri() : $namespaceUri); 140 $singularName = $this->singularize($name); 141 142 $xpath = $this->ownerDocument->getXpath(); 143 if($namespaceUri) { 144 return $xpath->query(sprintf('child::*[local-name() = "%2$s" and namespace-uri() = "%3$s"] | child::*[local-name() = "%1$s" and namespace-uri() = "%3$s"]/*[local-name() = "%2$s" and namespace-uri() = "%3$s"]', $name, $singularName, $namespaceUri), $this); 221 222 // init our vars 223 $query = ''; 224 $singularName = null; 225 226 if($pluralMagic) { 227 // we always assume that we either get plural names, or the singular of the singular is not different from the singular :) 228 $singularName = $this->singularize($name); 229 if($namespaceUri) { 230 $query = 'child::*[local-name() = "%2$s" and namespace-uri() = "%3$s"] | child::*[local-name() = "%1$s" and namespace-uri() = "%3$s"]/*[local-name() = "%2$s" and namespace-uri() = "%3$s"]'; 231 } else { 232 $query = '%1$s/%2$s | %2$s'; 233 } 145 234 } else { 146 return $xpath->query(sprintf('%1$s/%2$s | %2$s', $name, $singularName), $this); 147 } 235 if($namespaceUri) { 236 $query = 'child::*[local-name() = "%1$s" and namespace-uri() = "%3$s"]'; 237 } else { 238 $query = '%1$s'; 239 } 240 } 241 242 return $this->ownerDocument->getXpath()->query(sprintf($query, $name, $singularName, $namespaceUri), $this); 148 243 } 149 244 … … 166 261 public function hasChild($name, $namespaceUri = null) 167 262 { 263 return $this->getChild($name, $namespaceUri) !== null; 264 } 265 266 /** 267 * Return a single child element with a given name. 268 * Only returns anything if there is exactly one child of this name. 269 * 270 * @param string The name of the element. 271 * @param string The namespace URI. If null, the document default 272 * namespace will be used. If an empty string, no namespace 273 * will be used. 274 * 275 * @return DOMElement The child element, or null if none exists. 276 * 277 * @author Noah Fontes <noah.fontes@bitextender.com> 278 * @author David Zülke <david.zuelke@bitextender.com> 279 * @since 1.0.0 280 */ 281 public function getChild($name, $namespaceUri = null) 282 { 283 // if arg is null, then only check for elements from our default namespace 168 284 // if namespace uri is null, use default ns. if empty string, use no ns 169 return $this->countChildren($name, $namespaceUri) === 1; 170 171 // XXX: not necessary for single elements? 172 // remember singular/plural support 173 } 174 175 /** 176 * Return a single child element with a given name. 177 * 178 * @param string The name of the element. 179 * @param string The namespace URI. If null, the document default 180 * namespace will be used. If an empty string, no namespace 181 * will be used. 182 * 183 * @return DOMElement The child element, or null if none xists. 184 * 185 * @author Noah Fontes <noah.fontes@bitextender.com> 186 * @since 1.0.0 187 */ 188 public function getChild($name, $namespaceUri = null) 189 { 190 $list = $this->getChildren($name, $namespaceUri); 191 192 if($list->length > 0) { 193 return $list->item(0); 194 } 195 return null; 285 $namespaceUri = ($namespaceUri === null ? $this->ownerDocument->getDefaultNamespaceUri() : $namespaceUri); 286 287 if($namespaceUri) { 288 $query = 'self::node()[count(child::*[local-name() = "%1$s" and namespace-uri() = "%2$s"]) = 1]/*[local-name() = "%1$s" and namespace-uri() = "%2$s"]'; 289 } else { 290 $query = 'self::node()[count(child::%1$s) = 1]/%1$s'; 291 } 292 293 return $this->ownerDocument->getXpath()->query(sprintf($query, $name, $namespaceUri), $this)->item(0); 196 294 } 197 295 … … 209 307 * @see DOMElement::getAttribute() 210 308 * 211 * @author David Zülke <d z@bitxtender.com>309 * @author David Zülke <david.zuelke@bitextender.com> 212 310 * @since 1.0.0 213 311 */ … … 239 337 * @see DOMElement::getAttributeNS() 240 338 * 241 * @author David Zülke <d z@bitxtender.com>339 * @author David Zülke <david.zuelke@bitextender.com> 242 340 * @since 1.0.0 243 341 */ … … 254 352 255 353 /** 354 * Retrieve all attributes of the element that are in no namespace. 355 * 356 * @return array An associative array of attribute names and values. 357 * 358 * @author David Zülke <david.zuelke@bitextender.com> 359 * @since 1.0.0 360 */ 361 public function getAttributes() 362 { 363 return $this->getAttributesNS(''); 364 } 365 366 /** 367 * Retrieve all attributes of the element that are in the given namespace. 368 * 369 * @return array An associative array of attribute names and values. 370 * 371 * @author David Zülke <david.zuelke@bitextender.com> 372 * @since 1.0.0 373 */ 374 public function getAttributesNS($namespaceUri) 375 { 376 $retval = array(); 377 378 foreach($this->ownerDocument->getXpath()->query(sprintf('@*[namespace-uri() = "%s"]', $namespaceUri), $this) as $attribute) { 379 $retval[$attribute->localName] = $attribute->nodeValue; 380 } 381 382 return $retval; 383 } 384 385 /** 256 386 * Check whether or not the element has Agavi parameters as children. 257 387 * … … 264 394 { 265 395 if($this->ownerDocument->isAgaviConfiguration()) { 266 return $this->has Children('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST);396 return $this->has('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST); 267 397 } 268 398 … … 281 411 * 282 412 * @author Noah Fontes <noah.fontes@bitextender.com> 413 * @author David Zülke <david.zuelke@bitextender.com> 283 414 * @since 1.0.0 284 415 */ … … 289 420 290 421 if($this->ownerDocument->isAgaviConfiguration()) { 291 $elements = $this->get Children('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST);422 $elements = $this->get('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST); 292 423 293 424 foreach($elements as $element) { -
branches/felix-testing-implementation/src/validator/AgaviValidationManager.class.php
r2999 r3007 819 819 public function setError($name, $message) 820 820 { 821 $name = new AgaviValidationArgument($ fieldname);821 $name = new AgaviValidationArgument($name); 822 822 $incident = new AgaviValidationIncident(null, AgaviValidator::ERROR); 823 823 $incident->addError(new AgaviValidationError($message, null, array($name))); … … 842 842 $incident = new AgaviValidationIncident(null, AgaviValidator::ERROR); 843 843 foreach($errors as $name => $error) { 844 $name = new AgaviValidationArgument($ fieldname);844 $name = new AgaviValidationArgument($name); 845 845 $incident->addError(new AgaviValidationError($error, null, array($name))); 846 846 }

