当前位置: 首页>>代码示例>>PHP>>正文


PHP sfYaml::getSpecVersion方法代码示例

本文整理汇总了PHP中sfYaml::getSpecVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP sfYaml::getSpecVersion方法的具体用法?PHP sfYaml::getSpecVersion怎么用?PHP sfYaml::getSpecVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfYaml的用法示例。


在下文中一共展示了sfYaml::getSpecVersion方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upgrade

 public function upgrade()
 {
     $specVersion = sfYaml::getSpecVersion();
     $queue = array();
     $success = true;
     $finder = sfFinder::type('file')->name('*.yml')->prune('vendor');
     foreach ($finder->in(sfConfig::get('sf_root_dir')) as $file) {
         // attempt to upgrade booleans
         $original = file_get_contents($file);
         $upgraded = sfToolkit::pregtr($original, array('/^([^:]+: +)(?:on|y(?:es)?|\\+)(\\s*(#.*)?)$/im' => '\\1true\\2', '/^([^:]+: +)(?:off|no?|-)(\\s*(#.*)?)$/im' => '\\1false\\2'));
         try {
             sfYaml::setSpecVersion('1.1');
             $yaml11 = sfYaml::load($original);
             sfYaml::setSpecVersion('1.2');
             $yaml12 = sfYaml::load($upgraded);
         } catch (Exception $e) {
             // unable to load the YAML
             $yaml11 = 'foo';
             $yaml12 = 'bar';
         }
         if ($yaml11 == $yaml12) {
             if ($original != $upgraded) {
                 $this->getFilesystem()->touch($file);
                 file_put_contents($file, $upgraded);
             }
         } else {
             $this->logSection('yaml', 'Unable to upgrade ' . sfDebug::shortenFilePath($file), null, 'ERROR');
             // force project to use YAML 1.1 spec
             if ('1.1' != $specVersion) {
                 $specVersion = '1.1';
                 $class = sfClassManipulator::fromFile(sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php');
                 $original = $class->getCode();
                 $modified = $class->wrapMethod('setup', 'sfYaml::setSpecVersion(\'1.1\');');
                 if ($original != $modified && $this->askConfirmation(array('Unable to convert YAML file:', sfDebug::shortenFilePath($file), '', 'Would you like to force YAML to be parsed with the 1.1 specification? (Y/n)'), 'QUESTION_LARGE')) {
                     $this->logSection('yaml', 'Forcing YAML 1.1 spec');
                     $this->getFilesystem()->touch($class->getFile());
                     $class->save();
                 } else {
                     $this->logBlock(array('Unable to either upgrade YAML files or force 1.1 spec.', '(see UPGRADE_TO_1_3 file for more information)'), 'ERROR_LARGE');
                 }
             }
             $success = false;
         }
     }
     if ($success && '1.1' == $specVersion) {
         $file = sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php';
         $original = file_get_contents($file);
         $modified = preg_replace('/^\\s*sfYaml::setSpecVersion\\(\'1\\.1\'\\);\\n/im', '', $original);
         if ($original != $modified) {
             $this->logSection('yaml', 'Removing setting of YAML 1.1 spec');
             $this->getFilesystem()->touch($file);
             file_put_contents($file, $modified);
         }
     }
 }
开发者ID:souravmondal-cn,项目名称:symfonyweather,代码行数:55,代码来源:sfYamlUpgrade.class.php

示例2: __construct

 public function __construct($data)
 {
     try {
         $version = sfYaml::getSpecVersion();
         sfYaml::setSpecVersion('1.2');
         $this->data = $this->parse($data);
         sfYaml::setSpecVersion($version);
     } catch (InvalidArgumentException $e) {
         $this->errors[] = $e->getMessage();
     }
 }
开发者ID:pkdevbox,项目名称:mootools-forge,代码行数:11,代码来源:ForgeYamlParser.class.php

示例3: getYaml

 public function getYaml($entities, $locale)
 {
     // Use the Zend copy of this script to prevent class conflicts when RailsYaml is included
     require_once 'thirdparty/zend_translate_railsyaml/library/Translate/Adapter/thirdparty/sfYaml/lib' . '/sfYamlDumper.php';
     // Unflatten array
     $entitiesNested = array();
     foreach ($entities as $entity => $spec) {
         // Legacy support: Don't count *.ss as namespace
         $entity = preg_replace('/\\.ss\\./', '___ss.', $entity);
         $parts = explode('.', $entity);
         $currLevel =& $entitiesNested;
         while ($part = array_shift($parts)) {
             $part = str_replace('___ss', '.ss', $part);
             if (!isset($currLevel[$part])) {
                 $currLevel[$part] = array();
             }
             $currLevel =& $currLevel[$part];
         }
         $currLevel = $spec[0];
     }
     // Write YAML
     $oldVersion = sfYaml::getSpecVersion();
     sfYaml::setSpecVersion('1.1');
     $yamlHandler = new sfYaml();
     // TODO Dumper can't handle YAML comments, so the context information is currently discarded
     $result = $yamlHandler->dump(array($locale => $entitiesNested), 99);
     sfYaml::setSpecVersion($oldVersion);
     return $result;
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:29,代码来源:i18nTextCollector.php

示例4: evaluateScalar

 /**
  * Evaluates scalars and replaces magic values.
  *
  * @param string $scalar
  *
  * @return string A YAML string
  */
 protected static function evaluateScalar($scalar)
 {
     $scalar = trim($scalar);
     $trueValues = '1.1' == sfYaml::getSpecVersion() ? array('true', 'on', '+', 'yes', 'y') : array('true');
     $falseValues = '1.1' == sfYaml::getSpecVersion() ? array('false', 'off', '-', 'no', 'n') : array('false');
     switch (true) {
         case 'null' == strtolower($scalar):
         case '' == $scalar:
         case '~' == $scalar:
             return null;
         case 0 === strpos($scalar, '!str'):
             return (string) substr($scalar, 5);
         case 0 === strpos($scalar, '! '):
             return intval(self::parseScalar(substr($scalar, 2)));
         case 0 === strpos($scalar, '!!php/object:'):
             return unserialize(substr($scalar, 13));
         case ctype_digit($scalar):
             $raw = $scalar;
             $cast = intval($scalar);
             return '0' == $scalar[0] ? octdec($scalar) : ((string) $raw == (string) $cast ? $cast : $raw);
         case in_array(strtolower($scalar), $trueValues):
             return true;
         case in_array(strtolower($scalar), $falseValues):
             return false;
         case is_numeric($scalar):
             return '0x' == $scalar[0] . $scalar[1] ? hexdec($scalar) : floatval($scalar);
         case 0 == strcasecmp($scalar, '.inf'):
         case 0 == strcasecmp($scalar, '.NaN'):
             return -log(0);
         case 0 == strcasecmp($scalar, '-.inf'):
             return log(0);
         case preg_match('/^(-|\\+)?[0-9,]+(\\.[0-9]+)?$/', $scalar):
             return floatval(str_replace(',', '', $scalar));
         case preg_match(self::getTimestampRegex(), $scalar):
             return strtotime($scalar);
         default:
             return (string) $scalar;
     }
 }
开发者ID:SandeepUmredkar,项目名称:PortalSMIP,代码行数:46,代码来源:sfYamlInline.php


注:本文中的sfYaml::getSpecVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。