本文整理汇总了PHP中syck_load函数的典型用法代码示例。如果您正苦于以下问题:PHP syck_load函数的具体用法?PHP syck_load怎么用?PHP syck_load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了syck_load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Load configuration file by it's type and put it into a Zend_Config object
*
* @param string $configFile Configuration file path
* @param string $fileType Configuration file type
* @param string $section Configuration section to load
* @return Zend_Config
*/
public static function load($configFile, $fileType = self::YAML, $section = 'default')
{
switch ($fileType) {
case self::YAML:
$yaml = file_get_contents($configFile);
if (extension_loaded('syck')) {
$data = syck_load($yaml);
} else {
require_once 'Spyc.php';
$data = Spyc::YAMLLoad($yaml);
}
require_once 'Zend/Config.php';
return new Zend_Config($data[$section]);
break;
case self::INI:
require_once 'Zend/Config/Ini.php';
return new Zend_Config_Ini($configFile, $section);
break;
case self::XML:
require_once 'Zend/Config/Xml.php';
return new Zend_Config_Xml($configFile, $section);
break;
default:
require_once 'Spizer/Exception.php';
throw new Spizer_Exception("Configuration files of type '{$fileType}' are not (yet?) supported");
break;
}
}
示例2: load_translation_file
protected function load_translation_file($file)
{
if (!function_exists('syck_load'))
throw new SI18nException('Syck extension is not installed');
return syck_load(file_get_contents($file));
}
示例3: loadFile
public static function loadFile($file)
{
if (function_exists('yaml_parse_file')) {
// returns array() if no data, NULL if error.
$a = yaml_parse_file($file);
if ($a === NULL || $a === false) {
throw new WFException("Error processing YAML file: {$file}");
}
return $a;
} else {
if (function_exists('syck_load')) {
// php-lib-c version, much faster!
// ******* NOTE: if using libsyck with PHP, you should install from pear/pecl (http://trac.symfony-project.com/wiki/InstallingSyck)
// ******* NOTE: as it escalates YAML syntax errors to PHP Exceptions.
// ******* NOTE: without this, if your YAML has a syntax error, you will be really confused when trying to debug it b/c syck_load will just return NULL.
$yaml = NULL;
$yamlfile = file_get_contents($file);
if (strlen($yamlfile) != 0) {
$yaml = syck_load($yamlfile);
}
if ($yaml === NULL) {
$yaml = array();
}
return $yaml;
} else {
// php version
return Horde_Yaml::loadFile($file);
}
}
}
示例4: load
public static function load($filename)
{
// cache object
# $oCache = Days_Cache::instance();
// load configuration file from cache
# if ($oCache->isCached($filename)) {
# $config = $oCache->getCache($filename);
# }
// load configuration file and set to cache
# else {
// check file
if (!file_exists($filename)) {
throw new Days_Exception("Configuration file '{$filename}' not found");
}
// use fast Yaml module for php (if exists)
if (function_exists('syck_load')) {
$config = syck_load(file_get_contents($filename));
} else {
$config = Spyc::YAMLLoad($filename);
}
// renew cache
# $oCache->setCache($filename, $config);
# }
// return result array
return $config;
}
示例5: load
public function load($file_name)
{
if (($file = file_get_contents($file_name)) !== false) {
return syck_load($file);
}
YamlErrors::fileNotFound($file_name);
return null;
}
示例6: get
static function get($path, $graceful = false)
{
// TODO: Implement using http://spyc.sourceforge.net/ if syck is not available
if ($graceful) {
$content = midcom_core_helpers_snippet::get_contents_graceful($path);
} else {
$content = midcom_core_helpers_snippet::get_contents($path);
}
return syck_load($content);
}
示例7: load_yaml
/**
* Loads any .yml file
* @return array
*/
private static function load_yaml($config_file)
{
if (is_readable($config_file)) {
if (function_exists("syck_load")) {
return syck_load(file_get_contents($config_file));
} else {
return Spyc::YAMLLoad($config_file);
}
} else {
return false;
}
}
示例8: testSimple
public function testSimple()
{
$yaml = <<<YAML
---
define: &pointer_to_define
- 1
- 2
- 3
reference: *pointer_to_define
YAML;
$arr = syck_load($yaml);
$this->assertEquals($arr['define'], $arr['reference']);
}
示例9: load
public static function load($input)
{
// syck is prefered over spyc
if (function_exists('syck_load')) {
if (!empty($input) && is_readable($input)) {
$input = file_get_contents($input);
}
return syck_load($input);
} else {
$spyc = new pakeSpyc();
return $spyc->load($input);
}
}
示例10: process
/**
* Transform data and return the result.
*
* @param string $data Yaml string or file
* @return array
*/
public function process($data)
{
if ($this->chainInput) {
$data = $this->chainInput->process($data);
}
if ($data instanceof Fs_Node) {
$data = $data->getContents();
} else {
$data = (string) $data;
}
$data = syck_load($data);
return $data;
}
示例11: 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);
}
}
示例12: 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>
*
* @return array
* @param string $input Path of YAML file or string containing YAML
*/
public static function load($input)
{
$input = self::getIncludeContents($input);
// 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;
}
// syck is prefered over spyc
if (function_exists('syck_load')) {
$retval = syck_load($input);
return is_array($retval) ? $retval : array();
} else {
require_once dirname(__FILE__) . '/Spyc.class.php';
$spyc = new Spyc();
return $spyc->load($input);
}
}
示例13: 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" );
}
}
示例14: 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());
}
}
示例15: loadWithSource
private function loadWithSource($Source)
{
if (empty($Source)) {
return array();
}
if ($this->setting_use_syck_is_possible && function_exists('syck_load')) {
$array = syck_load(implode("\n", $Source));
return is_array($array) ? $array : array();
}
$this->path = array();
$this->result = array();
$cnt = count($Source);
for ($i = 0; $i < $cnt; $i++) {
$line = $Source[$i];
$this->indent = strlen($line) - strlen(ltrim($line));
$tempPath = $this->getParentPathByIndent($this->indent);
$line = self::stripIndent($line, $this->indent);
if (self::isComment($line)) {
continue;
}
if (self::isEmpty($line)) {
continue;
}
$this->path = $tempPath;
$literalBlockStyle = self::startsLiteralBlock($line);
if ($literalBlockStyle) {
$line = rtrim($line, $literalBlockStyle . " \n");
$literalBlock = '';
$line .= ' ' . $this->LiteralPlaceHolder;
$literal_block_indent = strlen($Source[$i + 1]) - strlen(ltrim($Source[$i + 1]));
while (++$i < $cnt && $this->literalBlockContinues($Source[$i], $this->indent)) {
$literalBlock = $this->addLiteralLine($literalBlock, $Source[$i], $literalBlockStyle, $literal_block_indent);
}
$i--;
}
// Strip out comments
if (strpos($line, '#')) {
$line = preg_replace('/\\s*#([^"\']+)$/', '', $line);
}
while (++$i < $cnt && self::greedilyNeedNextLine($line)) {
$line = rtrim($line, " \n\t\r") . ' ' . ltrim($Source[$i], " \t");
}
$i--;
$lineArray = $this->_parseLine($line);
if ($literalBlockStyle) {
$lineArray = $this->revertLiteralPlaceHolder($lineArray, $literalBlock);
}
$this->addArray($lineArray, $this->indent);
foreach ($this->delayedPath as $indent => $delayedPath) {
$this->path[$indent] = $delayedPath;
}
$this->delayedPath = array();
}
return $this->result;
}