Changeset 21883
- Timestamp:
- 09/11/09 09:27:08 (4 years ago)
- Files:
-
- components/yaml/trunk/lib/sfYaml.php (modified) (1 diff)
- components/yaml/trunk/lib/sfYamlInline.php (modified) (4 diffs)
- components/yaml/trunk/test/sfYamlDumperTest.php (modified) (1 diff)
- components/yaml/trunk/test/sfYamlInlineTest.php (modified) (1 diff)
- components/yaml/trunk/test/sfYamlParserTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
components/yaml/trunk/lib/sfYaml.php
r18321 r21883 19 19 class sfYaml 20 20 { 21 static protected 22 $spec = '1.2'; 23 24 /** 25 * Sets the YAML specification version to use. 26 * 27 * @param string $version The YAML specification version 28 */ 29 static public function setSpecVersion($version) 30 { 31 if (!in_array($version, array('1.1', '1.2'))) 32 { 33 throw new InvalidArgumentException(sprintf('Version %s of the YAML specifications is not supported', $version)); 34 } 35 36 self::$spec = $version; 37 } 38 39 /** 40 * Gets the YAML specification version to use. 41 * 42 * @return string The YAML specification version 43 */ 44 static public function getSpecVersion() 45 { 46 return self::$spec; 47 } 48 21 49 /** 22 50 * Loads YAML into a PHP array. components/yaml/trunk/lib/sfYamlInline.php
r21429 r21883 55 55 static public function dump($value) 56 56 { 57 $trueValues = '1.1' == sfYaml::getSpecVersion() ? array('true', 'on', '+', 'yes', 'y') : array('true'); 58 $falseValues = '1.1' == sfYaml::getSpecVersion() ? array('false', 'off', '-', 'no', 'n') : array('false'); 59 57 60 switch (true) 58 61 { … … 81 84 case preg_match(self::getTimestampRegex(), $value): 82 85 return "'$value'"; 83 case in_array(strtolower($value), array('true', 'on', '+', 'yes', 'y')):86 case in_array(strtolower($value), $trueValues): 84 87 return "'$value'"; 85 case in_array(strtolower($value), array('false', 'off', '-', 'no', 'n')):88 case in_array(strtolower($value), $falseValues): 86 89 return "'$value'"; 87 90 case in_array(strtolower($value), array('null', '~')): … … 360 363 $scalar = trim($scalar); 361 364 365 $trueValues = '1.1' == sfYaml::getSpecVersion() ? array('true', 'on', '+', 'yes', 'y') : array('true'); 366 $falseValues = '1.1' == sfYaml::getSpecVersion() ? array('false', 'off', '-', 'no', 'n') : array('false'); 367 362 368 switch (true) 363 369 { … … 376 382 $cast = intval($scalar); 377 383 return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw); 378 case in_array(strtolower($scalar), array('true', 'on', '+', 'yes', 'y')):384 case in_array(strtolower($scalar), $trueValues): 379 385 return true; 380 case in_array(strtolower($scalar), array('false', 'off', '-', 'no', 'n')):386 case in_array(strtolower($scalar), $falseValues): 381 387 return false; 382 388 case is_numeric($scalar): components/yaml/trunk/test/sfYamlDumperTest.php
r21429 r21883 10 10 11 11 require_once(dirname(__FILE__).'/lime/lime.php'); 12 require_once(dirname(__FILE__).'/../lib/sfYaml.php'); 12 13 require_once(dirname(__FILE__).'/../lib/sfYamlParser.php'); 13 14 require_once(dirname(__FILE__).'/../lib/sfYamlDumper.php'); 15 16 sfYaml::setSpecVersion('1.1'); 14 17 15 18 $t = new lime_test(142); components/yaml/trunk/test/sfYamlInlineTest.php
r19674 r21883 10 10 11 11 require_once(dirname(__FILE__).'/lime/lime.php'); 12 require_once(dirname(__FILE__).'/../lib/sfYaml.php'); 12 13 require_once(dirname(__FILE__).'/../lib/sfYamlInline.php'); 14 15 sfYaml::setSpecVersion('1.1'); 13 16 14 17 $t = new lime_test(118); components/yaml/trunk/test/sfYamlParserTest.php
r21429 r21883 10 10 11 11 require_once(dirname(__FILE__).'/lime/lime.php'); 12 require_once(dirname(__FILE__).'/../lib/sfYaml.php'); 12 13 require_once(dirname(__FILE__).'/../lib/sfYamlParser.php'); 14 15 sfYaml::setSpecVersion('1.1'); 13 16 14 17 $t = new lime_test(142);