Show:

Q Class

Module: Q

Core Qbix platform functionality

Methods

autoload

(
  • $className
)
static

Default autoloader for Q

Parameters:

  • $className String

b

(
  • $separator=",&#32;<br>\n"
)
String static

Backtrace as html

Parameters:

  • $separator=",&#32;<br>\n" String

Returns:

String:

backtrace

(
  • $pattern='$class::$function&#32;(from&#32;line&#32;$line)'
  • $skip=2
)
static

Return backtrace

Parameters:

  • $pattern='$class::$function&#32;(from&#32;line&#32;$line)' String
  • $skip=2 Integer

call

(
  • $callback
  • $params=array()
)
Mixed static

A replacement for call_user_func_array that implements some conveniences.

Parameters:

  • $callback Callable
  • $params=array() Array

Returns:

Mixed:

Returns whatever the function returned.

canHandle

(
  • $handler_name
  • $skip_include=false
)
Boolean static

Tests whether a particular handler exists

Parameters:

  • $handler_name String

    The name of the handler. The handler can be overridden via the include path, but an exception is thrown if it is missing.

  • $skip_include=false Boolean

    Defaults to false. If true, no file is loaded; the handler is executed only if the function is already defined; otherwise, null is returned.

Returns:

Boolean:

Whether the handler exists

compareVersion

(
  • $a
  • $b
)
-1 | 0 | 1 static

Compares version strings in the format A.B.C...

Parameters:

  • $a String
  • $b String

Returns:

-1 | 0 | 1:

do_dump

(
  • $var
  • $var_name=null
  • $indent=null
  • $reference=null
  • $as_text=false
)
private static

Parameters:

  • $var &mixed
  • $var_name=null String
  • $indent=null String
  • $reference=null String
  • $as_text=false Boolean

dump_table

(
  • $rows
)
static

Dumps as a table

Parameters:

  • $rows Array

errorHandler

(
  • $errno
  • $errstr
  • $errfile
  • $errline
  • $errcontext
)

Error handler

Parameters:

  • $errno Integer
  • $errstr String
  • $errfile String
  • $errline Integer
  • $errcontext Array

evalExpression

(
  • $expression
  • $params=array()
)
Mixed static

Evaluates a string containing an expression, with possible references to parameters. CAUTION: make sure the expression is safe!!

Parameters:

  • $expression String

    The code to eval.

  • $params=array() Array

    Optional. An array of parameters to the expression. Variable names in the expression can refer to them.

Returns:

Mixed:

The result of the expression

event

(
  • $eventName
  • $params=array()
  • $pure=false
  • $skipIncludes=false
  • $result=null
)
Mixed static

Fires a particular event. Might result in several handlers being called.

Parameters:

  • $eventName String

    The name of the event

  • $params=array() Array

    Parameters to pass to the event

  • $pure=false Boolean

    Defaults to false. If true, the handler of the same name is not invoked. Put true here if you just want to fire a pure event, without any default behavior. If 'before', only runs the "before" handlers, if any. If 'after', only runs the "after" handlers, if any. You'd want to signal events with 'before' and 'after' before and after some "default behavior" happens. Check for a non-null return value on "before", and cancel the default behavior if it is present.

  • $skipIncludes=false Boolean

    Defaults to false. If true, no new files are loaded. Only handlers which have already been defined as functions are run.

  • $result=null Reference

    Defaults to null. You can pass here a reference to a variable. It will be returned by this function when event handling has finished, or has been aborted by an event handler. It is passed to all the event handlers, which can modify it.

Returns:

Mixed:

Whatever the default event handler returned, or the final value of $result if it is modified by any event handlers.

eventStack

(
  • $eventName=null
)
Array | False static

Returns stack of events currently being executed.

Parameters:

  • $eventName=null String

    Optional. If supplied, searches event stack for this event name. If found, returns the latest call with this event name. Otherwise, returns false

Returns:

Array | False:

exceptionHandler

(
  • $exception
)

Default exception handler for Q

Parameters:

  • $exception Exception

handle

(
  • $handler_name
  • $params=array()
  • $skip_include=false
  • $result=null
)
Mixed static

Executes a particular handler

Parameters:

  • $handler_name String

    The name of the handler. The handler can be overridden via the include path, but an exception is thrown if it is missing.

  • $params=array() Array

    Parameters to pass to the handler. They may be altered by the handler, if it accepts $params as a reference.

  • $skip_include=false Boolean

    Defaults to false. If true, no file is loaded; the handler is executed only if the function is already defined; otherwise, null is returned.

  • $result=null &mixed

    Optional. Lets handlers modify return values of events.

Returns:

Mixed:

Whatever the particular handler returned, or null otherwise;

ifset

(
  • $ref
  • $def=null
)
Mixed

Used for shorthand for avoiding when you don't want to write (isset($some_long_expression) ? $some_long_expression: null) when you want to avoid possible "undefined variable" errors.

Parameters:

  • $ref &mixed

    The reference to test. Only lvalues can be passed. If $ref is an array or object, it can be followed by one or more strings or numbers, which will be used to index deeper into the contained arrays or objects. You can also pass arrays instead of the strings and numbers, which will then widen the search to try all combinations of the strings and numbers in all the arrays, before returning the default.

  • $def=null Mixed

    The default, if the reference isn't set

Returns:

Mixed:

includeFile

(
  • $filename
  • $params=array()
  • $once=false
  • $get_vars=false
)
Mixed static

Includes a file and evaluates code from it. Uses Q::realPath().

Parameters:

  • $filename String

    The filename to include

  • $params=array() Array

    Optional. Extracts this array before including the file.

  • $once=false Boolean

    Optional. Whether to use include_once instead of include.

  • $get_vars=false Boolean

    Optional. If true, returns the result of get_defined_vars() at the end. Otherwise, returns whatever the file returned.

Returns:

Mixed:

Depends on $get_vars

interpolate

(
  • $expression
  • $params=array()
)
String static

Goes through the params and replaces any references to their names in the string with their value. References are expected to be of the form {{varname}} or $varname. However, dollar signs prefixed with backslashes will not be replaced.

Parameters:

  • $expression String

    The string containing possible references to interpolate values for.

  • $params=array() Array | String

    An array of parameters to the expression. Variable names in the expression can refer to them. You can also pass an indexed array, in which case the expression's placeholders of the form {{0}}, {{1}}, or $0, $1 will be replaced by the corresponding strings. If the expression is missing {{0}} and $0, then {{1}} or $1 is replaced by the first string, {{2}} or $2 by the second string, and so on.

Returns:

String:

The result of the interpolation

log

(
  • $message
  • $key=null
  • $timestamp=true
  • $options
)
static

Append a message to the main log

Parameters:

  • $message Mixed

    the message to append. Usually a string.

  • $key=null String

    The name of log file. Defaults to "$app_name.log"

  • $timestamp=true Bool

    whether to prepend the current timestamp

  • $options Array
    • [maxLength=ini_get('log_errors_max_len')] Integer optional
    • [maxDepth=3] Integer optional

milliseconds

(
  • $sinceEpoch
)
Float

Returns the number of milliseconds since the first call to this function (i.e. since script started).

Parameters:

  • $sinceEpoch Boolean

    Defaults to false. If true, just returns the number of milliseconds in the UNIX timestamp.

Returns:

Float:

The number of milliseconds, with fractional part

parse_str

(
  • $search
  • $replace
  • $source
)
Array static

Replaces strings in all keys and values of an array, and nested arrays

Parameters:

  • $search String

    the first parameter to pass to str_replace

  • $replace String

    the first parameter to pass to str_replace

  • $source Array

    the array in which the values are found

Returns:

Array:

the resulting array

parse_str

(
  • $str
  • $arr
)
Array static

Parses a querystring like mb_parse_str but without converting some characters to underscores like PHP's version does

Parameters:

  • $str String
  • $arr Reference

    reference to an array to fill, just like in parse_str

Returns:

Array:

the resulting array of $field => $value pairs

readFile

(
  • $filename
  • $options
)
String static

Reads a file and caches it for a time period. Uses Q::realPath().

Parameters:

  • $filename String

    The name of the file to get the content of

  • $options Array
    • [duration=0] Integer optional

      Number of seconds to cache it for

    • [dontCache=false] Boolean optional

      whether to skip caching it

    • [ignoreCache=false] Boolean optional

      whether to ignore already cached result

Returns:

String:

the content of the file

realPath

(
  • $filename
  • $ignoreCache=false
)
String | False static

Check if a file exists in the include path And if it does, return the absolute path.

Parameters:

  • $filename String

    Name of the file to look for

  • $ignoreCache=false Boolean

    Defaults to false. If true, then this function ignores the cached value, if any, and attempts to search for the file. It will cache the new value.

Returns:

String | False:

The absolute path if file exists, false if it does not

reverseLengthCompare

() Integer private

Returns:

Integer:

startsWith

(
  • $text
  • $prefix
)
Boolean static

Test whether $text is prefixed by $prefix

Parameters:

  • $text String | Array

    The string or array of strings to check

  • $prefix String

Returns:

Boolean:

t

(
  • $text
)
String static

Use for surrounding text, so it can later be processed throughout.

Parameters:

  • $text String

Returns:

String:

take

(
  • $source
  • $fields
  • &$dest
)
Array | Object

Parameters:

  • $source Array | Object

    An array or object from which to take things.

  • $fields Array

    An array of fields to take or an associative array of fieldname => default pairs

  • &$dest Array | Object

    Optional reference to an array or object in which we will set values. Otherwise an empty array is used.

Returns:

Array | Object:

The $dest array or object, otherwise an array that has been filled with values.

test

(
  • $pattern
)

Parameters:

  • $pattern String

text

(
  • $expression
  • $params
  • [$convert=array()]
  • [$unconvert=array()]
)
static

A convenience method to use in your PHP templates. It is short for Q_Html::text(Q::interpolate($expression, ...)). In Handlebars templates, you just use {{interpolate expression ...}}

Parameters:

  • $expression String

    Same as in Q::interpolate()

  • $params Array

    Same as in Q::interpolate()

  • [$convert=array()] String optional

    Same as in Q_Html::text().

  • [$unconvert=array()] String optional

    Same as in Q_Html::text().

textMode

() Boolean static

Check if Qbix is ran as script

Returns:

Boolean:

tool

(
  • $name
  • $options=array()
  • [$extra=array()]
)
static

Instantiates a particular tool. Also generates javascript around it.

Parameters:

  • $name String

    The name of the tool, of the form "$moduleName/$toolName" The handler is found in handlers/$moduleName/tool/$toolName Also can be an array of $toolName => $toolOptions, in which case the following parameter, $options, is skipped.

  • $options=array() Array

    The options passed to the tool (or array of options arrays passed to the tools).

  • [$extra=array()] Array optional

    Options used by Qbix when rendering the tool.

    • [id] String optional

      An additional ID to distinguish tools instantiated side-by-side from each other, within the same parent HTMLElement.

    • [prefix] String optional

      Set a custom prefix for the tool's id

    • [cache=false] Boolean optional

      If true, then the Qbix front end will not replace existing tools with same id during Q.loadUrl when this tool appears in the rendered HTML

    • [merge=false] Boolean optional

      If true, the element for this tool is merged with the element of the tool already being rendered (if any), producing one element with markup for both tools and their options. This can be used more than once, merging multiple tools in one element. As part of the mege, the content this tool (if any) is prepended to the content of the tool which is already being rendered.

var_dump

(
  • $var
  • $max_levels=null
  • $label='$'
  • $return_content=null
)
String | Null static

Dumps a variable. Note: cannot show protected or private members of classes.

Parameters:

  • $var Mixed

    the variable to dump

  • $max_levels=null Integer

    the maximum number of levels to recurse

  • $label='$' String

    optional - label of the dumped variable. Defaults to $.

  • $return_content=null Boolean

    if true, returns the content instead of dumping it. You can also set to "text" to return text instead of HTML

Returns:

String | Null:

var_export

(
  • $var
)
String static

Exports a simple variable into something that looks nice, nothing fancy (for now) Does not preserve order of array keys.

Parameters:

  • $var &mixed

    the variable to export

Returns:

String:

view

(
  • $viewName
  • $params=array()
  • $options
)
String static

Renders a particular view

Parameters:

  • $viewName String

    The full name of the view

  • $params=array() Array

    Parameters to pass to the view

  • $options Array

    Some options

    • language String | Null

      Preferred language

Returns:

String:

The rendered content of the view

Properties

$bootstrapped

Boolean static

This is set to true when the bootstrapping process has completed successfully.

$cache

Array static

$controller

Array static

$event_empty

Array protected static

$event_stack

Array protected static

$event_stack_length

Integer protected static

$included_files

Array protected static

$state

Array static

$toolName

String static

$toolWasRendered

Array static

$var_dump_max_levels

Integer protected static

Events

$toolHandler

Renders the tool

Event Payload:

  • $options Array

    The options passed to the tool

Q/autoload

After

Event Payload:

  • className String
  • filename String

Q/autoload

Before

Event Payload:

  • $className String

Q/error

Event Payload:

  • errno Integer
  • errstr String
  • errfile String
  • errline Integer
  • errcontext Array

Q/exception

Event Payload:

  • exception Exception

Q/exception

Event Payload:

  • $exception Exception

Q/exception/native

Event Payload:

  • $exception Exception

Q/includeFile

Before

Skips includes to prevent recursion

Event Payload:

  • filename String

    The filename to include

  • params Array

    Optional. Extracts this array before including the file.

  • once Boolean

    Optional. Whether to use include_once instead of include.

  • get_vars Boolean

    Optional. Set to true to return result of get_defined_vars() at the end.

Q/missingTool

Renders the 'Missing Tool' content

Event Payload:

  • name Array

    The name of the tool

Q/missingView

Renders 'Missing View' page

Event Payload:

  • viewName String
  • viewpath String

Q/readFile

Before

Skips includes to prevent recursion

Event Payload:

  • $filename String

    The name of the file to get the content of

  • $options Array
    • duration Integer

      Number of seconds to cache it for

    • dontCache Boolean

      whether to skip caching it

    • ignoreCache Boolean

      whether to ignore already cached result

Q/realPath

After

Event Payload:

  • $result String

Q/t

Before

Q/tool/render

Before

Event Payload:

  • info String

    An array of $toolName => $options pairs

  • extra Array

    Options used by Qbix when rendering the tool. Can include:
    "id" => an additional ID to distinguish tools instantiated side-by-side from each other. Usually numeric.
    "cache" => if true, then the Qbix front end will not replace existing tools with same id during Q.loadUrl when this tool appears in the rendered HTML

Q/tool/render

After

Event Payload:

  • info String

    An array of $toolName => $options pairs

  • 'extra' Array

    Options used by Qbix when rendering the tool. Can include:
    "id" => an additional ID to distinguish tools instantiated side-by-side from each other. Usually numeric.
    "cache" => if true, then the Qbix front end will not replace existing tools with same id during Q.loadUrl when this tool appears in the rendered HTML

Q/view

Before

Event Payload:

  • viewName String
  • viewPath String
  • params String