Exemplo n.º 1
0
 /**
  * Get the database's configuration
  *
  * @param  boolean    $testing Whether to retrieve the test database credentials
  * @return array|null The configuration as defined in the config.yml file, null if no configuration was found
  */
 public static function getDatabaseConfig($testing = false)
 {
     $configPath = ConfigHandler::getConfigurationPath();
     if (!is_file($configPath)) {
         throw new \Exception("The configuration file could not be read");
     }
     $path = $testing ? 'testing' : 'mysql';
     $config = Yaml::parse(file_get_contents($configPath));
     if (isset($config['bzion'][$path])) {
         return $config['bzion'][$path];
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * Promote a player to an admin if the configuration file specifies so
  *
  * @param Player $player The player in question
  */
 private function configPromoteAdmin(Player $player)
 {
     $adminUsername = $this->container->getParameter('bzion.miscellaneous.admin');
     if (!$adminUsername) {
         return;
     }
     if (strtolower($player->getUsername()) === strtolower($adminUsername)) {
         $player->addRole(Player::DEVELOPER);
         // Remove the username from the configuration file so that we don't
         // give admin permissions to the wrong person in case callsign
         // changes take place. This is supposed to happen only once, so we
         // don't need to worry about the performance overhead due to the
         // parsing and dumping of the YML file
         $path = ConfigHandler::getConfigurationPath();
         $config = Yaml::parse($path);
         $config['bzion']['miscellaneous']['admin'] = null;
         file_put_contents($path, Yaml::dump($config, 4));
         $this->getLogger()->notice(sprintf("User %s with BZID %s is now an administrator, as instructed by the configuration file", $adminUsername, $player->getBZID()));
     }
 }