Skip to content

Internals Setting Settings

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

setting\Settings

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/setting/Settings.php · Snapshot 8411f4287706.

Database-backed settings are initialized as named SettingModel constants and retrieved through Config.

Imports and dependencies

use database\DatabaseManager;
use setting\model\SettingModel;

Settings

Declaration and architectural role

class Settings

Constants, enum cases, traits and properties

Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.

Member Declaration Purpose or source contract
$database private DatabaseManager $database; Used by __construct(), fetchSettings(), createSetting().
$settings private array $settings; Used by __construct(), fetchSettings(), initSettings(), getSettings(), getSetting().

Method index

Method Signature
__construct public function __construct()
fetchSettings public function fetchSettings(): self
initSettings public function initSettings(): self
getSettings public function getSettings(): array
getSetting public function getSetting(string $name): ?SettingModel
createSetting public function createSetting(int $package_id, string $name, string $value, int $perm, string $value_type = "text", string $category = "Miscellaneous"): int

__construct

Source line 12

public function __construct()

State writes: $this->database, $this->settings.

Implementation, validation guards and interaction order
public function __construct()
    {
        $this->database = new DatabaseManager();
        $this->settings = [];
    }

fetchSettings

Source line 18

public function fetchSettings(): self

State writes: $this->settings[$setting["id"]].

Return expressions (including local callbacks): $this.

Implementation, validation guards and interaction order
public function fetchSettings(): self
    {
        $result = $this->database->
        table("awt_setting")->
        select(["awt_setting.id", "awt_package.name AS package_name", "awt_setting.package_id", "awt_setting.name", "awt_setting.value", "awt_setting.value_type", "awt_setting.category", "awt_setting.required_permission_level"])->
        join("awt_package", "awt_package.id = awt_setting.package_id")->
        where(["1" => 1])->
        get();

        foreach ($result as $setting) {
            $this->settings[$setting["id"]] = new SettingModel($setting["id"], $setting["package_name"], $setting);
        }

        return $this;
    }

initSettings

Source line 34

public function initSettings(): self

Return expressions (including local callbacks): $this.

Implementation, validation guards and interaction order
public function initSettings(): self
    {
        foreach ($this->settings as $setting) {
            $setting->createObjectConstant();
        }
        return $this;
    }

getSettings

Source line 42

public function getSettings(): array

Return expressions (including local callbacks): $this->settings.

Implementation, validation guards and interaction order
public function getSettings(): array
    {
        return $this->settings;
    }

getSetting

Source line 47

public function getSetting(string $name): ?SettingModel

Parameters

Parameter Type, modifiers and default Purpose
$name string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.

Return expressions (including local callbacks): $setting; null.

Implementation, validation guards and interaction order
public function getSetting(string $name): ?SettingModel
    {
        foreach ($this->settings as $setting) {
            if ($setting->getName() === $name) {
                return $setting;
            }
        }

        return null;
    }

createSetting

Source line 58

public function createSetting(int $package_id, string $name, string $value, int $perm, string $value_type = "text", string $category = "Miscellaneous"): int

Parameters

Parameter Type, modifiers and default Purpose
$package_id int $package_id Operation input; the exact use, validation and propagation are shown in the implementation trace.
$name string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.
$value string $value Operation input; the exact use, validation and propagation are shown in the implementation trace.
$perm int $perm Operation input; the exact use, validation and propagation are shown in the implementation trace.
$value_type string $value_type = "text" Operation input; the exact use, validation and propagation are shown in the implementation trace.
$category string $category = "Miscellaneous" Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): 0; $this->database->table("awt_setting")->insert([ "package_id" => $package_id, "name" => $name, "value" => $value, "value_type" => $value_type, "category" => $category, "required_permission_level" => $perm ])->executeInsert().

Implementation, validation guards and interaction order
public function createSetting(int $package_id, string $name, string $value, int $perm, string $value_type = "text", string $category = "Miscellaneous"): int
    {


        $res = $this->database->table("awt_setting")->select(["id"])->where(["package_id" => $package_id, "name" => $name])->get();

        if($res !== null && count($res) > 0)
            return 0;

        return $this->database->table("awt_setting")->insert([
            "package_id" => $package_id,
            "name" => $name,
            "value" => $value,
            "value_type" => $value_type,
            "category" => $category,
            "required_permission_level" => $perm
        ])->executeInsert();
    }

Related types

Clone this wiki locally