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


PHP sfYamlParser::parse方法代码示例

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


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

示例1: __construct

 public function __construct()
 {
     parent::__construct();
     $this->specs = array();
     $this->tests = array();
     $parser = new sfYamlParser();
     $m = new Proust\Proust(array("enableCache" => true, "cacheDir" => dirname(__FILE__) . "/spec.cache", "compilerOptions" => array("beautify" => false, "includeDynamicPartials" => true)));
     $m->clearCache();
     $methods = array();
     foreach (glob(SPEC_DIR . "*.yml") as $file) {
         $name = str_replace(".yml", "", basename($file));
         $contents = file_get_contents($file);
         /* hack around sfyaml */
         $contents = str_replace("!code", "", $contents);
         $yaml = $parser->parse($contents);
         $yaml["name"] = $name;
         $i = 0;
         foreach ($yaml["tests"] as &$test) {
             if (array_key_exists("lambda", $test["data"])) {
                 $code = "return function (\$text = \"\") { " . $test["data"]["lambda"]["php"] . " };";
                 $test["data"]["lambda"] = eval($code);
             }
             $name = preg_replace('/[^a-zA-Z0-9]/', '_', $name);
             $test["method_name"] = "{$name}" . "_" . $i;
             array_push($methods, array($test["method_name"], $test["template"]));
             $this->tests[$name . "_{$i}"] = $test;
             $i++;
         }
         $this->specs[$name] = $yaml;
     }
     $classCode = $m->compileClass("Specs", $methods);
     eval($classCode);
     $m = new Proust\Proust(array("enableCache" => false));
     $this->obj = new Specs($m);
 }
开发者ID:sebcode,项目名称:proust,代码行数:35,代码来源:testSpec.php

示例2: __construct

 public function __construct($api_conf_file)
 {
     $this->api_conf_file = $api_conf_file;
     if (!class_exists('sfYamlParser')) {
         $this->api_last_error = "Symfony YAML (https://github.com/fabpot/yaml) not found or misconfigured";
         $this->api_created = false;
     } elseif (!function_exists('curl_init')) {
         $this->api_last_error = "No support found for cURL (http://www.php.net/manual/en/book.curl.php)";
         $this->api_created = false;
     } elseif (!function_exists('json_decode') || !function_exists('json_encode')) {
         $this->api_last_error = "No support found for json (http://fr2.php.net/manual/en/book.json.php)";
         $this->api_created = false;
     } else {
         try {
             $yaml = new sfYamlParser();
             if (!file_exists($api_conf_file) || !is_file($api_conf_file) || !is_readable($api_conf_file)) {
                 $this->api_last_error = "Unable to find/read the YAML api_conf_file : {$api_conf_file}";
                 $this->api_created = false;
             } else {
                 $values = $yaml->parse(file_get_contents($api_conf_file));
                 $this->api_conf = json_decode(json_encode($values));
                 $this->client_id = $this->api_conf->App->client_id;
                 $this->client_secret = $this->api_conf->App->client_secret;
                 $this->auth_url = $this->api_conf->App->auth_url;
                 $this->access_token_url = $this->api_conf->App->access_token_url;
                 $this->redirect_uri = $this->api_conf->App->redirect_uri;
                 $this->api_base_url = $this->api_conf->App->api_base_url;
                 $this->api_created = true;
             }
         } catch (InvalidArgumentException $e) {
             $this->api_last_error = "Unable to parse the YAML string: " . $e->getMessage();
             $this->api_created = false;
         }
     }
 }
开发者ID:Green-Cat,项目名称:runkeeperAPI,代码行数:35,代码来源:runkeeperAPI.class.php

示例3: load

 /**
  * Loads YAML into a PHP array.
  *
  * The load method, when supplied with a YAML stream (string or file),
  * will do its best to convert YAML in a file into a PHP array.
  *
  *  Usage:
  *  <code>
  *   $array = sfYaml::load('config.yml');
  *   print_r($array);
  *  </code>
  *
  * @param string $input Path of YAML file or string containing YAML
  *
  * @return array The YAML converted to a PHP array
  *
  * @throws InvalidArgumentException If the YAML is not valid
  */
 public static function load($input, $encoding = 'UTF-8')
 {
     $file = '';
     // if input is a file, process it
     if (strpos($input, "\n") === false && is_file($input)) {
         $file = $input;
         ob_start();
         $retval = (include $input);
         $content = ob_get_clean();
         // if an array is returned by the config file assume it's in plain php form else in YAML
         $input = is_array($retval) ? $retval : $content;
     }
     // if an array is returned by the config file assume it's in plain php form else in YAML
     if (is_array($input)) {
         return $input;
     }
     $mbConvertEncoding = false;
     $encoding = strtoupper($encoding);
     if ('UTF-8' != $encoding && function_exists('mb_convert_encoding')) {
         $input = mb_convert_encoding($input, 'UTF-8', $encoding);
         $mbConvertEncoding = true;
     }
     $yaml = new sfYamlParser();
     try {
         $ret = $yaml->parse($input);
     } catch (Exception $e) {
         throw new InvalidArgumentException(sprintf('Unable to parse %s: %s', $file ? sprintf('file "%s"', $file) : 'string', $e->getMessage()));
     }
     if ($ret && $mbConvertEncoding) {
         $ret = self::arrayConvertEncoding($ret, $encoding);
     }
     return $ret;
 }
开发者ID:Phennim,项目名称:symfony1,代码行数:51,代码来源:sfYaml.class.php

示例4: parseYAMLImport

 /**
  * Handles finding and parsing YAML input as a string or from the contents of a file.
  * 
  * @see addYAMLConfigFile() on {@link SS_ConfigManifest} from where this logic was taken and adapted.
  * @param string $source YAML as a string or a filename
  * @return array
  */
 public function parseYAMLImport($source)
 {
     if (is_file($source)) {
         $source = file_get_contents($source);
     }
     require_once 'thirdparty/zend_translate_railsyaml/library/Translate/Adapter/thirdparty/sfYaml/lib/sfYamlParser.php';
     $parser = new sfYamlParser();
     // Make sure the linefeeds are all converted to \n, PCRE '$' will not match anything else.
     $convertLF = str_replace(array("\r\n", "\r"), "\n", $source);
     /*
      * Remove illegal colons from Transition/Action titles, otherwise sfYamlParser will barf on them
      * Note: The regex relies on there being single quotes wrapped around these in the export .ss template
      */
     $converted = preg_replace("#('[^:\n][^']+)(:)([^']+')#", "\$1;\$3", $convertLF);
     $parts = preg_split('#^---$#m', $converted, -1, PREG_SPLIT_NO_EMPTY);
     // If we got an odd number of parts the config, file doesn't have a header.
     // We know in advance the number of blocks imported content will have so we settle for a count()==2 check.
     if (count($parts) != 2) {
         $msg = _t('WorkflowDefinitionImporter.INVALID_YML_FORMAT_NO_HEADER', 'Invalid YAML format.');
         throw new ValidationException($msg);
     }
     try {
         $parsed = $parser->parse($parts[1]);
         return $parsed;
     } catch (Exception $e) {
         $msg = _t('WorkflowDefinitionImporter.INVALID_YML_FORMAT_NO_PARSE', 'Invalid YAML format. Unable to parse.');
         throw new ValidationException($msg);
     }
 }
开发者ID:Neumes,项目名称:advancedworkflow,代码行数:36,代码来源:WorklowDefinitionImporter.php

示例5: load

 /**
  * Load YAML into a PHP array statically
  *
  * The load method, when supplied with a YAML stream (string or file),
  * will do its best to convert YAML in a file into a PHP array.
  *
  *  Usage:
  *  <code>
  *   $array = sfYAML::Load('config.yml');
  *   print_r($array);
  *  </code>
  *
  * @param string $input Path of YAML file or string containing YAML
  *
  * @return array
  */
 public static function load($input)
 {
     $file = '';
     // if input is a file, process it
     if (strpos($input, "\n") === false && is_file($input)) {
         $file = $input;
         ob_start();
         $retval = (include $input);
         $content = ob_get_clean();
         // if an array is returned by the config file assume it's in plain php form else in yaml
         $input = is_array($retval) ? $retval : $content;
     }
     // if an array is returned by the config file assume it's in plain php form else in yaml
     if (is_array($input)) {
         return $input;
     }
     require_once dirname(__FILE__) . '/sfYamlParser.class.php';
     $yaml = new sfYamlParser();
     try {
         $ret = $yaml->parse($input);
     } catch (Exception $e) {
         throw new InvalidArgumentException(sprintf('Unable to parse %s: %s', $file ? sprintf('file "%s"', $file) : 'string', $e->getMessage()));
     }
     return $ret;
 }
开发者ID:WIZARDISHUNGRY,项目名称:symfony,代码行数:41,代码来源:sfYaml.class.php

示例6: unyaml

function unyaml($file)
{
    static $yaml = false;
    if (!$yaml) {
        $yaml = new sfYamlParser();
    }
    $data = $yaml->parse(file_get_contents($file));
    $data = fix_comments($data);
    return $data;
}
开发者ID:najomi,项目名称:najomi.org,代码行数:10,代码来源:global.php

示例7: yaml_decode

function yaml_decode($input)
{
    require_once dirname(__FILE__) . '/../lib/yaml/sfYaml.php';
    require_once dirname(__FILE__) . '/../lib/yaml/sfYamlParser.php';
    $yaml = new sfYamlParser();
    try {
        return $yaml->parse($input);
    } catch (Exception $e) {
        return null;
    }
}
开发者ID:genma,项目名称:spip_ynh,代码行数:11,代码来源:yaml-mini.php

示例8: testExecuteProducesYaml

 /**
  * Проверяем что из csv получился yaml
  */
 public function testExecuteProducesYaml()
 {
     $csvImport = new myImportCsvVkoshelke($this->_csvData);
     $success = $csvImport->execute($this->_user);
     $this->assertTrue($success, 'Импорт должен завершиться успешно');
     $yaml = $csvImport->getYmlData();
     $yamlParser = new sfYamlParser();
     $data = $yamlParser->parse($yaml);
     $this->assertEquals(array('user_id' => $this->_user->getId(), 'date' => '2010-06-08', 'amount' => '20000.00', 'comment' => 'Тане', 'type' => 0, 'Account' => 'Account_1', 'Category' => 'Category_1'), $data['Operation']['Operation_1']);
     $this->assertEquals(array('user_id' => $this->_user->getId(), 'date' => '2010-06-06', 'amount' => '100.00', 'comment' => '', 'type' => 2, 'Account' => 'Account_2', 'transfer_amount' => '300000.00', 'TransferAccount' => 'Account_1'), $data['Operation']['Operation_4']);
 }
开发者ID:ru-easyfinance,项目名称:EasyFinance,代码行数:14,代码来源:myImportCsvVkoshelkeTest.php

示例9: executeStats

 public function executeStats()
 {
     $yaml = new sfYamlParser();
     $this->stats = "";
     if (file_exists(sfConfig::get('sf_data_dir') . '/stats/stats.yml')) {
         try {
             $this->stats = $yaml->parse(file_get_contents(sfConfig::get('sf_data_dir') . '/stats/stats.yml'));
         } catch (InvalidArgumentException $e) {
             // an error occurred during parsing
             echo __("Unable to parse statistics file");
         }
     }
 }
开发者ID:naturalsciences,项目名称:Darwin,代码行数:13,代码来源:components.class.php

示例10: loadFile

 public static function loadFile($file)
 {
     if (!file_exists($file)) {
         throw new pakeException('file not found: "' . $file . '"');
     }
     if (extension_loaded('yaml')) {
         return yaml_parse_file($file);
     }
     sfYaml::setSpecVersion('1.1');
     // more compatible
     $parser = new sfYamlParser();
     return $parser->parse(file_get_contents($file));
 }
开发者ID:piotras,项目名称:pake,代码行数:13,代码来源:pakeYaml.class.php

示例11: yaml_sfyaml_decode

function yaml_sfyaml_decode($input, $show_error = true)
{
    require_once _DIR_PLUGIN_YAML . 'sfyaml/sfYaml.php';
    require_once _DIR_PLUGIN_YAML . 'sfyaml/sfYamlParser.php';
    $yaml = new sfYamlParser();
    try {
        $ret = $yaml->parse($input);
    } catch (Exception $e) {
        if ($show_error) {
            throw new InvalidArgumentException(sprintf('Unable to parse string: %s', $e->getMessage()));
        } else {
            return false;
        }
    }
    return $ret;
}
开发者ID:RadioCanut,项目名称:site-radiocanut,代码行数:16,代码来源:yaml_sfyaml.php

示例12: unyaml

function unyaml($file)
{
    static $yaml = false;
    if ($_SERVER['HTTP_HOST'] != 'localhost:8000') {
        if (cache_exists($file)) {
            return read_cache($file);
        }
    }
    if (!$yaml) {
        $yaml = new sfYamlParser();
    }
    $data = $yaml->parse(file_get_contents($file));
    $data = fix_comments($data);
    write_cache($file, $data);
    return $data;
}
开发者ID:Bubujka,项目名称:najomi.org,代码行数:16,代码来源:global.php

示例13: loadString

 public static function loadString($input)
 {
     if (extension_loaded('yaml')) {
         $retval = yaml_parse($input);
         if (false === $retval) {
             throw new pakeException("empty yaml document");
         }
     } else {
         sfYaml::setSpecVersion('1.1');
         // more compatible
         $parser = new sfYamlParser();
         $retval = $parser->parse($input);
         if (null === $retval) {
             throw new pakeException("empty yaml document");
         }
     }
     return $retval;
 }
开发者ID:JasonWayne,项目名称:markdown-resume,代码行数:18,代码来源:pakeYaml.class.php

示例14: __construct

 private function __construct()
 {
     //try to figure out the environment
     if (file_exists('/serverConfig/serverConfig.ini')) {
         $serverConfig = parse_ini_file('/serverConfig/serverConfig.ini', true);
         $this->env = $serverConfig['serverType'];
     }
     //parse the config file
     $configFile = sfConfig::get('sf_config_dir') . '/server_env.yml';
     if (file_exists($configFile)) {
         $yaml = new sfYamlParser();
         $allOptions = $yaml->parse(file_get_contents($configFile));
         if (isset($allOptions[$this->env])) {
             $this->options = $allOptions[$this->env];
         }
     } else {
         throw new exception('The \'server_env.yml\' file is missing!');
     }
 }
开发者ID:nashlesigon,项目名称:project-dota,代码行数:19,代码来源:AzulServerEnv.class.php

示例15: loadSpec

 /**
  * Data provider for the mustache spec test.
  *
  * Loads YAML files from the spec and converts them to PHPisms.
  *
  * @param string $name
  *
  * @return array
  */
 protected function loadSpec($name)
 {
     $filename = dirname(__FILE__) . '/../../../vendor/spec/specs/' . $name . '.yml';
     if (!file_exists($filename)) {
         return array();
     }
     $data = array();
     $yaml = new sfYamlParser();
     $file = file_get_contents($filename);
     // @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
     if ($name === '~lambdas') {
         $file = str_replace(" !code\n", "\n", $file);
     }
     $spec = $yaml->parse($file);
     foreach ($spec['tests'] as $test) {
         $data[] = array($test['name'] . ': ' . $test['desc'], $test['template'], isset($test['partials']) ? $test['partials'] : array(), $test['data'], $test['expected']);
     }
     return $data;
 }
开发者ID:baardbaard,项目名称:bb-twitterfeed,代码行数:28,代码来源:SpecTestCase.php


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