Documentation/Container/Services/Settings

Settings

The Settings service allows you to obtain standard or custom framework settings from the files within the /config/ directory.

Methods of using Settings in controllers (and all classes inherited from Hleb\Base\Container) exemplified by retrieving the designated timezone from the /config/common.php file:

// variant 1
use Hleb\Reference\SettingInterface;
$timezone $this->container->get(SettingInterface::class)->getParam('common''timezone');

// variant 2
$timezone $this->container->settings()->getParam('common''timezone');

// variant 3
$timezone $this->settings()->getParam('common''timezone');

Example of accessing Settings within application code:

// variant 1
use Hleb\Static\Container;
use 
Hleb\Reference\SettingInterface;
$timezone Container::get(SettingInterface::class)->getParam('common''timezone');

// variant 2
use Hleb\Static\Settings;
$timezone Settings::getParam('common''timezone');

// variant 3
$timezone config('common''timezone');

The Settings object can also be obtained through dependency injection via the interface Hleb\Reference\Interface\Setting.

Settings are divided into four groups: 'common', 'main', 'database', and 'system'. They correspond to the configuration files within the /config/ directory. If a different file is being used, such as 'main-local.php' instead of 'main.php', the setting must still be retrieved using the name 'main'.

The service methods - common(), main(), database(), and system() allow for retrieving parameters from the respective settings. For example:

use Hleb\Static\Settings;

$timezone Settings::common('timezone');
Router CSRF Protection

Page translated: chatgpt 4-o
Back to top