本文整理汇总了PHP中spyc_load函数的典型用法代码示例。如果您正苦于以下问题:PHP spyc_load函数的具体用法?PHP spyc_load怎么用?PHP spyc_load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spyc_load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadString
/**
* @param $text string
* @return array
* @throws MWException
*/
public static function loadString($text)
{
global $wgTranslateYamlLibrary;
switch ($wgTranslateYamlLibrary) {
case 'phpyaml':
$ret = yaml_parse($text);
if ($ret === false) {
// Convert failures to exceptions
throw new InvalidArgumentException("Invalid Yaml string");
}
return $ret;
case 'spyc':
// Load the bundled version if not otherwise available
if (!class_exists('Spyc')) {
require_once __DIR__ . '/../libs/spyc/spyc.php';
}
$yaml = spyc_load($text);
return self::fixSpycSpaces($yaml);
case 'syck':
$yaml = self::syckLoad($text);
return self::fixSyckBooleans($yaml);
default:
throw new MWException("Unknown Yaml library");
}
}
示例2: testDump
public function testDump()
{
$yaml = spyc_load(file_get_contents('../spyc.yaml'));
$dump = Spyc::YAMLDump($yaml);
$yaml_after_dump = Spyc::YAMLLoad($dump);
$this->assertEquals($yaml, $yaml_after_dump);
}
示例3: init
public static function init(&$report)
{
$environments = PhpReports::$config['environments'];
if (!isset($environments[$report->options['Environment']][$report->options['Database']])) {
throw new Exception("No " . $report->options['Database'] . " database defined for environment '" . $report->options['Environment'] . "'");
}
//make sure the syntax highlighting is using the proper class
SqlFormatter::$pre_attributes = "class='prettyprint linenums lang-sql'";
$object = spyc_load($report->raw_query);
$report->raw_query = array();
//if there are any included reports, add the report sql to the top
if (isset($report->options['Includes'])) {
$included_sql = '';
foreach ($report->options['Includes'] as &$included_report) {
$included_sql .= trim($included_report->raw_query) . "\n";
}
if (strlen($included_sql) > 0) {
$report->raw_query[] = $included_sql;
}
}
$report->raw_query[] = $object;
//set a formatted query here for debugging. It will be overwritten below after macros are substituted.
//We can not set the query here - it's not a query just yet...
//$report->options['Query_Formatted'] = SqlFormatter::format($report->raw_query);
}
示例4: generateModel
public function generateModel($yaml_file, $dir)
{
$schema = spyc_load(file_get_contents($yaml_file));
$this->dir = $dir;
foreach ($schema as $entity_name => $entity_definition) {
$this->generateClass($dir . '/' . $entity_name . '.class.php', $entity_name, $entity_definition);
}
}
示例5: testDump
public function testDump()
{
foreach ($this->files_to_test as $file) {
$yaml = spyc_load(file_get_contents($file));
$dump = Spyc::YAMLDump($yaml);
$yaml_after_dump = Spyc::YAMLLoad($dump);
$this->assertEquals($yaml, $yaml_after_dump);
}
}
示例6: parse
/**
* Parse YAML data, and return an array.
*
* @param string $yaml The YAML data
*
* @return array
*/
public static function parse($yaml)
{
$options = null;
if (function_exists('yaml_parse')) {
$options = yaml_parse($yaml);
} else {
$options = spyc_load($yaml);
}
if ($options === null) {
throw new YamlParseException('There was an error parsing your YAML front matter');
}
return $options;
}
示例7: yaml_load
function yaml_load($input = null)
{
if (is_null($input)) {
return array();
}
$input = yaml_include_contents($input);
if (is_array($input)) {
return $input;
}
if (function_exists('syck_load')) {
$datas = syck_load($input);
return is_array($datas) ? $datas : array();
} else {
return spyc_load($input);
}
}
示例8: loadString
/**
* @param $text string
* @return array
* @throws MWException
*/
public static function loadString( $text ) {
global $wgTranslateYamlLibrary;
switch ( $wgTranslateYamlLibrary ) {
case 'spyc':
require_once( dirname( __FILE__ ) . '/../spyc/spyc.php' );
$yaml = spyc_load( $text );
return self::fixSpycSpaces( $yaml );
case 'syck':
$yaml = self::syckLoad( $text );
return self::fixSyckBooleans( $yaml );
case 'syck-pecl':
$text = preg_replace( '~^(\s*)no(\s*:\s*[a-zA-Z-_]+\s*)$~m', '\1"no"\2', $text );
return syck_load( $text );
default:
throw new MWException( "Unknown Yaml library" );
}
}
示例9: parseYml
public function parseYml($file, $env, $dir = NULL)
{
static $ymldatas;
$dir = ($dir === NULL ? dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'config' : $dir) . DIRECTORY_SEPARATOR;
$file_path = realpath($dir . $file);
if (!isset($ymldatas[$file_path])) {
ob_start();
include $dir . $file;
$buff = ob_get_contents();
ob_end_clean();
$buff = spyc_load($buff);
$ymldatas[$file_path] = $buff;
} else {
$buff = $ymldatas[$file_path];
}
$res = isset($buff[$env]) ? $this->mergeConfiguration($buff['all'], $buff[$env]) : $buff['all'];
return $res;
}
示例10: yaml
function yaml($string)
{
return spyc_load(trim($string));
}
示例11: editextension
function editextension($id = 0, $data_type = null, $relation_id = null)
{
if ($id != 0) {
$this->data['data'] = $this->general_model->get_extension_detail($id);
if ($this->data['data'] == null) {
redirect("cpanel/extension");
}
if (isset($this->data['data']['extension_more'])) {
$this->data['data']['extension_more'] = spyc_load($this->data['data']['extension_more']);
}
if (isset($this->data['data']["data_type"]) && $this->data['data']["data_type"] != "") {
$data_type = $this->data['data_type'] = $this->data['data']["data_type"];
}
if (isset($this->data['data']["relation_id"]) && $this->data['data']["relation_id"] != 0) {
$relation_id = $this->data['relation_id'] = $this->data['data']["relation_id"];
}
} elseif ($data_type == null || $relation_id == null) {
$this->session->set_flashdata('error', _l('Your request is not valid.', $this));
redirect("/cpanel/extensions/");
} else {
if ($data_type != null) {
$this->data['data_type'] = $data_type;
}
if ($relation_id != null) {
$this->data['relation_id'] = $relation_id;
}
}
$this->load->library('spyc');
if ($data_type == "page" && $relation_id != null) {
$page = $this->general_model->get_page_detail($relation_id);
$options = spyc_load_file(getcwd() . "/page_type.yml");
if (isset($options[$page["page_type"]])) {
$this->data['page_type'] = $options[$page["page_type"]];
}
} else {
$this->data['fields'] = array("icon", "image", "description", "full_description");
}
$icons = spyc_load_file(getcwd() . "/icons.yml");
$this->data['faicons'] = $icons["fa"];
$this->data['languages'] = $this->general_model->get_all_language();
$this->data['title'] = _l("extension", $this);
$this->data['page'] = "extension";
$this->data['content'] = $this->load->view('flatlab/extension_edit', $this->data, true);
$this->load->view('flatlab', $this->data);
}
示例12: load_state_file
/**
* Load a given Yaml state file
*
* @param string $file
* @return object
*/
private function load_state_file($file)
{
if (!file_exists($file)) {
WP_CLI::error(sprintf("File doesn't exist: %s", $file));
}
$yaml = spyc_load(file_get_contents($file));
if (empty($yaml)) {
WP_CLI::error(sprintf("Doesn't appear to be a Yaml file: %s", $file));
}
return $yaml;
}
示例13: file_get_contents
*
* UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't
* have to do anything special to choose one license or the other and you don't
* have to notify anyone which license you are using. You are free to use
* UniversalLanguageSelector in commercial projects as long as the copyright
* header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
*
* @file
* @ingroup Extensions
* @licence GNU General Public Licence 2.0 or later
* @licence MIT License
*/
include __DIR__ . '/spyc.php';
print "Reading langdb.yaml...\n";
$yamlLangdb = file_get_contents('langdb.yaml');
$parsedLangdb = spyc_load($yamlLangdb);
$supplementalDataFilename = 'supplementalData.xml';
$supplementalDataUrl = "http://unicode.org/repos/cldr/trunk/common/supplemental/{$supplementalDataFilename}";
$curl = curl_init($supplementalDataUrl);
$supplementalDataFile = fopen($supplementalDataFilename, 'w');
curl_setopt($curl, CURLOPT_FILE, $supplementalDataFile);
curl_setopt($curl, CURLOPT_HEADER, 0);
print "Trying to download {$supplementalDataUrl}...\n";
$curlSuccess = curl_exec($curl);
curl_close($curl);
fclose($supplementalDataFile);
if (!$curlSuccess) {
die("Failed to download CLDR data from {$supplementalDataUrl}.\n");
}
print "Downloaded {$supplementalDataFilename}, trying to parse...\n";
$supplementalData = simplexml_load_file($supplementalDataFilename);
示例14: ReadAndAddLang
/**
* @param string $sFileName
* @param array $aResultLang
*
* @return void
*/
public static function ReadAndAddLang($sFileName, &$aResultLang)
{
if (\file_exists($sFileName)) {
$isYml = '.yml' === substr($sFileName, -4);
if ($isYml) {
$aLang = \spyc_load(\str_replace(array(': >-', ': |-'), array(': >', ': |'), \file_get_contents($sFileName)));
if (\is_array($aLang)) {
\reset($aLang);
$sLangKey = key($aLang);
if (isset($aLang[$sLangKey]) && is_array($aLang[$sLangKey])) {
$aLang = $aLang[$sLangKey];
} else {
$aLang = null;
}
}
} else {
$aLang = \RainLoop\Utils::CustomParseIniFile($sFileName, true);
}
if (\is_array($aLang)) {
foreach ($aLang as $sKey => $mValue) {
if (\is_array($mValue)) {
foreach ($mValue as $sSecKey => $mSecValue) {
$aResultLang[$sKey . '/' . $sSecKey] = $mSecValue;
}
} else {
$aResultLang[$sKey] = $mValue;
}
}
}
}
}
示例15: importZippedProblem
/**
* Read problem description file and testdata from zip archive
* and update problem with it, or insert new problem when probid=NULL.
* Returns probid on success, or generates error on failure.
*/
function importZippedProblem($zip, $probid = NULL, $cid = -1)
{
global $DB, $teamid, $cdatas, $matchstrings;
$prop_file = 'domjudge-problem.ini';
$yaml_file = 'problem.yaml';
$ini_keys_problem = array('name', 'timelimit', 'special_run', 'special_compare');
$ini_keys_contest_problem = array('probid', 'allow_submit', 'allow_judge', 'points', 'color');
$def_timelimit = 10;
// Read problem properties
$ini_array = parse_ini_string($zip->getFromName($prop_file));
if (empty($ini_array)) {
if ($probid === NULL) {
error("Need '" . $prop_file . "' file when adding a new problem.");
}
} else {
// Only preserve valid keys:
$ini_array_problem = array_intersect_key($ini_array, array_flip($ini_keys_problem));
$ini_array_contest_problem = array_intersect_key($ini_array, array_flip($ini_keys_contest_problem));
// Set default of 1 point for a problem if not specified
if (!isset($ini_array_contest_problem['points'])) {
$ini_array_contest_problem['points'] = 1;
}
if ($probid === NULL) {
if (!isset($ini_array_contest_problem['probid'])) {
error("Need 'probid' in '" . $prop_file . "' when adding a new problem.");
}
// Set sensible defaults for name and timelimit if not specified:
if (!isset($ini_array_problem['name'])) {
$ini_array_problem['name'] = $ini_array_contest_problem['probid'];
}
if (!isset($ini_array_problem['timelimit'])) {
$ini_array_problem['timelimit'] = $def_timelimit;
}
// rename probid to shortname
$shortname = $ini_array_contest_problem['probid'];
unset($ini_array_contest_problem['probid']);
$ini_array_contest_problem['shortname'] = $shortname;
$probid = $DB->q('RETURNID INSERT INTO problem (' . implode(', ', array_keys($ini_array_problem)) . ') VALUES (%As)', $ini_array_problem);
if ($cid != -1) {
$ini_array_contest_problem['cid'] = $cid;
$ini_array_contest_problem['probid'] = $probid;
$DB->q('INSERT INTO contestproblem (' . implode(', ', array_keys($ini_array_contest_problem)) . ') VALUES (%As)', $ini_array_contest_problem);
}
} else {
if (count($ini_array_problem) > 0) {
$DB->q('UPDATE problem SET %S WHERE probid = %i', $ini_array_problem, $probid);
}
if ($cid != -1) {
if ($DB->q("MAYBEVALUE SELECT probid FROM contestproblem\n\t\t\t\t WHERE probid = %i AND cid = %i", $probid, $cid)) {
// Remove keys that cannot be modified:
unset($ini_array_contest_problem['probid']);
if (count($ini_array_contest_problem) != 0) {
$DB->q('UPDATE contestproblem SET %S WHERE probid = %i AND cid = %i', $ini_array_contest_problem, $probid, $cid);
}
} else {
$shortname = $ini_array_contest_problem['probid'];
unset($ini_array_contest_problem['probid']);
$ini_array_contest_problem['shortname'] = $shortname;
$ini_array_contest_problem['cid'] = $cid;
$ini_array_contest_problem['probid'] = $probid;
$DB->q('INSERT INTO contestproblem (' . implode(', ', array_keys($ini_array_contest_problem)) . ') VALUES (%As)', $ini_array_contest_problem);
}
}
}
}
// parse problem.yaml
$problem_yaml = $zip->getFromName($yaml_file);
if ($problem_yaml !== FALSE) {
$problem_yaml_data = spyc_load($problem_yaml);
if (!empty($problem_yaml_data)) {
if (isset($problem_yaml_data['uuid']) && $cid != -1) {
$DB->q('UPDATE contestproblem SET shortname=%s
WHERE cid=%i AND probid=%i', $problem_yaml_data['uuid'], $cid, $probid);
}
$yaml_array_problem = array();
if (isset($problem_yaml_data['name'])) {
if (is_array($problem_yaml_data['name'])) {
foreach ($problem_yaml_data['name'] as $lang => $name) {
// TODO: select a specific instead of the first language
$yaml_array_problem['name'] = $name;
break;
}
} else {
$yaml_array_problem['name'] = $problem_yaml_data['name'];
}
}
if (isset($problem_yaml_data['validator_flags'])) {
$yaml_array_problem['special_compare_args'] = $problem_yaml_data['validator_flags'];
}
if (isset($problem_yaml_data['validation']) && $problem_yaml_data['validation'] == 'custom') {
// search for validator
$validator_files = array();
for ($j = 0; $j < $zip->numFiles; $j++) {
$filename = $zip->getNameIndex($j);
if (starts_with($filename, "output_validators/") && !ends_with($filename, "/")) {
//.........这里部分代码省略.........