Functions

PHP functions defined in Webasyst framework

Contents...

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

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

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

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

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

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

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

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

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

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

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

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

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

Example

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