コード例 #1
0
ファイル: IRC.php プロジェクト: nkreer/Fish
 public function loadConfig($path)
 {
     if (!file_exists($path)) {
         if ($path === "fish.json") {
             Logger::info(BashColor::RED . "Couldn't find configuration file. Making a new one...");
             @copy(__DIR__ . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "fish.json", "fish.json");
         } else {
             Logger::info(BashColor::RED . "No config found in " . $path . ": Falling back to default...");
             $path = __DIR__ . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "fish.json";
         }
     }
     $this->configPath = $path;
     $conf = new JsonConfig();
     $conf->loadFile($path);
     $this->config = $conf;
     $this->idleTime = $conf->getData("cpu_idle") * 1000;
 }
コード例 #2
0
ファイル: PluginManager.php プロジェクト: nkreer/Fish
 /**
  * @param $name
  * @return bool|int
  */
 public function loadPlugin(string $name, bool $force = false)
 {
     if (file_exists("phar://plugins" . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . "plugin.json") && !$this->hasPlugin($name)) {
         $json = new JsonConfig();
         $json->loadFile("phar://plugins" . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . "plugin.json");
         $json = $json->getConfig();
         if (isset($json["load"]) and $json["load"] !== false or $force == true) {
             if ($json["api"] != IRC::VERSION) {
                 Logger::info(BashColor::YELLOW . "Plugin " . $name . " was developed for Fish version " . $json["api"] . ", while you are running version " . IRC::VERSION . "! It might not be compatible!");
             }
             $success = true;
             if (isset($json["depend"])) {
                 foreach ($json["depend"] as $dependency) {
                     Logger::info(BashColor::YELLOW . "Loading dependency " . $dependency);
                     $success = $this->loadPlugin($dependency, true);
                     if ($success === false) {
                         Logger::info(BashColor::RED . "Couldn't find dependency " . $dependency);
                         break;
                     }
                 }
             }
             if ($success !== false) {
                 $this->getClassLoader()->addPsr4(basename($name, ".phar") . "\\", "phar://plugins" . DIRECTORY_SEPARATOR . $name);
                 $plugin = new Plugin(basename($name, ".phar"), $json, $this->getConnection());
                 $ev = new PluginLoadEvent($plugin);
                 $this->getConnection()->getEventHandler()->callEvent($ev);
                 if (!$ev->isCancelled()) {
                     $key = count($this->plugins);
                     $this->plugins[$plugin->name] = $plugin;
                     $plugin->load();
                     return $key;
                 } else {
                     unset($plugin);
                     // Don't keep it loaded
                 }
             }
         }
     }
     return false;
 }