Changeset 10832
- Timestamp:
- 08/13/08 09:46:08 (5 months ago)
- Files:
-
- branches/1.2/UPGRADE_TO_1_2 (modified) (1 diff)
- branches/1.2/lib/yaml/sfYamlParser.class.php (modified) (4 diffs)
- branches/1.2/test/unit/yaml/fixtures/sfMergeKey.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/UPGRADE_TO_1_2
r10830 r10832 97 97 98 98 The browser class also automatically expires cookies as per the `expire` value of each cookie. 99 100 YAML 101 ---- 102 103 The YAML parser now supports full merge key (see http://yaml.org/type/merge.html for more examples). 104 105 [php] 106 $yaml = new sfYamlParser(); 107 108 print_r($yaml->parse(<<<EOF 109 default_param: &default_param 110 datasource: propel 111 phptype: mysql 112 hostspec: localhost 113 database: db 114 username: user 115 password: pass 116 117 param: 118 <<: *default_param 119 username: myuser 120 password: mypass 121 EOF 122 )); 123 124 // displays 125 Array 126 ( 127 [default_param] => Array 128 ( 129 [datasource] => propel 130 [phptype] => mysql 131 [hostspec] => localhost 132 [database] => db 133 [username] => user 134 [password] => pass 135 ) 136 137 [param] => Array 138 ( 139 [datasource] => propel 140 [phptype] => mysql 141 [hostspec] => localhost 142 [database] => db 143 [username] => myuser 144 [password] => mypass 145 ) 146 147 ) branches/1.2/lib/yaml/sfYamlParser.class.php
r10740 r10832 67 67 } 68 68 69 $isRef = $isInPlace = false;69 $isRef = $isInPlace = $isProcessed = false; 70 70 if (preg_match('#^\-(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values)) 71 71 { … … 112 112 else 113 113 { 114 throw new InvalidArgumentException(sprintf('In place substitution must point to a reference at line %s (%s).', $this->getRealCurrentLineNb() + 1, $this->currentLine)); 114 if (isset($values['value']) && $values['value'] !== '') 115 { 116 $value = $values['value']; 117 } 118 else 119 { 120 $value = $this->getNextEmbedBlock(); 121 } 122 $c = $this->getRealCurrentLineNb() + 1; 123 $parser = new sfYamlParser($c); 124 $parser->refs =& $this->refs; 125 $parsed = $parser->parse($value); 126 127 $merged = array(); 128 if (!is_array($parsed)) 129 { 130 throw new InvalidArgumentException(sprintf("YAML merge keys used with a scalar value instead of an array at line %s (%s)", $this->getRealCurrentLineNb() + 1, $this->currentLine)); 131 } 132 else if (isset($parsed[0])) 133 { 134 // Numeric array, merge individual elements 135 foreach (array_reverse($parsed) as $parsedItem) 136 { 137 if (!is_array($parsedItem)) 138 { 139 throw new InvalidArgumentException(sprintf("Merge items must be arrays at line %s (%s).", $this->getRealCurrentLineNb() + 1, $parsedItem)); 140 } 141 $merged = array_merge($parsedItem, $merged); 142 } 143 } 144 else 145 { 146 // Associative array, merge 147 $merged = array_merge($merge, $parsed); 148 } 149 150 $isProcessed = $merged; 115 151 } 116 152 } … … 121 157 } 122 158 159 if ($isProcessed) 160 { 161 // Merge keys 162 $data = $isProcessed; 163 } 123 164 // hash 124 if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#'))165 else if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) 125 166 { 126 167 // if next line is less indented or equal, then it means that the current value is null … … 154 195 if (1 == count(explode("\n", rtrim($this->value, "\n")))) 155 196 { 156 return sfYamlInline::load($this->lines[0]); 197 $value = sfYamlInline::load($this->lines[0]); 198 if (is_array($value)) 199 { 200 $first = reset($value); 201 if ('*' === substr($first, 0, 1)) 202 { 203 $data = array(); 204 foreach ($value as $alias) 205 { 206 $data[] = $this->refs[substr($alias, 1)]; 207 } 208 $value = $data; 209 } 210 } 211 212 return $value; 157 213 } 158 214 branches/1.2/test/unit/yaml/fixtures/sfMergeKey.yml
r8111 r10832 8 8 yaml: | 9 9 foo: &foo 10 -Steve11 -Clark12 -Brian13 bar: 10 a: Steve 11 b: Clark 12 c: Brian 13 bar: &bar 14 14 <<: *foo 15 - Oren 15 x: Oren 16 foo2: &foo2 17 a: Ballmer 18 ding: &dong [ fi, fei, fo, fam] 19 check: 20 <<: 21 - *foo 22 - *dong 23 isit: tested 24 head: 25 <<: [ *foo , *dong , *foo2 ] 16 26 php: | 17 array('foo' => array(' Steve', 'Clark', 'Brian'), 'bar' => array('Steve', 'Clark', 'Brian', 'Oren'))27 array('foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian'), 'bar' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'x' => 'Oren'), 'foo2' => array('a' => 'Ballmer'), 'ding' => array('fi', 'fei', 'fo', 'fam'), 'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'), 'head' => array('a' => 'Ballmer', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam'))