示例#1
0
 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
0
 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
0
 /**
  * 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;
 }
 /**
  * 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);
     }
 }
 /**
  * @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
0
 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 = [];
 }
 /**
  * @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
0
 /**
  * @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
0
 public function __invoke($data)
 {
     set_error_handler($this->generateErrorHandler($data));
     $parsed = yaml_parse($data);
     restore_error_handler();
     return $parsed;
 }
示例#10
0
文件: Yaml.php 项目: tany/php-note
 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
0
文件: Index.php 项目: iamfat/gini
 private static function _config()
 {
     $configFile = self::_configFile();
     if (file_exists($configFile)) {
         $config = yaml_parse(@file_get_contents($configFile));
     }
     return (array) $config;
 }
 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
0
文件: Yaml.php 项目: xeriab/konfig
 /**
  * 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
0
 /**
  * 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
0
 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);
 }
 public function yamlDataProvider()
 {
     $class = str_replace('Nl2Go\\Templates\\', '', static::class);
     $filename = str_replace('\\', DIRECTORY_SEPARATOR, $class);
     $filename = sprintf('tests/%s.yaml', $filename);
     $trace = debug_backtrace(false, 3);
     $method = $trace[2]['args'][2];
     $testdata = yaml_parse(file_get_contents($filename));
     return $testdata['tests'][$method]['dataProvider'];
 }
示例#17
0
 function __construct($configFile)
 {
     $config = yaml_parse(file_get_contents($configFile));
     $num = 0;
     $this->apiKey = $config["APIKey"];
     $this->voteUrl = $config["VoteURL"];
     $this->ranks = $config["Ranks"];
     $this->autoRanks = $config["AutoRanks"];
     $this->voteRanks = $config["VoteRanks"];
     $this->messages = $config["Messages"];
 }
示例#18
0
 public static function getRepoVersion($pluginYamlURL)
 {
     $curl = curl_init($pluginYamlURL);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
     $data = curl_exec($curl);
     curl_close($curl);
     return yaml_parse($data)["version"];
 }
示例#19
0
文件: Config.php 项目: tany/php-note
 public static function load($name, $section = 'default')
 {
     static $caches = [];
     if (isset($caches[$key = "{$name}--{$section}"])) {
         return $caches[$key];
     }
     $conf = yaml_parse(load_file(ROOT . "/conf/default/{$name}.yml"))[$section];
     if (is_file($file = ROOT . "/conf/{$name}.yml")) {
         $conf = array_replace_recursive($conf, yaml_parse(load_file($file))[$section]);
     }
     return $caches[$key] = $conf;
 }
示例#20
0
 public function test_serialization()
 {
     $path = realpath(dirname(__FILE__)) . '/../../configuration/defaults.yml';
     $data = yaml_parse(file_get_contents($path));
     $serialized = yaml_emit($data);
     $serialized2 = $this->_core->configuration->serialize($data);
     if ($serialized === $serialized2) {
         $this->assertTrue(true);
     } else {
         $this->assertTrue(false);
     }
 }
 /**
  * Decode given YAML data to PHP array.
  *
  * @param string $data
  * @return array
  * @throws DataFormatInvalidException
  */
 public function decodeData($data)
 {
     $this->turnOffErrors();
     $this->validateData($data);
     $parsedData = \yaml_parse($data);
     $parsingSuccessful = $parsedData !== false;
     if ($parsingSuccessful) {
         return $parsedData;
     } else {
         throw new DataFormatInvalidException('Invalid YAML data format.');
     }
 }
示例#22
0
 /**
  * Parse YAML data, and return an array.
  *
  * @param string $yaml The YAML data
  *
  * @return array
  */
 public static function parse($yaml)
 {
     $options = null;
     if (function_exists('yaml_parse')) {
         $options = yaml_parse($yaml);
     } else {
         $options = spyc_load($yaml);
     }
     if ($options === null) {
         throw new YamlParseException('There was an error parsing your YAML front matter');
     }
     return $options;
 }
示例#23
0
 /**
  * Constructor
  * 
  * @param string $root The root uri path
  * @param array $segments The uri segments following the root path
  * @param bool $from_controller
  */
 public function __construct($request)
 {
     parent::__construct($request);
     $filename = PATH_CONFIG . $this->context . "/" . $this->metadata->app . ".conf";
     if (file_exists($filename)) {
         $yaml = file_get_contents($filename);
         $this->appmeta = new AttributeReader(yaml_parse($yaml));
     } else {
         throw new Exception("No app metadata specified.");
     }
     // Wrap the controller's Request object in a simplified proxy for search
     $this->request = new SearchRequestProxy($this->request);
 }
示例#24
0
 private function readYAMLs($paths)
 {
     if (!is_array($paths)) {
         $paths = (array) $paths;
     }
     $defs = array();
     foreach ($paths as $path) {
         foreach ($this->findYAMLs($path . '/*.yaml') as $file) {
             $defs = array_merge($defs, yaml_parse(file_get_contents($file)));
         }
     }
     return $defs;
 }
示例#25
0
 public function onEnable()
 {
     @mkdir($this->getDataFolder());
     if (!is_file($this->getDataFolder() . "jobs.yml")) {
         $this->jobs = new Config($this->getDataFolder() . "jobs.yml", Config::YAML, yaml_parse($this->readResource("jobs.yml")));
     } else {
         $this->jobs = new Config($this->getDataFolder() . "jobs.yml", Config::YAML);
     }
     $this->player = new Config($this->getDataFolder() . "players.yml", Config::YAML);
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
     $this->api = EconomyAPI::getInstance();
     self::$instance = $this;
 }
示例#26
0
 private function loadKits()
 {
     if (!file_exists($this->getDataFolder() . "kits.yml")) {
         $r = $this->getResource("kits.yml");
         $o = stream_get_contents($r);
         fclose($r);
         file_put_contents($this->getDataFolder() . "kits.yml", $o);
     }
     $kitsData = yaml_parse(file_get_contents($this->getDataFolder() . "kits.yml"));
     $this->fixConfig($kitsData);
     foreach ($kitsData as $kitName => $kitData) {
         $this->kits[$kitName] = new Kit($this, $kitData, $kitName);
     }
 }
示例#27
0
 /**
  * Read from a YAML string and create a config object
  *
  * @param  string $string
  * @return ObjectConfigYaml|false   Returns a ObjectConfig object. False on failure.
  * @throws \RuntimeException
  */
 public static function fromString($string)
 {
     $config = false;
     if (function_exist('yaml_parse')) {
         $data = array();
         if (!empty($string)) {
             $data = yaml_parse($string);
             if ($data === false) {
                 throw new \RuntimeException('Cannot parse YAML string');
             }
         }
         $config = new static($data);
     }
     return $config;
 }
示例#28
0
 static function get($path, $graceful = false)
 {
     if ($graceful) {
         $content = midgardmvc_core_helpers_snippet::get_contents_graceful($path);
     } else {
         $content = midgardmvc_core_helpers_snippet::get_contents($path);
     }
     if (!extension_loaded('yaml')) {
         // YAML PHP extension is not loaded, include the pure-PHP implementation
         require_once 'midgardmvc_core/helpers/spyc.php';
         return Spyc::YAMLLoad($content);
     } else {
         return yaml_parse($content);
     }
 }
示例#29
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = null)
 {
     $content = file_get_contents($this->locator->locate($resource));
     if ($this->parserType == self::PARSER_SYMFONY) {
         $parser = new Parser();
         $parsed = $parser->parse($content);
         return $parsed;
     } else {
         if ($this->parserType == self::PARSER_EXTENSION) {
             $parsed = yaml_parse($content);
             return $parsed;
         }
     }
     return false;
 }
示例#30
0
 public function checkFiles()
 {
     if (!file_exists($this->getDataFolder())) {
         @mkdir($this->getDataFolder(), 0777);
     }
     if (!file_exists($this->getDataFolder() . "config.yml") or \yaml_parse($this->getDataFolder() . "config.yml")["version"] !== 1) {
         $this->saveResource("config.yml", true);
         $this->cfg = new Config($this->getDataFolder() . "config.yml", Config::YAML);
     }
     if (!\file_exists($this->getDataFolder() . "arena/") or \scandir($this->getDataFolder() . "arena/") === false) {
         @mkdir($this->getDataFolder() . "arena/", 0777);
         $this->saveResource("default.yml", true);
     }
     if (!\file_exists($this->getDataFolder() . $this->cfg->get("language") . ".yml") or \yaml_parse($this->getDataFolder() . $this->cfg->get("language") . ".yml")["lang"] != $this->cfg->get("language")) {
         $this->saveResource($this->cfg->get("language") . ".yml", true);
     }
 }