Changeset 8133
- Timestamp:
- 03/28/08 10:30:13 (5 months ago)
- Files:
-
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/addon/sfPropelData.class.php (modified) (6 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5ObjectBuilder.php (modified) (2 diffs)
- branches/dwhittle/1.1/lib/util/sfYamlParser.class.php (modified) (8 diffs)
- branches/dwhittle/1.1/test/unit/util/fixtures/yaml/YtsAnchorAlias.yml (modified) (1 diff)
- branches/dwhittle/1.1/test/unit/util/fixtures/yaml/YtsSpecificationExamples.yml (modified) (7 diffs)
- branches/dwhittle/1.1/test/unit/util/fixtures/yaml/index.yml (modified) (1 diff)
- branches/dwhittle/1.1/test/unit/util/fixtures/yaml/sfMergeKey.yml (copied) (copied from branches/1.1/test/unit/util/fixtures/yaml/sfMergeKey.yml)
- branches/dwhittle/1.1/test/unit/util/sfYamlParserTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/addon/sfPropelData.class.php
r7918 r8133 96 96 { 97 97 // create a new entry in the database 98 if (!class_exists($class)) 99 { 100 throw new InvalidArgumentException(sprintf('Unknown class "%s".', $class)); 101 } 102 98 103 $obj = new $class(); 99 104 100 105 if (!$obj instanceof BaseObject) 101 106 { 102 throw new Exception(sprintf('The class "%s" is not a Propel class. This probably means there is already a class named "%s" somewhere in symfony or in your project.', $class, $class));107 throw new RuntimeException(sprintf('The class "%s" is not a Propel class. This probably means there is already a class named "%s" somewhere in symfony or in your project.', $class, $class)); 103 108 } 104 109 105 110 if (!is_array($data)) 106 111 { 107 throw new Exception(sprintf('You must give a name for each fixture data entry (class %s)', $class));112 throw new InvalidArgumentException(sprintf('You must give a name for each fixture data entry (class %s).', $class)); 108 113 } 109 114 … … 137 142 if (!isset($this->object_references[$relatedTable->getPhpName().'_'.$value])) 138 143 { 139 throw new sfException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedTable->getPhpName()));144 throw new InvalidArgumentException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedTable->getPhpName())); 140 145 } 141 146 $value = $this->object_references[$relatedTable->getPhpName().'_'.$value]->getPrimaryKey(); … … 153 158 else 154 159 { 155 throw new sfException(sprintf('Column "%s" does not exist for class "%s"', $name, $class));160 throw new InvalidArgumentException(sprintf('Column "%s" does not exist for class "%s".', $name, $class)); 156 161 } 157 162 } … … 189 194 if (!isset($relatedClass)) 190 195 { 191 throw new sfException(sprintf('Unable to find the many-to-many relationship for object "%s"', get_class($obj)));196 throw new InvalidArgumentException(sprintf('Unable to find the many-to-many relationship for object "%s".', get_class($obj))); 192 197 } 193 198 … … 199 204 if (!isset($this->object_references[$relatedClass.'_'.$value])) 200 205 { 201 throw new sfException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedClass));206 throw new InvalidArgumentException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedClass)); 202 207 } 203 208 … … 245 250 { 246 251 continue; 252 } 253 254 // Check that peer class exists before calling doDeleteAll() 255 if (!class_exists($class.'Peer')) 256 { 257 throw new InvalidArgumentException(sprintf('Unknown class "%sPeer".', $class)); 247 258 } 248 259 branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5ObjectBuilder.php
r7989 r8133 2 2 3 3 /* 4 * $Id: PHP5ObjectBuilder.php 10 06 2008-03-19 15:30:19Z hans $4 * $Id: PHP5ObjectBuilder.php 1017 2008-03-27 17:58:03Z hans $ 5 5 * 6 6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS … … 3275 3275 $vars[] = $varName; 3276 3276 $script .= " 3277 \$this->{$varName}->clearAllReferences(\$deep);"; 3277 if (\$this->$varName) { 3278 \$this->{$varName}->clearAllReferences(\$deep); 3279 }"; 3278 3280 } else { 3279 3281 $varName = $this->getRefFKCollVarName($refFK); 3280 3282 $vars[] = $varName; 3281 3283 $script .= " 3282 foreach (\$this->$varName as \$o) { 3283 \$o->clearAllReferences(\$deep); 3284 if (\$this->$varName) { 3285 foreach((array) \$this->$varName as \$o) { 3286 \$o->clearAllReferences(\$deep); 3287 } 3284 3288 }"; 3285 3289 } branches/dwhittle/1.1/lib/util/sfYamlParser.class.php
r7927 r8133 26 26 $lines = array(), 27 27 $currentLineNb = -1, 28 $currentLine = ''; 28 $currentLine = '', 29 $refs = array(); 29 30 30 31 /** … … 66 67 } 67 68 69 $isRef = $isInPlace = false; 68 70 if (preg_match('#^\-(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values)) 69 71 { 72 if (isset($values['value']) && preg_match('#^&(?P<ref>\w+) *(?P<value>.*)#', $values['value'], $matches)) 73 { 74 $isRef = $matches['ref']; 75 $values['value'] = $matches['value']; 76 } 77 70 78 // array 71 79 if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) … … 73 81 $c = $this->getRealCurrentLineNb() + 1; 74 82 $parser = new sfYamlParser($c); 83 $parser->refs =& $this->refs; 75 84 $data[] = $parser->parse($this->getNextEmbedBlock()); 76 85 } … … 83 92 { 84 93 $key = sfYamlInline::parseScalar($values['key']); 94 95 if ('<<' === $key) 96 { 97 if (isset($values['value']) && '*' === substr($values['value'], 0, 1)) 98 { 99 $isInPlace = substr($values['value'], 1); 100 if (!array_key_exists($isInPlace, $this->refs)) 101 { 102 throw new InvalidArgumentException(sprintf('Reference "%s" does not exist on line %s.', $isInPlace, $this->currentLine)); 103 } 104 } 105 else 106 { 107 throw new InvalidArgumentException(sprintf('In place substitution must point to a reference on line %s.', $this->currentLine)); 108 } 109 } 110 else if (isset($values['value']) && preg_match('#^&(?P<ref>\w+) *(?P<value>.*)#', $values['value'], $matches)) 111 { 112 $isRef = $matches['ref']; 113 $values['value'] = $matches['value']; 114 } 85 115 86 116 // hash … … 96 126 $c = $this->getRealCurrentLineNb() + 1; 97 127 $parser = new sfYamlParser($c); 128 $parser->refs =& $this->refs; 98 129 $data[$key] = $parser->parse($this->getNextEmbedBlock()); 99 130 } … … 101 132 else 102 133 { 103 $data[$key] = $this->parseValue($values['value']); 134 if ($isInPlace) 135 { 136 $data = $this->refs[$isInPlace]; 137 } 138 else 139 { 140 $data[$key] = $this->parseValue($values['value']); 141 } 104 142 } 105 143 } … … 114 152 throw new InvalidArgumentException(sprintf('Unable to parse line %d (%s).', $this->getRealCurrentLineNb(), $this->currentLine)); 115 153 } 154 155 if ($isRef) 156 { 157 $this->refs[$isRef] = end($data); 158 } 116 159 } 117 160 … … 227 270 protected function parseValue($value) 228 271 { 272 if ('*' === substr($value, 0, 1)) 273 { 274 if (false !== $pos = strpos($value, '#')) 275 { 276 $value = substr($value, 1, $pos - 2); 277 } 278 else 279 { 280 $value = substr($value, 1); 281 } 282 283 if (!array_key_exists($value, $this->refs)) 284 { 285 throw new InvalidArgumentException(sprintf('Reference "%s" does not exist (%s).', $value, $this->currentLine)); 286 } 287 return $this->refs[$value]; 288 } 289 229 290 if (preg_match('/^(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?$/', $value, $matches)) 230 291 { branches/dwhittle/1.1/test/unit/util/fixtures/yaml/YtsAnchorAlias.yml
r7989 r8133 14 14 - Oren 15 15 - *showell 16 python: |17 [18 [ 'Steve', 'Clark', 'Brian', 'Oren', 'Steve']19 ]20 ruby-setup: |21 showell = 'Steve'22 ruby: |23 [ showell, 'Clark', 'Brian', 'Oren', showell ]24 16 php: | 25 array('&showell Steve', 'Clark', 'Brian', 'Oren', '*showell') 17 array('Steve', 'Clark', 'Brian', 'Oren', 'Steve') 18 26 19 --- 27 #test: Alias of a Mapping 28 #brief: > 29 # An alias can be used on any item of data, including 30 # sequences, mappings, and other complex data types. 31 #yaml: | 32 # - &hello 33 # Meat: pork 34 # Starch: potato 35 # - banana 36 # - *hello 37 #python: | 38 # [ 39 # [ 40 # {'Meat': 'pork', 'Starch': 'potato'}, 41 # 'banana', 42 # {'Meat': 'pork', 'Starch': 'potato'}, 43 # ] 44 # ] 45 #ruby-setup: | 46 # hello = { 'Meat' => 'pork', 'Starch' => 'potato' } 47 #ruby: | 48 # [ 49 # hello, 50 # 'banana', 51 # hello 52 # ] 53 #php: | 54 # array(array('Meat' => 'pork', 'Starch' => 'potato')) 20 test: Alias of a Mapping 21 brief: > 22 An alias can be used on any item of data, including 23 sequences, mappings, and other complex data types. 24 yaml: | 25 - &hello 26 Meat: pork 27 Starch: potato 28 - banana 29 - *hello 30 php: | 31 array(array('Meat'=>'pork', 'Starch'=>'potato'), 'banana', array('Meat'=>'pork', 'Starch'=>'potato')) branches/dwhittle/1.1/test/unit/util/fixtures/yaml/YtsSpecificationExamples.yml
r7927 r8133 215 215 --- 216 216 test: Node for Sammy Sosa appears twice in this document 217 todo: true218 217 spec: 2.10 219 218 yaml: | … … 226 225 - *SS # Subsequent occurance 227 226 - Ken Griffey 228 perl: | 229 { 230 'hr' => [ 'Mark McGwire', 'Sammy Sosa' ], 231 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] 232 } 233 python: | 234 [{ 235 'hr': [ 'Mark McGwire', 'Sammy Sosa' ], 236 'rbi': [ 'Sammy Sosa', 'Ken Griffey' ] 237 }] 238 ruby: | 239 { 240 'hr' => 241 [ 'Mark McGwire', 'Sammy Sosa' ], 242 'rbi' => 243 [ 'Sammy Sosa', 'Ken Griffey' ] 244 } 245 syck: | 246 struct test_node seq1[] = { 247 { T_STR, 0, "Mark McGwire" }, 248 { T_STR, 0, "Sammy Sosa" }, 249 end_node 250 }; 251 struct test_node seq2[] = { 252 { T_STR, 0, "Sammy Sosa" }, 253 { T_STR, 0, "Ken Griffey" }, 254 end_node 255 }; 256 struct test_node map[] = { 257 { T_STR, 0, "hr" }, 258 { T_SEQ, 0, 0, seq1 }, 259 { T_STR, 0, "rbi" }, 260 { T_SEQ, 0, 0, seq2 }, 261 end_node 262 }; 263 struct test_node stream[] = { 264 { T_MAP, 0, 0, map }, 265 end_node 266 }; 267 227 php: | 228 array( 229 'hr' => 230 array('Mark McGwire', 'Sammy Sosa'), 231 'rbi' => 232 array('Sammy Sosa', 'Ken Griffey') 233 ) 268 234 --- 269 235 test: Mapping between sequences … … 737 703 --- 738 704 test: Invoice 739 todo: true705 dump_skip: true 740 706 spec: 2.27 741 707 yaml: | … … 755 721 ship-to: *id001 756 722 product: 757 - sku : BL394D 723 - 724 sku : BL394D 758 725 quantity : 4 759 726 description : Basketball 760 727 price : 450.00 761 - sku : BL4438H 728 - 729 sku : BL4438H 762 730 quantity : 1 763 731 description : Super Hoop … … 769 737 Backup contact is Nancy 770 738 Billsmer @ 338-4338. 771 ruby-setup: | 772 YAML.add_domain_type( "clarkevans.com,2002", "invoice" ) { |type, val| val } 773 id001 = { 'given' => 'Chris', 'family' => 'Dumars', 'address' => 774 { 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 775 'state' => 'MI', 'postal' => 48046 } } 776 ruby: | 777 { 778 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ), 779 'bill-to' => id001, 'ship-to' => id001, 'product' => 780 [ { 'sku' => 'BL394D', 'quantity' => 4, 781 'description' => 'Basketball', 'price' => 450.00 }, 782 { 'sku' => 'BL4438H', 'quantity' => 1, 783 'description' => 'Super Hoop', 'price' => 2392.00 } ], 739 php: | 740 array( 741 'invoice' => 34843, 'date' => mktime(0, 0, 0, 1, 23, 2001), 742 'bill-to' => 743 array( 'given' => 'Chris', 'family' => 'Dumars', 'address' => array( 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 ) ) 744 , 'ship-to' => 745 array( 'given' => 'Chris', 'family' => 'Dumars', 'address' => array( 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 ) ) 746 , 'product' => 747 array( 748 array( 'sku' => 'BL394D', 'quantity' => 4, 'description' => 'Basketball', 'price' => 450.00 ), 749 array( 'sku' => 'BL4438H', 'quantity' => 1, 'description' => 'Super Hoop', 'price' => 2392.00 ) 750 ), 784 751 'tax' => 251.42, 'total' => 4443.52, 785 'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" } 752 'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" 753 ) 786 754 --- 787 755 test: Log file … … 1047 1015 --- 1048 1016 test: Overriding anchors 1049 todo: true1050 1017 yaml: | 1051 1018 anchor : &A001 This scalar has an anchor. … … 1054 1021 repeated use of this value. 1055 1022 alias : *A001 1056 ruby: | 1057 { 'anchor' => 'This scalar has an anchor.', 1058 'override' => "The alias node below is a repeated use of this value.\n", 1059 'alias' => "The alias node below is a repeated use of this value.\n" } 1060 syck: | 1061 struct test_node map[] = { 1062 { T_STR, 0, "anchor" }, 1063 { T_STR, 0, "This scalar has an anchor." }, 1064 { T_STR, 0, "override" }, 1065 { T_STR, 0, "The alias node below is a repeated use of this value.\n" }, 1066 { T_STR, 0, "alias" }, 1067 { T_STR, 0, "The alias node below is a repeated use of this value.\n" }, 1068 end_node 1069 }; 1070 struct test_node stream[] = { 1071 { T_MAP, 0, 0, map }, 1072 end_node 1073 }; 1074 1023 php: | 1024 array( 'anchor' => 'This scalar has an anchor.', 1025 'override' => "The alias node below is a repeated use of this value.\n", 1026 'alias' => "The alias node below is a repeated use of this value.\n" ) 1075 1027 --- 1076 1028 test: Flow and block formatting branches/dwhittle/1.1/test/unit/util/fixtures/yaml/index.yml
r7989 r8133 2 2 - sfTests 3 3 - sfObjects 4 - sfMergeKey 4 5 - YtsAnchorAlias 5 6 - YtsBasicTests branches/dwhittle/1.1/test/unit/util/sfYamlParserTest.php
r7989 r8133 12 12 require_once(dirname(__FILE__).'/../../../lib/util/sfYamlParser.class.php'); 13 13 14 $t = new lime_test(136, new lime_output_color()); 14 $t = new lime_test(138, new lime_output_color()); 15 15 16 $parser = new sfYamlParser(); 16 17