本文整理汇总了PHP中sfYamlParser类的典型用法代码示例。如果您正苦于以下问题:PHP sfYamlParser类的具体用法?PHP sfYamlParser怎么用?PHP sfYamlParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sfYamlParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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']);
}
示例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");
}
}
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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!');
}
}