Changeset 3001
- Timestamp:
- 10/08/08 18:28:51 (3 months ago)
- Location:
- branches/1.0
- Files:
-
- 4 modified
-
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) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/CHANGELOG
r2983 r3001 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/1.0/src/config/AgaviConfigHandlersConfigHandler.class.php
r2727 r3001 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/1.0/src/config/AgaviTestSuitesConfigHandler.class.php
r2893 r3001 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/1.0/src/config/util/dom/AgaviXmlConfigDomElement.class.php
r2942 r3001 3 3 class AgaviXmlConfigDomElement extends DOMElement implements IteratorAggregate 4 4 { 5 /**6 * Overloaded method for accessing child nodes. Does the pluralizing etc, and7 * 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.015 */16 public function __get($name) {17 // TODO: add {namespace}element support18 // should look into the default ns, IMO. otherwise, you gotta use getChild()19 // must use singular/plural handling20 }21 22 public function __isset($name) {23 // TODO: add {namespace}element support24 // should look into the default ns, IMO. otherwise, you gotta use hasChild()25 }26 27 5 public function __toString() 28 6 { … … 72 50 73 51 /** 52 * Convenience method to retrieve child elements of the given name. 53 * Accepts singular or plural forms of the name, and will detect and handle 54 * parent containers with plural names properly. 55 * 56 * @param string The name of the element(s) to check for. 57 * @param string The namespace URI. If null, the document default 58 * namespace will be used. If an empty string, no namespace 59 * will be used. 60 * 61 * @return DOMNodeList A list of the child elements. 62 * 63 * @author David Zülke <david.zuelke@bitextender.com> 64 * @since 1.0.0 65 */ 66 public function get($name, $namespaceUri = null) 67 { 68 return $this->getChildren($name, $namespaceUri, true); 69 } 70 71 /** 72 * Convenience method to check if there are child elements of the given name. 73 * Accepts singular or plural forms of the name, and will detect and handle 74 * parent containers with plural names properly. 75 * 76 * @param string The name of the element(s) to check for. 77 * @param string The namespace URI. If null, the document default 78 * namespace will be used. If an empty string, no namespace 79 * will be used. 80 * 81 * @return bool True if one or more child elements with the given name 82 * exist, false otherwise. 83 * 84 * @author David Zülke <david.zuelke@bitextender.com> 85 * @since 1.0.0 86 */ 87 public function has($name, $namespaceUri = null) 88 { 89 return $this->hasChildren($name, $namespaceUri, true); 90 } 91 92 /** 74 93 * Count the number of child elements with a given name. 75 94 * … … 78 97 * namespace will be used. If an empty string, no namespace 79 98 * will be used. 99 * @param bool Whether or not to apply automatic singular/plural 100 * handling that skips plural container elements. 80 101 * 81 102 * @return int The number of child elements with the given name. 82 103 * 83 104 * @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 105 * @author David Zülke <david.zuelke@bitextender.com> 106 * @since 1.0.0 107 */ 108 public function countChildren($name, $namespaceUri = null, $pluralMagic = false) 109 { 110 // if arg is null, then only check for elements from our default namespace 111 // if namespace uri is null, use default ns. if empty string, use no ns 90 112 $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); 113 114 // init our vars 115 $query = ''; 116 $singularName = null; 117 118 if($pluralMagic) { 119 // we always assume that we either get plural names, or the singular of the singular is not different from the singular :) 120 $singularName = $this->singularize($name); 121 if($namespaceUri) { 122 $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"])'; 123 } else { 124 $query = 'count(%1$s/%2$s) + count(%2$s)'; 125 } 96 126 } else { 97 return (int)$xpath->evaluate(sprintf('count(%2$s) + count(%1$s/%2$s)', $name, $singularName), $this); 98 } 127 if($namespaceUri) { 128 $query = 'count(child::*[local-name() = "%1$s" and namespace-uri() = "%3$s"])'; 129 } else { 130 $query = 'count(%1$s)'; 131 } 132 } 133 134 return (int)$this->ownerDocument->getXpath()->evaluate(sprintf($query, $name, $singularName, $namespaceUri), $this); 99 135 } 100 136 … … 107 143 * namespace will be used. If an empty string, no namespace 108 144 * will be used. 145 * @param bool Whether or not to apply automatic singular/plural 146 * handling that skips plural container elements. 109 147 * 110 148 * @return bool True if one or more child elements with the given name … … 112 150 * 113 151 * @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; 152 * @author David Zülke <david.zuelke@bitextender.com> 153 * @since 1.0.0 154 */ 155 public function hasChildren($name, $namespaceUri = null, $pluralMagic = false) 156 { 157 return $this->countChildren($name, $namespaceUri, $pluralMagic) !== 0; 119 158 } 120 159 … … 126 165 * namespace will be used. If an empty string, no namespace 127 166 * will be used. 167 * @param string Whether or not to apply pluralization magic in selects. 168 * @param bool Whether or not to apply automatic singular/plural 169 * handling that skips plural container elements. 128 170 * 129 171 * @return DOMNodeList A list of the child elements. 130 172 * 131 173 * @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 namespace174 * @author David Zülke <david.zuelke@bitextender.com> 175 * @since 1.0.0 176 */ 177 public function getChildren($name, $namespaceUri = null, $pluralMagic = false) 178 { 179 // if arg is null, then only check for elements from our default namespace 138 180 // if namespace uri is null, use default ns. if empty string, use no ns 139 181 $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); 182 183 // init our vars 184 $query = ''; 185 $singularName = null; 186 187 if($pluralMagic) { 188 // we always assume that we either get plural names, or the singular of the singular is not different from the singular :) 189 $singularName = $this->singularize($name); 190 if($namespaceUri) { 191 $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"]'; 192 } else { 193 $query = '%1$s/%2$s | %2$s'; 194 } 145 195 } else { 146 return $xpath->query(sprintf('%1$s/%2$s | %2$s', $name, $singularName), $this); 147 } 196 if($namespaceUri) { 197 $query = 'child::*[local-name() = "%1$s" and namespace-uri() = "%3$s"]'; 198 } else { 199 $query = '%1$s'; 200 } 201 } 202 203 return $this->ownerDocument->getXpath()->query(sprintf($query, $name, $singularName, $namespaceUri), $this); 148 204 } 149 205 … … 166 222 public function hasChild($name, $namespaceUri = null) 167 223 { 224 return $this->getChild($name, $namespaceUri) !== null; 225 } 226 227 /** 228 * Return a single child element with a given name. 229 * Only returns anything if there is exactly one child of this name. 230 * 231 * @param string The name of the element. 232 * @param string The namespace URI. If null, the document default 233 * namespace will be used. If an empty string, no namespace 234 * will be used. 235 * 236 * @return DOMElement The child element, or null if none exists. 237 * 238 * @author Noah Fontes <noah.fontes@bitextender.com> 239 * @author David Zülke <david.zuelke@bitextender.com> 240 * @since 1.0.0 241 */ 242 public function getChild($name, $namespaceUri = null) 243 { 244 // if arg is null, then only check for elements from our default namespace 168 245 // 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; 246 $namespaceUri = ($namespaceUri === null ? $this->ownerDocument->getDefaultNamespaceUri() : $namespaceUri); 247 248 if($namespaceUri) { 249 $query = 'self::node()[count(child::*[local-name() = "%1$s" and namespace-uri() = "%2$s"]) = 1]/*[local-name() = "%1$s" and namespace-uri() = "%2$s"]'; 250 } else { 251 $query = 'self::node()[count(child::%1$s) = 1]/%1$s'; 252 } 253 254 return $this->ownerDocument->getXpath()->query(sprintf($query, $name, $namespaceUri), $this)->item(0); 196 255 } 197 256 … … 264 323 { 265 324 if($this->ownerDocument->isAgaviConfiguration()) { 266 return $this->has Children('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST);325 return $this->has('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST); 267 326 } 268 327 … … 281 340 * 282 341 * @author Noah Fontes <noah.fontes@bitextender.com> 342 * @author David Zülke <david.zuelke@bitextender.com> 283 343 * @since 1.0.0 284 344 */ … … 289 349 290 350 if($this->ownerDocument->isAgaviConfiguration()) { 291 $elements = $this->get Children('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST);351 $elements = $this->get('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST); 292 352 293 353 foreach($elements as $element) {

