waSystemConfig

Class for reading the framework’s configuration information

Contents...

To obtain an instance of this class, use method wa()->getConfig().

Methods

  • getAuth

    Returns authorization parameters of all websites.

  • getBackendUrl

    Returns relative URL of backend.

  • getConfigFile

    Returns the contents of a system configuration file.

  • getConfigPath

    Returns the path to a configuration file.

  • getCurrentUrl

    Returns relative URL of current HTTP request.

  • getDatabase

    Returns database configurations.

  • getDomain

    Returns current HTTP request’s URL domain name.

  • getHostUrl

    Returns current HTTP request’s host URL.

  • getLocales

    Returns information of all locales enabled in framework configuration.

  • getPath

    Returns the path to a framework’s directory or PHP file.

  • getRequestUrl

    Returns current HTTP request URL.

  • getRootPath

    Returns the path to framework’s root directory.

  • getRootUrl

    Returns framework’s root URL.

  • isDebug

    Returns debug mode status.

  • systemOption

    Returns a system configuration parameter value.

  • getAppsPath

    Returns the path to an app’s files directory.

  • getRouting

    Returns the contents of the frontend routing configuration file applicable for the current configuration class instance.

public function getAuth()

Returns authorization parameters of all websites. For each website, the method returns the authorization setting status and the ID of the app selected for managing website visitors’ login and signup. If the authorization option is not enabled in a website’s settings, then the method either does not include that website in its return value or returns an empty array for it.

Example

$auth_config = wa()->getConfig()->getAuth();

Result

[
    'mydomain.com' => [
        'auth' => true,
        'app' => 'site',
    ],
    'seconddomain.com' => [
        'auth' => true,
        'app' => 'shop',
    ],
]

public function getBackendUrl ($with_root_url = false)

Returns relative URL of backend.

Parameters

  • $with_root_url

    Flag requiring to return backend URL with a leading and a trailing slash. By default (false) backend URL is returned without slashes.

Example

wa()->getConfig()->getBackendUrl();

Result

webasyst

Example

wa()->getConfig()->getBackendUrl(true);

Result

/webasyst/

public function getConfigFile ($file, $default = [])

Returns the contents of a system configuration file.

Parameters

  • $file

    Name of a configuration file in directory wa-config/.

  • $default

    Default value which must be returned if the specified file does not exist.

Example

wa()->getConfig()->getConfigFile('config');

Result

[
    'debug' => true,
    'backend_url' => 'admin',
    'mod_rewrite' => true,
]

public function getConfigPath ($name, $user_config = true, $app = null)

Returns the path to a configuration file.

Parameters

  • $name

    File name.

  • $user_config

    Flag denoting that the file is used for storing configuration values specified by users; in this case the method returns a path in the wa-config/apps/[app_id] directory. Otherwise it returns a path in the wa-apps/[app_id]/lib/config directory.

  • $app

    App ID. If no value is specified then the method returns the to a framework configuration file.

Example

wa()->getConfig()->getConfigPath('workflow.php', true, 'shop');

Result

/var/www/wa-config/apps/shop/workflow.php

public function getCurrentUrl()

Returns relative URL of current HTTP request.

Example

wa()->getConfig()->getCurrentUrl();

Result

/webasyst/blog/?plugin=test&action=settings

public function getDatabase()

Returns the configurations of all databases connected to the framework, from file wa-config/db.php.

Example

wa()->getConfig()->getDatabase();

Result

[
    'default' => [
        'type' => 'mysqli',
        'host' => 'localhost',
        'port' => '3306',
        'user' => 'admin',
        'password' => 'qL5UfHtoV4k8Xw7M',
        'database' => 'webasyst',
        'sql_mode' => 'TRADITIONAL',
    ],
]

public function getDomain()

Returns current HTTP request’s URL domain name.

Example

wa()->getConfig()->getDomain();

Result

mydomain.com

public function getHostUrl()

Returns the current HTTP request’s host URL without trailing slash.

Example

wa()->getConfig()->getHostUrl();

Result

https://mydomain.com

public function getLocales ($type = false)

Returns information of all locales enabled in framework’s configuration file wa-config/locale.php.

Parameters

  • $type

    Return values format:

    • true or 'all': return all available information about enabled locales.
    • 'name_region': for each locale return a string of the form “Locale name (Region name from locale properties)”. Example: “English (United States)”.
    • 'name': return only locale names. Example: “English>".
    • false: return only locale IDs (default format).

Example

wa()->getConfig()->getLocales();

Result

[
    0 => 'en_US',
    1 => 'ru_RU',
]

Example

wa()->getConfig()->getLocales(true);

Result

[
    'en_US' => [
        'iso3' => 'usa',
        'name' => 'English',
        'region' => 'USA',
        'english_name' => 'English',
        'english_region' => 'USA',
        'date_formats' => [
            'humandate' => 'F j, Y',
            'date' => 'm/d/Y',
            'dtime' => 'd/m H:i',
            'datetime' => 'm/d/Y H:i',
            'fulldatetime' => 'm/d/Y H:i:s',
        ],
        'decimal_point' => '.',
        'frac_digits' => '2',
        'thousands_sep' => ',',
        'first_day' => 7,
        'amount_in_words' => [
            'delim' => [
                10 => '-',
                100 => ' and ',
            ],
        ],
        'currency' => 'USD',
    ],
    'ru_RU' => [
        'iso3' => 'rus',
        'name' => 'Русский',
        'region' => 'Российская Федерация',
        'english_name' => 'Russian',
        'english_region' => 'Russian Federation',
        'date_formats' => [
            'humandate' => 'j f Y',
            'date' => 'd.m.Y',
            'dtime' => 'd.m H:i',
            'datetime' => 'd.m.Y H:i',
            'fulldatetime' => 'd.m.Y H:i:s',
        ],
        'date_month_postfix' => 'я',
        'decimal_point' => ',',
        'frac_digits' => '2',
        'thousands_sep' => ' ',
        'first_day' => 1,
        'amount_in_words' => [
            'plural' => [
                1000 => 2,
            ],
        ],
        'translit_table' => [
            'А' => 'A',
            'Б' => 'B',
            'В' => 'V',
            'Г' => 'G',
            'Д' => 'D',
            'Е' => 'Ye',
            'Ё' => 'Yo',
            'Ж' => 'Zh',
            'З' => 'Z',
            'И' => 'I',
            'Й' => 'Y',
            'К' => 'K',
            'Л' => 'L',
            'М' => 'M',
            'Н' => 'N',
            'О' => 'O',
            'П' => 'P',
            'Р' => 'R',
            'С' => 'S',
            'Т' => 'T',
            'У' => 'U',
            'Ф' => 'F',
            'Х' => 'Kh',
            'Ц' => 'Ts',
            'Ч' => 'Ch',
            'Ш' => 'Sh',
            'Щ' => 'Shch',
            'Ь' => '',
            'Ы' => 'Y',
            'Ъ' => '',
            'Э' => 'E',
            'Ю' => 'Yu',
            'Я' => 'Ya',
            'а' => 'a',
            'б' => 'b',
            'в' => 'v',
            'г' => 'g',
            'д' => 'd',
            'е' => 'e',
            'ё' => 'yo',
            'ж' => 'zh',
            'з' => 'z',
            'и' => 'i',
            'й' => 'y',
            'к' => 'k',
            'л' => 'l',
            'м' => 'm',
            'н' => 'n',
            'о' => 'o',
            'п' => 'p',
            'р' => 'r',
            'с' => 's',
            'т' => 't',
            'у' => 'u',
            'ф' => 'f',
            'х' => 'kh',
            'ц' => 'ts',
            'ч' => 'ch',
            'ш' => 'sh',
            'щ' => 'shch',
            'ь' => '',
            'ы' => 'y',
            'ъ' => '',
            'э' => 'e',
            'ю' => 'yu',
            'я' => 'ya',
        ],
        'currency' => 'RUB',
    ],
];

Example

wa()->getConfig()->getLocales('name');

Result

[
    'en_US' => 'English',
    'ru_RU' => 'Русский',
]

Example

wa()->getConfig()->getLocales('name_region');

Result

[
    'en_US' => 'English (USA)',
    'ru_RU' => 'Русский (Российская Федерация)',
]

public function getPath ($name, $file = null)

Returns the path to a framework’s directory or PHP file.

Parameters

  • $name

    Framework’s subdirectory code from the list below.

    • 'root': root directory
    • 'apps': wa-apps/
    • 'cache': wa-cache/
    • 'config': wa-config/
    • 'content': wa-content/
    • 'data': wa-data/
    • 'installer': wa-installer/
    • 'log': wa-log/
    • 'plugins': wa-plugins/
    • 'system': wa-system/
    • 'widgets': wa-widgets/
  • $file

    Name of a PHP file, without an extension, in the specified directory.

Example

wa()->getConfig()->getPath('data');

Result

/var/www/mywebsite/wa-data

Example

wa()->getConfig()->getPath('data', 'public/shop/products/thumb');

Result

/var/www/mywebsite/wa-data/public/shop/products/thumb.php

public function getRequestUrl ($without_root = true, $without_params = false)

Returns current HTTP request URL.

Parameters

  • $without_root

    Flag requiring to return a relative URL. By default (true) relative URL is returned.

  • $without_params

    Flag requiring to return a URL without GET parameters. By default (false) URLs are returned with GET parameters.

Example

wa()->getConfig()->getRequestUrl()

Result

webasyst/myapp/?action=save

Example

wa()->getConfig()->getRequestUrl(false)

Result

https://mydomain.com/webasyst/myapp/?action=save

Example

wa()->getConfig()->getRequestUrl(false, true)

Result

https://mydomain.com/webasyst/myapp/

public function getRootPath()

Returns the path to framework’s root directory.

Example

wa()->getConfig()->getRootPath()

Result

/var/www/mywebsite

public function getRootUrl ($absolute = false, $script = false)

Returns framework’s root URL.

Parameters

  • $absolute

    Flag requiring to return an absolute URL. By default (false) relative URLs are returned.

  • $script

    Flag requiring to include string 'index.php' in the returned URL. The flag is used only with parameter mod_rewrite enabled in configuration file wa-config/config.php.

Example

wa()->getConfig()->getRootUrl()

Result

/

Example

wa()->getConfig()->getRootUrl(true)

Result

https://mydomain.com/

public static function isDebug()

Returns debug mode status.

Example

$debug_mode_enabled = waSystemConfig::isDebug();

public static function systemOption ($name)

Returns a system configuration parameter value.

Parameters

  • $name

    Name of a parameter in configuration file wa-config/config.php.

Example

$mod_rewrite_enabled = waSystemConfig::systemOption('mod_rewrite');

public function getAppsPath ($app, $path = null)

Returns the path to an app’s files directory.

Parameters/h4>
  • $app

    App ID.

  • $path

    Relative path to the app’s files sub-directory. If no value is specified then the path to the app’s files root directory is returned.

Example

wa()->getConfig()->getAppsPath('shop', 'plugins');

Result

/var/www/wa-apps/shop/plugins

public function getRouting()

Returns the contents of the frontend routing configuration file applicable for the current configuration class instance.

Example

// routing configuration of 'site' app
wa('site')->getConfig()->getRouting();

Result

[
    'login/' => 'login/',
    'forgotpassword/' => 'forgotpassword/',
    'signup/' => 'signup/',
    'data/regions/' => 'frontend/regions',
    'my/' => [
      'module' => 'frontend',
      'action' => 'my',
      'secure' => true,
    ],
    '<url>' => 'frontend/',
]</url>

Example

// routing configuration of all sites' settlements
wa('wa-system')->getConfig()->getRouting();

Result

[
    'mydomain.com' => [
        22 => [
            'url' => 'blog/*',
            'app' => 'blog',
            'theme' => 'default',
            'theme_mobile' => 'default',
            'locale' => 'en_US',
            'blog_url_type' => '2',
            'post_url_type' => '0',
            'title_type' => 'blog_post',
            'title' => 'TITLE',
            'meta_keywords' => 'KEYWORDS',
            'meta_description' => 'DESCRIPTION',
            'rss_title' => '0',
        ],
        23 => [
            'url' => 'info/*',
            'app' => 'site',
            'theme' => 'hypermarket',
            'theme_mobile' => 'mobile',
            'locale' => 'en_US',
        ],
        24 => [
            'url' => '*',
            'app' => 'shop',
            'theme' => 'default',
            'theme_mobile' => 'default',
            'checkout_version' => '2',
            'locale' => 'en_US',
            'title' => '',
            'meta_keywords' => '',
            'meta_description' => '',
            'og_title' => '',
            'og_image' => '',
            'og_video' => '',
            'og_description' => '',
            'og_type' => '',
            'og_url' => '',
            'url_type' => '0',
            'products_per_page' => '',
            'type_id' => '0',
            'currency' => 'RUB',
            'public_stocks' => '0',
            'drop_out_of_stock' => '0',
            'payment_id' => '0',
            'shipping_id' => '0',
            'checkout_storefront_id' => '41c1fb59db445e1b2aa68102f56e161e',
        ],
    ],
    'mydomain2.com' => [
        // ...
    ],
]