Skip to content

Configuration

Giuseppe Trivisano edited this page May 16, 2025 · 6 revisions

As mentioned in the Init class page, the first steps in processing a request are related to the configuration setup.

The configuration properties are specified inside the config/config.json file. Here you can write different groups of configuration properties, for example one for production environment and another one for testing environment. This is the meaning of the $development_mode value inside the hook.php file.

You need to fill the config.json with your information, like Telegram Bot API token first of all, database credentials, and so on...
You can eventually add some fields, like other API tokens or something similar, and you can also add other development modes.

⚠️ Important reminder - the different development modes must have the exact same properties, with the same keys!


These properties are handled by the ConfigurationHandler class, inside the config/ folder, which is a Singleton class to select the right set of properties based on $development_mode parameter, as shown in the following code snippet:

// inside the ConfigurationHandler class

public static function setInstance(string $development_mode="production") {
  if (self::$_ClassInstance==null) {
    self::$_ClassInstance = new ConfigurationHandler($development_mode);
  }
  return self::$_ClassInstance;
}

Based on the properties in your configuration file, you will need to create the relevant methods to get the information you need in your setup code. For example, in the ConfigurationHandler class the following methods are able to extract specific properties, using the keys inside the config.json file:

  public function getTelegramBotApiToken() {
    return $this->config_properties['TELEGRAM_BOT_API_TOKEN'];
  }

  public function getDatabaseUsername() {
    return $this->config_properties['DATABASE_INFO']['username'];
  }
  public function getDatabasePassword() {
    return $this->config_properties['DATABASE_INFO']['password'];
  }
  public function getDatabaseName() {
    return $this->config_properties['DATABASE_INFO']['db_name'];
  }
  public function getDatabaseHost() {
    return $this->config_properties['DATABASE_INFO']['db_host'];
  }

Clone this wiki locally