本文整理汇总了PHP中Spyc::loadFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Spyc::loadFile方法的具体用法?PHP Spyc::loadFile怎么用?PHP Spyc::loadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spyc
的用法示例。
在下文中一共展示了Spyc::loadFile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveIntoDatabase
/**
* Mostly rewritten from parent, but allows circular dependencies - goes through the relation loop only after
* the dictionary is fully populated.
*/
public function saveIntoDatabase(DataModel $model)
{
// Custom plumbing: this has to be executed only once per fixture.
$testDataTag = basename($this->fixtureFile);
$this->latestVersion = DB::query("SELECT MAX(\"Version\") FROM \"TestDataTag\" WHERE \"FixtureFile\"='{$testDataTag}'")->value();
// 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();
$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);
}
}
// Dictionary is now fully built, inject the relations.
foreach ($fixtureContent as $dataClass => $items) {
if (ClassInfo::exists($dataClass)) {
$this->writeRelations($dataClass, $items);
}
}
DataObject::set_validation_enabled($validationenabled);
}
示例2: requireDefaultRecords
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
// get schemas that need creating
$schemas = $this->config()->get('default_schemas');
require_once 'spyc/spyc.php';
foreach ($schemas as $file) {
if (file_exists(Director::baseFolder() . '/' . $file)) {
$parser = new Spyc();
$factory = new FixtureFactory();
$fixtureContent = $parser->loadFile(Director::baseFolder() . '/' . $file);
if (isset($fixtureContent['MetadataSchema'])) {
$toBuild = array();
// check if it exists or not, if so don't re-create it
foreach ($fixtureContent['MetadataSchema'] as $id => $desc) {
$name = isset($desc['Name']) ? $desc['Name'] : null;
if (!$name) {
throw new Exception("Cannot create metadata schema without a name");
}
$existing = MetadataSchema::get()->filter('Name', $name)->first();
if ($existing) {
$factory->setId('MetadataSchema', $id, $existing->ID);
} else {
$factory->createObject('MetadataSchema', $id, $desc);
DB::alteration_message('Metadata schema ' . $id . ' created', 'created');
}
}
// don't need this now
unset($fixtureContent['MetadataSchema']);
// go through and unset any existing fields
$toBuild = array();
foreach ($fixtureContent as $class => $items) {
foreach ($items as $identifier => $data) {
$nameField = isset($data['Name']) ? 'Name' : (isset($data['Key']) ? 'Key' : '');
if (!strlen($nameField)) {
throw new Exception("Metadata fields must have a Name or Key field defined");
}
if (!isset($data['Title'])) {
$data['Title'] = $data[$nameField];
}
$existing = $class::get()->filter($nameField, $data[$nameField])->first();
if ($existing) {
$factory->setId($class, $identifier, $existing->ID);
} else {
$factory->createObject($class, $identifier, $data);
DB::alteration_message('Metadata field ' . $data[$nameField] . ' created', 'created');
}
}
}
}
}
}
}
示例3: load
/**
* Load a directory of config files (YAML) into this static object.
*/
static function load($path, $required = true, $refresh = false)
{
static $__spyc, $__cache;
if ($path[0] !== '/') {
$path = APP_ROOT . "config/{$path}.yml";
}
if (!is_file($path)) {
if ($required) {
throw new Exception("Config file not found at {$path}");
} else {
return null;
}
}
if (!$__spyc) {
$__spyc = new Spyc();
}
$yml = !$refresh && $__cache[$path] ? $__cache[$path] : $__spyc->loadFile($path);
$__cache[$path] = $yml;
return $yml;
}
示例4: loadData
/**
* loads data from file.
* This is only actioned once the first request is made.
*/
private function loadData()
{
require_once 'thirdparty/spyc/spyc.php';
foreach (self::$folder_and_file_locations as $folderAndFileLocation) {
$fixtureFolderAndFile = Director::baseFolder() . '/' . $folderAndFileLocation;
if (!file_exists($fixtureFolderAndFile)) {
user_error('No custom configuration has been setup for Ecommerce - I was looking for: "' . $fixtureFolderAndFile . '"', E_USER_NOTICE);
}
$parser = new Spyc();
$newArray = $parser->loadFile($fixtureFolderAndFile);
}
$this->fixtureDictionary = array_merge($newArray, $this->fixtureDictionary);
}
示例5: 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()
{
// 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();
$fixtureContent = $parser->loadFile(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);
}
}
DataObject::set_validation_enabled($validationenabled);
}
示例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: getDefaultValues
protected function getDefaultValues()
{
require_once 'thirdparty/spyc/spyc.php';
$fixtureFolderAndFile = Director::baseFolder() . "/" . $this->defaultLocation;
$parser = new Spyc();
return $parser->loadFile($fixtureFolderAndFile);
}
示例8: run
function run($request)
{
ini_set('max_execution_time', 3000);
require_once 'thirdparty/spyc/spyc.php';
$filesArray = Config::inst()->get("DataIntegrityTestYML", "config_files");
$classesToSkip = Config::inst()->get("DataIntegrityTestYML", "classes_to_skip");
$variablesToSkip = Config::inst()->get("DataIntegrityTestYML", "variables_to_skip");
foreach ($filesArray as $folderAndFileLocation) {
db::alteration_message("<h2>Checking {$folderAndFileLocation}</h2>");
$fixtureFolderAndFile = Director::baseFolder() . '/' . $folderAndFileLocation;
if (!file_exists($fixtureFolderAndFile)) {
user_error('No custom configuration has been setup here : "' . $fixtureFolderAndFile . '" set the files here: DataIntegrityTestYML::config_files', E_USER_NOTICE);
}
$parser = new Spyc();
$arrayOfSettings = $parser->loadFile($fixtureFolderAndFile);
foreach ($arrayOfSettings as $className => $variables) {
if (in_array(strtolower($className), $classesToSkip)) {
db::alteration_message("{$className} : skipped");
} else {
echo "<br /><br />";
if (!class_exists($className)) {
db::alteration_message("{$className} does not exist", "deleted");
} else {
db::alteration_message("{$className}", "created");
foreach ($variables as $variable => $setting) {
if ($variable == "icon") {
$fileLocationForOthers = Director::baseFolder() . '/' . $setting;
$fileLocationForSiteTree = Director::baseFolder() . '/' . $setting . '-file.gif';
if ($className::create() instanceof SiteTree) {
if (!file_exists($fileLocationForSiteTree)) {
db::alteration_message(" <u>{$className}.{$variable}</u> icon {$fileLocationForSiteTree} can not be found", "deleted");
} else {
db::alteration_message(" <u>{$className}.{$variable}</u> icon {$fileLocationForSiteTree} exists", "created");
}
} else {
if (!file_exists($fileLocationForOthers)) {
db::alteration_message(" <u>{$className}.{$variable}</u> icon {$fileLocationForOthers} can not be found", "deleted");
} else {
db::alteration_message(" <u>{$className}.{$variable}</u> icon {$fileLocationForOthers} exists", "created");
}
}
} elseif ($variable == "extensions") {
if (!is_array($setting)) {
db::alteration_message(" <u>{$className}.{$variable}</u> extensions should be set as an array.", "deleted");
} else {
foreach ($setting as $extensionClassName) {
if (!class_exists($extensionClassName)) {
db::alteration_message(" <u>{$className}.{$variable}</u> extension class <u>{$extensionClassName}</u> does not exist", "deleted");
} else {
db::alteration_message(" <u>{$className}.{$variable}</u> extension class <u>{$extensionClassName}</u> found", "created");
}
}
}
} elseif (in_array($variable, $variablesToSkip)) {
db::alteration_message(" <u>{$className}.{$variable}</u> skipped");
} else {
if (!property_exists($className, $variable)) {
db::alteration_message(" <u>{$className}.{$variable}</u> does not exist", "deleted");
} else {
db::alteration_message(" <u>{$className}.{$variable}</u> found", "created");
}
}
}
}
}
}
}
}
示例9: createcustomisationsteps
function createcustomisationsteps()
{
require_once 'thirdparty/spyc/spyc.php';
$parser = new Spyc();
$array = $parser->loadFile(Director::baseFolder() . '/ecommerce/docs/en/CustomisationChart.yaml');
$html = "\r\n\t\t\t<ol>";
foreach ($array as $question => $answerArray) {
$html .= "\r\n\t\t\t\t<li><h3>" . $question . "</h3>";
foreach ($answerArray as $answer => $notes) {
$html .= "\r\n\t\t\t\t<h4>" . $answer . "</h4>\r\n\t\t\t\t<ul>";
foreach ($notes as $noteKey => $note) {
if (is_array($note)) {
print_r($note);
}
$html .= "\r\n\t\t\t\t\t<li>{$note}</li>";
}
$html .= "\r\n\t\t\t\t</ul>";
}
}
$html .= "\r\n\t\t\t</ol>";
return $html;
}