本文整理汇总了PHP中yaml_parse函数的典型用法代码示例。如果您正苦于以下问题:PHP yaml_parse函数的具体用法?PHP yaml_parse怎么用?PHP yaml_parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了yaml_parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onEnable
public function onEnable()
{
$this->getServer()->getPluginManager()->registerEvents($this, $this);
if (!is_dir($this->getDataFolder())) {
mkdir($this->getDataFolder());
}
if (!file_exists($this->getDataFolder() . "areas.json")) {
file_put_contents($this->getDataFolder() . "areas.json", "[]");
}
if (!file_exists($this->getDataFolder() . "config.yml")) {
$c = $this->getResource("config.yml");
$o = stream_get_contents($c);
fclose($c);
file_put_contents($this->getDataFolder() . "config.yml", str_replace("DEFAULT", $this->getServer()->getDefaultLevel()->getName(), $o));
}
$this->areas = array();
$data = json_decode(file_get_contents($this->getDataFolder() . "areas.json"), true);
foreach ($data as $datum) {
$area = new Area($datum["name"], $datum["flags"], $datum["pos1"], $datum["pos2"], $datum["level"], $datum["whitelist"], $this);
}
$c = yaml_parse(file_get_contents($this->getDataFolder() . "config.yml"));
$this->god = $c["Default"]["God"];
$this->edit = $c["Default"]["Edit"];
$this->touch = $c["Default"]["Touch"];
$this->levels = array();
foreach ($c["Worlds"] as $level => $flags) {
$this->levels[$level] = $flags;
}
}
示例2: extractContent
private function extractContent()
{
if (!$this->content) {
//todo use composer yaml parser instead of pecl
$this->content = yaml_parse(file_get_contents($this->directory . DIRECTORY_SEPARATOR . $this->filename));
}
}
示例3: GetNodeConf
/**
* Retrieves the node configuration, loading it if it hasn't been already;
*
* @param string $nodename Name of the node
* @return Config The node's configuration
*/
protected static function GetNodeConf($node_uri)
{
if (isset(self::$_nodes[$node_uri])) {
return self::$_nodes[$node_uri];
}
$cache = Cache::GetCache('serialization');
$node = $cache->get($node_uri);
if (!$node) {
$filename = PATH_APP . 'map/' . str_replace(".", "/", $node_uri);
$format = null;
$data = null;
if (file_exists($filename . '.js')) {
$format = "js";
$data = json_decode(file_get_contents($filename . '.js'), true);
} else {
if (file_exists($filename . '.yaml')) {
$format = "yaml";
$data = yaml_parse(file_get_contents($filename . '.yaml'));
}
}
$map = new Config($data, $filename, $format);
foreach ($map as $key => $value) {
self::$_nodes[$key] = $value;
}
if (!isset(self::$_nodes[$node_uri])) {
throw new Exception("Could not find {$node_uri} serialization node.");
}
}
$node = self::$_nodes[$node_uri];
$cache->set($node_uri, $node);
return $node;
}
示例4: parse
/**
* Parses the contents of a given YAML file.
*
* @param $filePath
* @throws Exceptions\FileReaderException
* @return array
*/
public static function parse($filePath)
{
try {
$data = self::load($filePath);
if (!empty($data)) {
//Try to process the yaml file with the PHP function, if installed
if (function_exists("yaml_parse")) {
$dataArray = yaml_parse($data);
if (is_array($dataArray)) {
return $dataArray;
}
} else {
try {
$yml = new \Symfony\Component\Yaml\Yaml();
return $yml->parse($data);
} catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
//Do nothing. Fire exception after the if-else statement.
}
}
throw new FileReaderException('The file does not contain valid well formatted YAML data.');
} else {
throw new FileReaderException('No data has been loaded. Use the load($filePath) method before using getData().');
}
} catch (FileReaderException $e) {
throw new FileReaderException($e);
}
}
示例5: loadString
/**
* @param $text string
* @return array
* @throws MWException
*/
public static function loadString($text)
{
global $wgTranslateYamlLibrary;
switch ($wgTranslateYamlLibrary) {
case 'phpyaml':
$ret = yaml_parse($text);
if ($ret === false) {
// Convert failures to exceptions
throw new InvalidArgumentException("Invalid Yaml string");
}
return $ret;
case 'spyc':
// Load the bundled version if not otherwise available
if (!class_exists('Spyc')) {
require_once __DIR__ . '/../libs/spyc/spyc.php';
}
$yaml = spyc_load($text);
return self::fixSpycSpaces($yaml);
case 'syck':
$yaml = self::syckLoad($text);
return self::fixSyckBooleans($yaml);
default:
throw new MWException("Unknown Yaml library");
}
}
示例6: onEnable
public function onEnable()
{
@mkdir($this->getDataFolder());
XcelUpdater::chkUpdate($this);
if (!is_file($this->getDataFolder() . "shops.json")) {
file_put_contents($this->getDataFolder() . "shops.json", json_encode([]));
}
$shops = json_decode(file_get_contents($this->getDataFolder() . "shops.json"), true);
$translations = yaml_parse(stream_get_contents($this->getResource("translation.yml")));
foreach ($translations as $name => $data) {
ToAruPG::addTranslation($name, $data);
}
foreach ($shops as $tag => $meta) {
switch ($meta["type"]) {
case "SET":
$this->shops[$tag] = new SetShop($meta["meta"], $meta["cost"], $meta["desc"]);
break;
case "JOB":
$this->shops[$tag] = new JobShop($meta["meta"], $meta["cost"], $meta["desc"]);
break;
case "SKILL":
$this->shops[$tag] = new SkillShop($meta["meta"], $meta["cost"], $meta["desc"]);
break;
}
}
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->doubleTap = [];
$this->itemPlaceList = [];
}
示例7: run
/**
* @return InspectionResult
*/
public function run()
{
$result = new InspectionResult("Bad practice");
$pluginYml = file_get_contents($this->dir . "plugin.yml");
$manifest = yaml_parse($pluginYml);
if ($manifest === false) {
$result->error("Error parsing <code>plugin.yml</code>");
return $result;
}
$mainFile = realpath($this->dir . "src/" . str_replace("\\", "/", $manifest["main"]) . ".php");
/** @var \SplFileInfo $file */
foreach (new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->dir)), "#\\.php\$#") as $file) {
$file = $file->getPathname();
$contents = file_get_contents($file);
$isMain = $file === $mainFile;
if (stripos($contents, "server::getinstance()") !== false) {
$result->warning("<code>Server::getInstance()</code> scanned in file <code>" . substr($file, strlen($this->dir)) . "</code><br>\n\t\t\t\t\t<ul><li>The PHP extensions that PocketMine-MP uses have some issues with\n\t\t\t\t\tstatic properties. You are recommended try using other methods to get\n\t\t\t\t\tthe <code>Server</code> instance.</li>\n\t\t\t\t\t<li>" . ($isMain ? "You can use <code>\$this->getServer()</code> to get the server object instead." : (stripos($contents, "extends PluginTask") !== false ? "You can use <code>\$this->getOwner()->getServer()</code> to get\n\t\t\t\t\t\t\tthe <code>Server</code> instance instead." : "You can pass <code>\$this->getServer()</code> from the plugin object to\n\t\t\t\t\t\t\tyour current class's constructor.")) . "</li></ul>");
}
if ($isMain) {
if (preg_match_all("#\\\$this->config[ \t\r\n]?=[ \t\r\n]?new[ \t\r\n]+config[ \t\r\n]?\\(#i", $contents)) {
$result->warning("<code>PluginBase::\$config</code> is already defined in PocketMine\n\t\t\t\t\t\tPluginBase class. Strange errors will occur if you override\n\t\t\t\t\t\t<code>\$this->config</code> yourself. For example, when you decide to use\n\t\t\t\t\t\t<code>\$this->saveDefaultConfig()</code> later, it will not work.<br>\n\t\t\t\t\t\t<ul><li>You are recommended to improve this by renaming <code>\$this->config</code>\n\t\t\t\t\t\tto something else, or to use <code>\$this->saveDefaultConfig()</code> and related\n\t\t\t\t\t\tfunctions.</li></ul>");
}
}
}
return $result;
}
示例8: decode
/**
* @param string $data
* @param string $format
* @param array $context
*
* @return mixed
*/
public function decode($data, $format, array $context = array())
{
if ($this->native) {
return yaml_parse($data);
}
return $this->decoder->parse($data);
}
示例9: __invoke
public function __invoke($data)
{
set_error_handler($this->generateErrorHandler($data));
$parsed = yaml_parse($data);
restore_error_handler();
return $parsed;
}
示例10: decode
public static function decode($yaml)
{
$data = yaml_parse($yaml, 0, $ndocs, ['DateTime' => 'self::bsonSerialize', 'Timestamp' => 'self::bsonSerialize', 'ObjectID' => 'self::bsonSerialize', 'Binary' => 'self::bsonSerialize', 'Javascript' => 'self::bsonSerialize', 'Regex' => 'self::bsonSerialize', 'MaxKey' => 'self::bsonSerialize', 'MinKey' => 'self::bsonSerialize']);
if (!is_array($data)) {
throw new \Exception('Not yaml format');
}
return $data;
}
示例11: _config
private static function _config()
{
$configFile = self::_configFile();
if (file_exists($configFile)) {
$config = yaml_parse(@file_get_contents($configFile));
}
return (array) $config;
}
示例12: parse
public static function parse($content)
{
if (self::$native === false) {
$yaml = new \Symfony\Component\Yaml\Yaml();
return new Collection($yaml->parse($content));
} else {
return new Collection(yaml_parse($content));
}
}
示例13: loadFile
/**
* Loads in the given file and parses it.
*
* @param string $file File to load
*
* @return string|array|stdClass The parsed file data
*
* @since 0.2.4
* @codeCoverageIgnore
*/
protected function loadFile($file = null)
{
$this->file = $file;
$contents = $this->parseVars(Utils::getContent($file));
if (extension_loaded('yaml')) {
return yaml_parse($contents);
}
return YamlParser::parse($contents);
}
示例14: load
/**
* Loads configuration from YAML.
*
* @param mixed $source
*
* @return array
*/
public function load($source)
{
if (is_resource($source)) {
$source = stream_get_contents($source);
} elseif (file_exists($source)) {
$source = file_get_contents($source);
}
return yaml_parse($source);
}
示例15: loadString
public static function loadString($input)
{
if (extension_loaded('yaml')) {
return yaml_parse($input);
}
sfYaml::setSpecVersion('1.1');
// more compatible
$parser = new sfYamlParser();
return $parser->parse($input);
}