waSystemConfig

Класс для получения информации о конфигурации фреймворка

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.

  • 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.

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

array(
  'mydomain.com' => array(
    'auth' => true,
    'app' => 'site',
  ),
  'seconddomain.com' => array(
    '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 = array())

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

array(
  'debug' => true,
  'backend_url' => 'admin',
  'mod_rewrite' => true,
)

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

array(
  'default' => array(
    '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

array(
  0 => 'en_US',
  1 => 'ru_RU',
)

Example

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

Result

array(
  'en_US' => array(
    'iso3' => 'usa',
    'name' => 'English',
    'region' => 'USA',
    'english_name' => 'English',
    'english_region' => 'USA',
    'date_formats' => array(
      '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' => array(
      'delim' => array(
        10 => '-',
        100 => ' and ',
      ),
    ),
    'currency' => 'USD',
  ),
  'ru_RU' => array(
    'iso3' => 'rus',
    'name' => 'Русский',
    'region' => 'Российская Федерация',
    'english_name' => 'Russian',
    'english_region' => 'Russian Federation',
    'date_formats' => array(
      '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' => array(
      'plural' => array(
        1000 => 2,
      ),
    ),
    'translit_table' => array(
      'А' => '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

array(
  'en_US' => 'English',
  'ru_RU' => 'Русский',
)

Example

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

Result

array(
  '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');