patterns_yamlparser.module in Patterns 7
File
patterns_yamlparser/patterns_yamlparser.module
View source
<?php
define('PATTERNS_FORMAT_YAML', 'yaml');
function patterns_yamlparser_patterns_parser() {
$parser = array();
$parser['format'] = PATTERNS_FORMAT_YAML;
$parser['parser'] = 'patterns_yamlparser';
return $parser;
}
function patterns_yamlparser_libraries_info() {
$libraries['spyc'] = array(
'name' => 'Spyc (A simple YAML loader/dumper class for PHP)',
'vendor url' => 'https://code.google.com/p/spyc/',
'download url' => 'https://github.com/mustangostang/spyc/',
'version arguments' => array(
'file' => 'Spyc.php',
'pattern' => '@version\\s+([0-9a-zA-Z\\.-]+)@',
),
'files' => array(
'php' => array(
'Spyc.php',
),
),
);
return $libraries;
}
function patterns_yamlparser_load($path, $local = TRUE) {
if ($local && !file_exists($path)) {
return FALSE;
}
$library = libraries_load('spyc');
if (!empty($library['loaded'])) {
return Spyc::YAMLLoad($path);
}
else {
watchdog('Patterns', 'Spyc library not found while trying to load the file.', array(), WATCHDOG_ERROR);
return FALSE;
}
}
function patterns_yamlparser_parse($pattern) {
$library = libraries_load('spyc');
if (!empty($library['loaded'])) {
if (!is_array($pattern)) {
$pattern = Spyc::YAMLLoad($pattern);
}
}
else {
watchdog('Patterns', 'Spyc library not found while trying to parse.', array(), WATCHDOG_ERROR);
return FALSE;
}
return $pattern;
}
function patterns_yamlparser_dump($pattern = NULL, $append = NULL) {
if (is_null($pattern) || !is_array($pattern)) {
return FALSE;
}
$dump = empty($append) ? '' : $append . "\n";
$library = libraries_load('spyc');
if (!empty($library['loaded'])) {
$dump .= Spyc::YAMLDump($pattern);
return $dump;
}
else {
watchdog('Patterns', 'Spyc library not found while trying to dump.', array(), WATCHDOG_ERROR);
return FALSE;
}
}
function patterns_yamlparser_dump_comment($text = NULL, $append = NULL) {
if (is_null($text)) {
return FALSE;
}
$dump = empty($append) ? '' : $append . "\n";
$dump .= "# " . $text;
return $dump;
}