本文整理汇总了PHP中Spyc::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Spyc::load方法的具体用法?PHP Spyc::load怎么用?PHP Spyc::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spyc
的用法示例。
在下文中一共展示了Spyc::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDumpWithQuotes
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);
}
示例2: testDumpWithQuotes
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);
}
}
示例3: 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);
}
}
示例4: __construct
/**
* __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;
}
示例5: formapi_print
/**
* 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;
}
示例6: writeInto
/**
* 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);
}
}
}
}
示例7: read
/**
* 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!');
}
示例8: loadFixture
/**
* 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;
}
示例9: Spyc
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;
}
}
示例10: loadYaml
function loadYaml($filename)
{
include_once "spyc.php";
$parser = new Spyc();
$temparray = $parser->load($filename);
return array($temparray, $parser->errors);
}
示例11: saveIntoDatabase
/**
* 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);
}
示例12: saveIntoDatabase
/**
* 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);
}
}
}
示例13: loadFixture
/**
* 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;
}
}
}
示例14: yaml
function yaml($file)
{
$parser = new Spyc();
return $parser->load($file);
}
示例15: YAMLLoad
/**
* 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);
}