Development

Changeset 21883

You must first sign up to be able to contribute.

Changeset 21883

Show
Ignore:
Timestamp:
09/11/09 09:27:08 (4 years ago)
Author:
fabien
Message:

[yaml] started support for the 1.2 YAML specification

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • components/yaml/trunk/lib/sfYaml.php

    r18321 r21883  
    1919class sfYaml 
    2020{ 
     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 
    2149  /** 
    2250   * Loads YAML into a PHP array. 
  • components/yaml/trunk/lib/sfYamlInline.php

    r21429 r21883  
    5555  static public function dump($value) 
    5656  { 
     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 
    5760    switch (true) 
    5861    { 
     
    8184      case preg_match(self::getTimestampRegex(), $value): 
    8285        return "'$value'"; 
    83       case in_array(strtolower($value), array('true', 'on', '+', 'yes', 'y')): 
     86      case in_array(strtolower($value), $trueValues): 
    8487        return "'$value'"; 
    85       case in_array(strtolower($value), array('false', 'off', '-', 'no', 'n')): 
     88      case in_array(strtolower($value), $falseValues): 
    8689        return "'$value'"; 
    8790      case in_array(strtolower($value), array('null', '~')): 
     
    360363    $scalar = trim($scalar); 
    361364 
     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 
    362368    switch (true) 
    363369    { 
     
    376382        $cast = intval($scalar); 
    377383        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): 
    379385        return true; 
    380       case in_array(strtolower($scalar), array('false', 'off', '-', 'no', 'n')): 
     386      case in_array(strtolower($scalar), $falseValues): 
    381387        return false; 
    382388      case is_numeric($scalar): 
  • components/yaml/trunk/test/sfYamlDumperTest.php

    r21429 r21883  
    1010 
    1111require_once(dirname(__FILE__).'/lime/lime.php'); 
     12require_once(dirname(__FILE__).'/../lib/sfYaml.php'); 
    1213require_once(dirname(__FILE__).'/../lib/sfYamlParser.php'); 
    1314require_once(dirname(__FILE__).'/../lib/sfYamlDumper.php'); 
     15 
     16sfYaml::setSpecVersion('1.1'); 
    1417 
    1518$t = new lime_test(142); 
  • components/yaml/trunk/test/sfYamlInlineTest.php

    r19674 r21883  
    1010 
    1111require_once(dirname(__FILE__).'/lime/lime.php'); 
     12require_once(dirname(__FILE__).'/../lib/sfYaml.php'); 
    1213require_once(dirname(__FILE__).'/../lib/sfYamlInline.php'); 
     14 
     15sfYaml::setSpecVersion('1.1'); 
    1316 
    1417$t = new lime_test(118); 
  • components/yaml/trunk/test/sfYamlParserTest.php

    r21429 r21883  
    1010 
    1111require_once(dirname(__FILE__).'/lime/lime.php'); 
     12require_once(dirname(__FILE__).'/../lib/sfYaml.php'); 
    1213require_once(dirname(__FILE__).'/../lib/sfYamlParser.php'); 
     14 
     15sfYaml::setSpecVersion('1.1'); 
    1316 
    1417$t = new lime_test(142);