Functions

PHP functions defined in Webasyst framework

Contents...
  • ifempty

    Returns specified non-empty variable value or, if value empty, default value.

  • ifset

    Returns value of existing variable or array item, or, if variable or array key does not exist, default value.

  • wa

    Loads specified app's configuration into memory.

  • wa_array_diff_r

    Recursively calculates difference between two specified multi-dimensional arrays.

  • wa_backend_url

    Returns relative backend URL.

  • wa_currency

    Returns formatted amount of money using specified currency and current locale.

  • wa_currency_html

    Returns formatted amount of money using specified currency's HTML sign and current locale.

  • wa_date

    Returns formatted date and time value.

  • wa_dump

    Dumps debugging information about specified values on a web page and terminates execution of PHP script.

  • wa_dumpc

    Dumps debugging information about specified values on a web page without terminating execution of PHP script.

  • wa_header

    Returns main backend menu HTML.

  • wa_is_int

    Checks whether specified value is an integer or a string containing only one integer.

  • wa_make_pattern

    Generates a regular expression from a string.

  • wa_parse_date

    Returns time value, formatted using one of the formats supported by Webasyst framework, as a string acceptable by standard PHP functions.

  • wa_url

    Returns relative root Webasyst URL.

  • wao

    Returns instance of class by specified class constructor call, for calling its public methods.

function ifempty (&$var, $def = null)

Returns specified non-empty value or, if empty, default value is returned. Variable value is checked using PHP function empty(). If variable did not exist before being passed to function, it is created with null value.

Parameters

  • $var

    Variable whose value must be checked.

  • $def

    Default value which will be returned if variable value is determined as empty.

Example

$var = 1;
ifempty($var); //returns 1
    
$var = 0;
ifempty($var); //returns standard default value null
    
$var = 0;
ifempty($var, array()); //returns custom default value array()

function ifset (&$var, $def=null)

Returns value of existing variable or array item, or, if variable or array key does not exist, default value. Variable value is checked using PHP function isset(). If variable did not exist before being passed to function, it is created with null value.

Parameters

  • $var

    Variable or array item which must be checked for being set.

  • $def

    Default value which will be returned if variable or array key is determined as not set.

Example

//variable $var is not set
//function returns default value
ifset($var); //returns null

//$var variable value is null
//function returns default value
$var = null;
ifset($var, array()); //returns custom default value array()


//value of $var variable is not null
//function returns variable value
$var = 1;
ifset($var, array()); //returns 1

function wa ($name = null, $set_current = false)

Calls method waSystem::getInstance() for loading configuration; e.g., PHP classes, of specified app into memory.

Parameters

  • $name

    App ID.

  • $set_current

    Flag requiring to load localization of specified app upon function call.

Example

//function call only makes available
//PHP classes of 'blog' app
wa('blog');

//function call makes available
//PHP classes AND localization of 'blog' app
wa('blog', true);

function wa_array_diff_r ($value1, $value2, &$diff)

Recursively calculates difference between two specified multi-dimensional arrays, saves the diff to $diff variable passed by reference, and returns Boolean value denoting whether specified arrays are different or not.

Parameters

  • $value1

    Array #1.

  • $value2

    Array #2.

  • $diff

    Variable to store the diff.

Example

$different = wa_array_diff_r($array1, $array2, $difference);
wa_dump($different); //finding out whether arrays are different
wa_dump($difference); //printing the diff

function wa_backend_url ()

Returns relative backend URL. Note that it can be different from /webasyst/.

Example

wa_backend_url();

Result

/webasyst/

function wa_currency ($n, $currency, $format = '%{s}')

Returns formatted amount of money with specified currency using current locale.

Parameters

  • $n

    Number denoting an amount of money.

  • $currency

    ISO3 currency code.

  • $format

    Currency displaying format supported by method waCurrency::format(). By default, format string '%{s}' is used.

Example

wa_currency (123456.78, 'USD');

Result

$123,456.78

function wa_currency_html ($n, $currency, $format = '%{h}')

Returns formatted amount of money using specified currency's HTML sign and current locale, if that currency has an HTML sign. Otherwise simple currency sign is used, if no other format is specified for $format parameter.

Parameters

  • $n

    Number denoting an amount of money.

  • $currency

    ISO3 currency code.

  • $format

    Currency displaying format supported by method waCurrency::format(). By default, format string '%{h}' is used.

Example

wa_currency_html (123456.78, 'RUB');
wa_currency_html (123456.78, 'USD');

Result

123,456.78 <span class="ruble">Р</span>
$123,456.78

function wa_date ($format, $time = null, $timezone = null, $locale = null)

Returns formatted date and time value using method waDateTime::format().

Parameters

  • $format

    Date/time format. The following format strings are acceptable:

    • humandatetime: adds words "yesterday", "today", "tomorrow" instead of appropriate dates relative to the current user date
    • humandate: returns the date in format d f Y supported by method waDateTime::date() (format strings listed below are also supported by that method)
    • date: returns date/time in format Y-m-d
    • time: returns date/time in format H:i
    • fulltime: returns date/time in format H:i:s
    • datetime: returns date/time in format Y-m-d H:i
    • fulldatetime: returns date/time in format Y-m-d H:i:s
    • timestamp: returns date/time in format U
  • $time

    Unix timestamp. If not specified, current timestamp is used.

  • $timezone

    Time zone identifier. If not specified, the time zone is determined automatically.

  • $locale

    Locale identifier. If not specified, the current user locale is determined automatically.

Example

wa_date('humandatetime');

Result

Today 17:11

function wa_dump ()

Dumps debugging information about specified values on a web page and terminates execution of PHP script.

Parameters

  • $var1, var2, ...

    Any number of values of any type, specified in a comma as function arguments.

Example

$var1 = 1;
$var2 = 2;
wa_dump($var1, $var2);

Result

1
2

function wa_dumpc ()

Dumps debugging information about specified values on a web page without terminating execution of PHP script.

Parameters

  • $var1, var2, ...

    Any number of values of any type, specified in a comma as function arguments.

Example

$var1 = 1;
$var2 = 2;
wa_dumpc($var1, $var2);

Result

1
2

function wa_header ()

Returns main backend menu HTML.

function wa_is_int ($val)

Checks whether specified value is an integer or a string containing only one integer.

Parameters

  • $val

    Value to be checked.

Example

wa_is_int(null);  //false
wa_is_int(false); //false
wa_is_int(true);  //false
wa_is_int(0);     //true
wa_is_int('0');   //true
wa_is_int(1);     //true
wa_is_int('1');   //true
wa_is_int(0.1);   //false
wa_is_int('0.1'); //false

function wa_make_pattern ($string, $separator = '/')

Generates a regular expression from a string.

Parameters

  • $string

    String to generate a regular expression from.

  • $separator

    Character to be escaped by backslash \ in generated regular expression.

Example

wa_make_pattern('test');
wa_make_pattern('test|');
wa_make_pattern('test|', '|');

Result

'test';
'test|'
'test\|'

function wa_parse_date ($format, $string, $timezone = null, $locale = null)

Returns time value (using waDateTime::parse() method), formatted with one of the formats supported by Webasyst framework, as a string acceptable by standard PHP functions.

Parameters

  • $format

    Format string accepted by waDateTime::format() except for humandatetime.

  • $string

    Date/time value string formatted to match the format identifier specified in $format parameter.

  • $timezone

    Time zone identifier. If not specified, the time zone is determined automatically.

  • $locale

    Locale identifier. If not specified, the current user locale is determined automatically.

Example

wa_parse_date ('humandate', 'November 8, 2013', null, 'en_US');

Result

2013-11-08

function wa_url ()

Returns relative root Webasyst URL.

Example

wa_url();

Result

/

function wao ($o)

Returns instance of class by specified class constructor call, for calling its public methods.

Parameters

  • $o

    Call of constructor of a class whose public method must be used.

Example

$settings_html = wao(new myappBackendSettingsAction())->display();