public function testDumpWithQuotes() { $Spyc = new Spyc(); $Spyc->setting_dump_force_quotes = true; $yaml = $Spyc->load(file_get_contents('../spyc.yaml')); $dump = $Spyc->dump($yaml); $yaml_after_dump = Spyc::YAMLLoad($dump); $this->assertEquals($yaml, $yaml_after_dump); }
public function testDumpWithQuotes() { $Spyc = new Spyc(); $Spyc->setting_dump_force_quotes = true; foreach ($this->files_to_test as $file) { $yaml = $Spyc->load(file_get_contents($file)); $dump = $Spyc->dump($yaml); $yaml_after_dump = Spyc::YAMLLoad($dump); $this->assertEquals($yaml, $yaml_after_dump); } }
/** * 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); } }
/** * __construct() */ private function __construct($oFinder, $sFile) { require_once "spyc/Spyc.php"; $oSpyc = new Spyc(); $oSpyc->setting_use_syck_is_possible = false; $aConfigPaths = $oFinder->find(); $this->aSettings = array(); foreach ($aConfigPaths as $sConfigPath) { // Consolidate sections from all files foreach ($oSpyc->load(self::replaceEnvVars(file_get_contents($sConfigPath))) as $sSection => $aSection) { // Ignore empty sections or non-array sections if (!is_array($aSection)) { continue; } if (!isset($this->aSettings[$sSection])) { $this->aSettings[$sSection] = array(); } foreach ($aSection as $sKey => $mValue) { $this->aSettings[$sSection][$sKey] = $mValue; } } } $this->sFile = $sFile; }
/** * Print out the form that is defined by $formid */ function formapi_print($formid, $submit = "") { global ${'formapi_define_' . $formid}; // make the definition a global variable // use yaml parser include_once "spyc.php"; $parser = new Spyc(); $formdefinition = $parser->load(${'formapi_define_' . $formid}); // get YAML formatted variable and turn into PHP array. print_r($formdefinition); // for debugging... // Start de form $output .= "<form method='post' action='{$submit}'>"; $output .= "<input type='hidden' name='formid' value='" . $formid . "'>"; // loop tru array while (list($key, $val) = each($formdefinition)) { // Massage values that are used for all fields if ($val["required"]) { $req = " (required)"; } else { $req = ""; } switch ($key) { case "h2": $output .= "<h2>{$val}</h2>"; break; case "p": $output .= "<p>{$val}</p>"; break; case "textfield": if (!$val["id"]) { $val["id"] = formapi_getuniqueid(); } // if id is not defined. $output .= '<br><label for="' . $val["id"] . '">' . $val["label"] . '</label> <input type="text" name="' . $val["id"] . '" id="' . $val["id"] . '">' . $req; break; case "checkbox": if (!$val["id"]) { $val["id"] = formapi_getuniqueid(); } // if id is not defined. $output .= '<br><input type="checkbox" name="' . $val["id"] . '" value="checkbox" id="' . $val["id"] . '"> <label for="' . $val["id"] . '">' . $val["label"] . '</label>' . $req; break; case "dropdown": // loop tru values while (list($key2, $val2) = each($val["values"])) { $options .= "<option value='" . $val2 . "'>" . $key2 . "</option>"; } $output .= <<<EOF <p> <label for="select">{$val["label"]}</label> <select name="select" id="select"> {$options} </select> </p> EOF; break; case "hidden": $output .= <<<EOF <input name="{$val["name"]}" type="hidden" value="{$val["value"]}"> EOF; break; case "textarea": $output .= <<<EOF <label for="textarea">{$val["label"]}<br></label> <textarea name="textarea" cols="{$val["cols"]}" rows="{$val["rows"]}" id="textarea"></textarea> EOF; break; case "radiogroup": if ($val["title"]) { $output .= "<h4>" . $val["title"] . "</h4>"; } while (list($key2, $val2) = each($val["values"])) { if ($key2["selected"] == TRUE) { $selected = " selected"; } else { $selected = ""; } $output .= "<br><label><input type='radio' name='" . $val["id"] . "' value='{$val2}' {$selected}>{$key2}</label>"; } case "fieldset": $output .= "<fieldset><legend>" . $val["label"] . "</legend>"; break; case "fieldsetclose": $output .= "</fieldset>"; break; case "submitbutton": $output .= '<br><input type="submit" name="submit" value="' . $val["label"] . '">'; break; default: $output .= "<br>[unknown formfield type.]"; break; } } $output .= "</form>"; return $output; }
/** * Persists the YAML data in a FixtureFactory, * which in turn saves them into the database. * Please use the passed in factory to access the fixtures afterwards. * * @param FixtureFactory $factory */ public function writeInto(FixtureFactory $factory) { $parser = new Spyc(); if (isset($this->fixtureString)) { $fixtureContent = $parser->load($this->fixtureString); } else { $fixtureContent = $parser->loadFile($this->fixtureFile); } foreach ($fixtureContent as $class => $items) { foreach ($items as $identifier => $data) { if (ClassInfo::exists($class)) { $factory->createObject($class, $identifier, $data); } else { $factory->createRaw($class, $identifier, $data); } } } }
/** * Read the complete config file *.yaml. * * @param string The yaml file. * * @return array PHP array of the yaml file. */ public static function read($file) { if (is_file($file) === false or is_readable($file) === false) { throw new \Koch\Exception\Exception('YAML File ' . $file . ' not existing or not readable.'); } if (extension_loaded('yaml')) { return yaml_parse_file($file); } elseif (extension_loaded('syck')) { $yaml = file_get_contents($file); return syck_load($yaml); } elseif (class_exists('Spyc')) { $spyc = new Spyc(); $yaml = file_get_contents($file); return $spyc->load($yaml); } throw new \Koch\Exception\Exception('No YAML Parser available. Get Spyc or Syck!'); }
/** * Load a YAML fixture file into the database. * Once loaded, you can use idFromFixture() and objFromFixture() to get items from the fixture. * Doesn't clear existing fixtures. * * @param $fixtureFile The location of the .yml fixture file, relative to the site base dir */ function loadFixture($fixtureFile) { $parser = new Spyc(); $fixtureContent = $parser->load(Director::baseFolder() . '/' . $fixtureFile); $fixture = new YamlFixture($fixtureFile); $fixture->saveIntoDatabase(); $this->fixtures[] = $fixture; }
if ($result->EOF) { $language_code = "default"; } else { $language_code = $result->fields['code']; } // addonモジュールYAML取得 require_once '../includes/addon_modules/addon_modules/classes/spyc.php'; $spyc = new Spyc(); $modules = array(); $distributes = explode("\n", MODULE_ADDON_MODULES_DISTRIBUTION_URL); for ($i = 0; $i < count($distributes); $i++) { if (trim($distributes[$i]) != "") { $contents = @file_get_contents(trim($distributes[$i]) . MODULE_ADDON_MODULES_MODULE_LIST_YML_NAME); if ($contents !== false) { $contents = mb_convert_encoding($contents, CHARSET, "utf-8"); $yaml = $spyc->load($contents); if (isset($yaml['modules'])) { foreach ($yaml['modules'] as $k => $v) { // インストール状況確認 $installed_version = "-"; // ディレクトリが存在する場合はダウンロード済 if (file_exists(getcwd() . "/../" . MODULE_ADDON_MODULES_DOWNLOAD_DIRECTORY . $k)) { $installed_version = MODULE_ADDON_MODULES_UNKNOWN_INSTALL_VERSION; } if (isset($GLOBALS[$k])) { if (isset($GLOBALS[$k]->version)) { $installed_version = $GLOBALS[$k]->version; } else { $installed_version = MODULE_ADDON_MODULES_UNKNOWN_INSTALL_VERSION; } }
function loadYaml($filename) { include_once "spyc.php"; $parser = new Spyc(); $temparray = $parser->load($filename); return array($temparray, $parser->errors); }
/** * Load a YAML fixture file into the database. * Once loaded, you can use idFromFixture() and objFromFixture() to get items from the fixture. * * Caution: In order to support reflexive relations which need a valid object ID, * the record is written twice: first after populating all non-relational fields, * then again after populating all relations (has_one, has_many, many_many). */ public function saveIntoDatabase(DataModel $model) { // We have to disable validation while we import the fixtures, as the order in // which they are imported doesnt guarantee valid relations until after the // import is complete. $validationenabled = DataObject::get_validation_enabled(); DataObject::set_validation_enabled(false); $parser = new Spyc(); if (isset($this->fixtureString)) { $fixtureContent = $parser->load($this->fixtureString); } else { $fixtureContent = $parser->loadFile($this->fixtureFile); } $this->fixtureDictionary = array(); foreach ($fixtureContent as $dataClass => $items) { if (ClassInfo::exists($dataClass)) { $this->writeDataObject($model, $dataClass, $items); } else { $this->writeSQL($dataClass, $items); } } DataObject::set_validation_enabled($validationenabled); }
/** * Load a YAML fixture file into the database. * Once loaded, you can use idFromFixture() and objFromFixture() to get items from the fixture. * * Caution: In order to support reflexive relations which need a valid object ID, * the record is written twice: first after populating all non-relational fields, * then again after populating all relations (has_one, has_many, many_many). */ public function saveIntoDatabase() { $parser = new Spyc(); $fixtureContent = $parser->load(Director::baseFolder().'/'.$this->fixtureFile); $this->fixtureDictionary = array(); foreach($fixtureContent as $dataClass => $items) { if(ClassInfo::exists($dataClass)) { $this->writeDataObject($dataClass, $items); } else { $this->writeSQL($dataClass, $items); } } }
/** * Load a YAML fixture file into the database. * Once loaded, you can use idFromFixture() and objFromFixture() to get items from the fixture * @param $fixtureFile The location of the .yml fixture file, relative to the site base dir */ function loadFixture($fixtureFile) { $parser = new Spyc(); $fixtureContent = $parser->load(Director::baseFolder() . '/' . $fixtureFile); $this->fixtureDictionary = array(); foreach ($fixtureContent as $dataClass => $items) { foreach ($items as $identifier => $fields) { $obj = new $dataClass(); foreach ($fields as $fieldName => $fieldVal) { if ($obj->many_many($fieldName) || $obj->has_many($fieldName)) { $parsedItems = array(); $items = split(' *, *', trim($fieldVal)); foreach ($items as $item) { $parsedItems[] = $this->parseFixtureVal($item); } $obj->write(); if ($obj->many_many($fieldName)) { $obj->getManyManyComponents($fieldName)->setByIDList($parsedItems); } else { $obj->getComponents($fieldName)->setByIDList($parsedItems); } } else { $obj->{$fieldName} = $this->parseFixtureVal($fieldVal); } } $obj->write(); // Populate the dictionary with the ID $this->fixtureDictionary[$dataClass][$identifier] = $obj->ID; } } }
function yaml($file) { $parser = new Spyc(); return $parser->load($file); }
/** * 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. Pretty * simple. * Usage: * <code> * $array = Spyc::YAMLLoad('lucky.yaml'); * print_r($array); * </code> * @access public * @return array * @param string $input Path of YAML file or string containing YAML */ public static function YAMLLoad($input) { $Spyc = new Spyc(); return $Spyc->load($input); }
/** * 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. Pretty * simple. * Usage: * <code> * $array = Spyc::YAMLLoad('lucky.yaml'); * print_r($array); * </code> * @access public * @return array * @param string $input Path of YAML file or string containing YAML */ function YAMLLoad($input) { $spyc = new Spyc(); return $spyc->load($input); }
function DBB_LoadYAMLFile($filename, &$retarr) { // KFD 12/8/07 New pre-scan, try to prevent known // syntax errors that will not be reported by spyc // if (!$this->DBB_LoadYAMLFile_PreScan($filename)) { return false; } // Now convert to YAML and dump include_once "spyc.php"; $parser = new Spyc(); $temparray = $parser->load($filename); #$temparray=Spyc::YAMLLoad($filename); if (count($parser->errors) > 0) { x_echoFlush(" >>> "); x_echoFlush(" >>> Parse errors in the YAML File"); x_echoFlush(" >>> "); foreach ($parser->errors as $idx => $err) { $idx = str_pad($idx + 1, 4, ' ', STR_PAD_LEFT); x_EchoFlush("{$idx}) {$err}"); } return false; } $this->YAMLError = false; $this->YAMLPrevious = array("no entries yet, look at top of file"); $this->YAMLStack = array(); $this->YAMLContent = array(); $retarr['data'] = $this->YAMLWalk($temparray); $retarr['content'] = $this->YAMLContent; return !$this->YAMLError; }
<?php require __DIR__ . '/external/spyc/spyc.php'; $core = null; if (!isset($co3Config)) { $co3Config = array(); } call_user_func(function () { global $co3Config, $core; //load conf $spyc = new Spyc(); $configFile = __DIR__ . '/conf.yaml'; if (!is_readable($configFile)) { throw new Exception("co3 Bootstrap error: " . "Missing system file '{$confFile}'"); } $conf = $spyc->load(file_get_contents($configFile), true); if ($conf === null) { throw new Exception("co3 Bootstrap error: " . "Parsing config file failed: '{$configFile}'"); } $localConfigFile = __DIR__ . '/conf.local.yaml'; if (is_readable($localConfigFile)) { $localConfig = $spyc->load(file_get_contents($localConfigFile), true); if ($localConfig === null) { throw new Exception("co3 Bootstrap error: " . "Parsing local config file failed: '{$localConfigFile}'"); } $conf = array_merge_recursive($conf, $localConfig); } $conf = array_replace_recursive($conf, $co3Config); array_walk_recursive($conf, function (&$val, $key, $vars) { $val = str_replace(array_keys($vars), $vars, $val); }, array('#BOOT#' => __FILE__, '#BOOT_DIR#' => __DIR__, '#CONFIG#' => $configFile, '#CONFIG_DIR#' => dirname($configFile), '#SCRIPT#' => $_SERVER['SCRIPT_FILENAME'], '#SCRIPT_DIR#' => dirname($_SERVER['SCRIPT_FILENAME']), '#SCRIPT_HASH#' => md5($_SERVER['SCRIPT_FILENAME']), '#PACKAGE_DIR#' => dirname(__DIR__), '#TMP#' => sys_get_temp_dir()));
/** * Read the complete config file *.yaml * * @param string The yaml filename * @return array */ public static function readConfig($file) { // check if the filename exists if (is_file($file) === false or is_readable($file) === false) { throw new Koch_Exception('YAML File ' . $file . ' not existing or not readable.'); } // init $array = ''; $yaml_content = ''; // read the yaml content of the file $yaml_content = file_get_contents($file); /** * check if the php extension SYCK is available as parser * SYCK is written in C, so it's implementation is faster then SPYC, which is pure PHP. */ if (extension_loaded('syck')) { // take the faster one first // syck_load accepts a YAML string as input and converts it into a PHP data structure $array = syck_load($yaml_content); } elseif (is_file(ROOT_LIBRARIES . '/spyc/Spyc.class.php') === true) { // ok, load spyc if (false === class_exists('Spyc', false)) { include ROOT_LIBRARIES . '/spyc/Spyc.class.php'; } // instantiate $spyc = new Spyc(); // parse the yaml content with spyc $array = $spyc->load($yaml_content); } else { // we have no YAML Parser - too bad :( throw new Koch_Exception('No YAML Parser available. Get Spyc or Syck!'); } return $array; }