br() magic function to access everything

This function is the key of framework. Depending on calling paramaters it will work as best as you need to.


When called without paramateres - instance of Br class will be returned. Via calling to br() you can access all Bright objects and functions. For example:

// db
br()->db()->runQuery('UPDATE table SET field = ? WHERE key = ?', $val, $keyValue);

// session
$value = br()->session()->get('name');

// authorization
$login = br()->auth()->getLogin();

// cache
$value = br()->cache()->get('name');

// routing
    route('/', function() {

// file system

// Logger
br()->log()->writeLn('log message');

// etc...


When called with one paramater - instance of the corresponsing "sugar syntax" class will be returned: BrString if $value is a string, BrArray if $value is an array.

br($array, $keyName, $defaultValue = null)

When called with more that one paramateres - it will replace you following code:

$value = br($_POST, 'postParamName', 'defaultValue');

// equal to

if (isset($_POST['postParamName'])) {
  $value = $_POST['postParamName'];
} else {
  $value = 'defaultValue';