本文整理汇总了PHP中sfYamlParser类的典型用法代码示例。如果您正苦于以下问题:PHP sfYamlParser类的具体用法?PHP sfYamlParser怎么用?PHP sfYamlParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sfYamlParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __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
示例2: 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
示例3: __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
示例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: 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)
{
$file = '';
// if input is a file, load it
if (strpos($input, "\n") === false && is_file($input)) {
$file = $input;
$content = $yaml = file_get_contents($input);
// if the file contains valid PHP, process it
if (strpos($content, '<' . '?') !== false and !(defined('_YAML_EVAL_PHP') and !_YAML_EVAL_PHP)) {
ob_start();
$retval = eval('?' . '>' . $yaml);
$content = ob_get_clean();
// syntax error?
if ($retval === FALSE) {
$content = $yaml;
}
}
// 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.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:RadioCanut,项目名称:site-radiocanut,代码行数:51,代码来源:sfYaml.php
示例12: 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
示例13: 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
示例14: 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
示例15: __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
示例16: 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
示例17: load
public static function load($string, $forgiving = false)
{
if (substr($string, 0, 3) != '---') {
$string = "---\n{$string}";
}
try {
// if syck is available use it
if (extension_loaded('syck')) {
return syck_load($string);
}
// if not, use the symfony YAML parser
$yaml = new sfYamlParser();
return $yaml->parse($string);
} catch (Exception $e) {
if ($forgiving) {
// if YAML document is not correct,
// but we're forgiving, use the Spyc parser
return Spyc::YAMLLoadString($string);
}
throw new Wikidot_Yaml_Exception("Can't parse the YAML string." . $e->getMessage());
}
}
开发者ID:jbzdak,项目名称:wikidot,代码行数:22,代码来源:Yaml.php
示例18: load
public static function load($input)
{
$file = '';
if (strpos($input, "\n") === false && is_file($input)) {
$file = $input;
ob_start();
$retval = (include $input);
$content = ob_get_clean();
$input = is_array($retval) ? $retval : $content;
}
if (is_array($input)) {
return $input;
}
require_once dirname(__FILE__) . '/sfYamlParser.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:robextrem,项目名称:testgrid,代码行数:22,代码来源:sfyaml.php
示例19: input
/**
* Read any data stored in $data, using options in $options.
*
* @param string $data The data to read.
* @param array $options The options for reading data.
* @return string
* @access public
*/
public function input($data, $options = array())
{
include_once CURATOR_APP_DIR . DS . 'Vendors' . DS . 'yaml' . DS . 'lib' . DS . 'sfYamlParser.php';
$yaml = new \sfYamlParser();
$result = null;
try {
if (strpos($data, NL) === false && is_file($data)) {
$data = file_get_contents($data);
if ($data === false) {
throw new \Exception('Could not load yaml: ' . $data);
}
}
$result = $yaml->parse($data);
} catch (\InvalidArgumentException $e) {
\Curator\Console::stderr('** Unable to parse the YAML string:');
\Curator\Console::stderr(' ' . $e->getMessage());
} catch (\Exception $e) {
\Curator\Console::stderr('** Could not handle YAML data:');
\Curator\Console::stderr(' ' . $e->getMessage());
}
return $result;
}
开发者ID:hscale,项目名称:curator,代码行数:30,代码来源:YAML.php
示例20: parse
/**
* Parses a YAML string to a PHP value.
*
* @param string $value A YAML string
*
* @return mixed A PHP value
*
* @throws InvalidArgumentException If the YAML is not valid
*/
public function parse($value)
{
$this->currentLineNb = -1;
$this->currentLine = '';
$this->lines = explode("\n", $this->cleanup($value));
if (function_exists('mb_internal_encoding') && (int) ini_get('mbstring.func_overload') & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('UTF-8');
}
$data = array();
while ($this->moveToNextLine()) {
if ($this->isCurrentLineEmpty()) {
continue;
}
// tab?
if (preg_match('#^\\t+#', $this->currentLine)) {
throw new InvalidArgumentException(sprintf('A YAML file cannot contain tabs as indentation at line %d (%s).', $this->getRealCurrentLineNb() + 1, $this->currentLine));
}
$isRef = $isInPlace = $isProcessed = false;
if (preg_match('#^\\-(\\s+(?P<value>.+?))?\\s*$#u', $this->currentLine, $values)) {
if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) {
$isRef = $matches['ref'];
$values['value'] = $matches['value'];
}
// array
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
$c = $this->getRealCurrentLineNb() + 1;
$parser = new sfYamlParser($c);
$parser->refs =& $this->refs;
$data[] = $parser->parse($this->getNextEmbedBlock());
} else {
if (preg_match('/^([^ ]+)\\: +({.*?)$/u', $values['value'], $matches)) {
$data[] = array($matches[1] => sfYamlInline::load($matches[2]));
} else {
$data[] = $this->parseValue($values['value']);
}
}
} else {
if (preg_match('#^(?P<key>' . sfYamlInline::REGEX_QUOTED_STRING . '|[^ ].*?) *\\:(\\s+(?P<value>.+?))?\\s*$#u', $this->currentLine, $values)) {
$key = sfYamlInline::parseScalar($values['key']);
if ('<<' === $key) {
if (isset($values['value']) && '*' === substr($values['value'], 0, 1)) {
$isInPlace = substr($values['value'], 1);
if (!array_key_exists($isInPlace, $this->refs)) {
throw new InvalidArgumentException(sprintf('Reference "%s" does not exist at line %s (%s).', $isInPlace, $this->getRealCurrentLineNb() + 1, $this->currentLine));
}
} else {
if (isset($values['value']) && $values['value'] !== '') {
$value = $values['value'];
} else {
$value = $this->getNextEmbedBlock();
}
$c = $this->getRealCurrentLineNb() + 1;
$parser = new sfYamlParser($c);
$parser->refs =& $this->refs;
$parsed = $parser->parse($value);
$merged = array();
if (!is_array($parsed)) {
throw new InvalidArgumentException(sprintf("YAML merge keys used with a scalar value instead of an array at line %s (%s)", $this->getRealCurrentLineNb() + 1, $this->currentLine));
} else {
if (isset($parsed[0])) {
// Numeric array, merge individual elements
foreach (array_reverse($parsed) as $parsedItem) {
if (!is_array($parsedItem)) {
throw new InvalidArgumentException(sprintf("Merge items must be arrays at line %s (%s).", $this->getRealCurrentLineNb() + 1, $parsedItem));
}
$merged = array_merge($parsedItem, $merged);
}
} else {
// Associative array, merge
$merged = array_merge($merge, $parsed);
}
}
$isProcessed = $merged;
}
} else {
if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) {
$isRef = $matches['ref'];
$values['value'] = $matches['value'];
}
}
if ($isProcessed) {
// Merge keys
$data = $isProcessed;
} else {
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
// if next line is less indented or equal, then it means that the current value is null
if ($this->isNextLineIndented()) {
$data[$key] = null;
} else {
$c = $this->getRealCurrentLineNb() + 1;
//.........这里部分代码省略.........
开发者ID:ketheriel,项目名称:ETVA,代码行数:101,代码来源:sfYamlParser.php
注:本文中的sfYamlParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论