/**
 * Initialize params from URL query string. The function
 * creates globals variables for each of the params
 * and if the URL query string doesn't specify a particular
 * param initializes them with the corresponding default
 * value specified in the input.
 *
 * @params array $params An array whose keys are the names
 *                       of URL params who value needs to
 *                       be retrieved from the URL query
 *                       string. PHP globals are created
 *                       with these names. The value is
 *                       itself an array with 2-elems (the
 *                       param type, and its default value).
 *                       If a param is not specified in the
 *                       query string the default value is
 *                       used.
 * @author Kannan
 */
function xhprof_param_init($params)
{
    /* Create variables specified in $params keys, init defaults */
    foreach ($params as $k => $v) {
        switch ($v[0]) {
            case XHPROF_STRING_PARAM:
                $p = xhprof_get_string_param($k, $v[1]);
                break;
            case XHPROF_UINT_PARAM:
                $p = xhprof_get_uint_param($k, $v[1]);
                break;
            case XHPROF_FLOAT_PARAM:
                $p = xhprof_get_float_param($k, $v[1]);
                break;
            case XHPROF_BOOL_PARAM:
                $p = xhprof_get_bool_param($k, $v[1]);
                break;
            default:
                xhprof_error("Invalid param type passed to xhprof_param_init: " . $v[0]);
                // gg: let the script go on anyway
                //exit();
                throw new Exception("Invalid param type passed to xhprof_param_init: " . $v[0]);
        }
        // create a global variable using the parameter name.
        $GLOBALS[$k] = $p;
    }
}
Example #2
0
/**
 * Initialize params from URL query string. The function
 * creates globals variables for each of the params
 * and if the URL query string doesn't specify a particular
 * param initializes them with the corresponding default
 * value specified in the input.
 *
 * @params array $params An array whose keys are the names
 *                       of URL params who value needs to
 *                       be retrieved from the URL query
 *                       string. PHP globals are created
 *                       with these names. The value is
 *                       itself an array with 2-elems (the
 *                       param type, and its default value).
 *                       If a param is not specified in the
 *                       query string the default value is
 *                       used.
 * @author Kannan
 */
function xhprof_param_init($params)
{
    /* Create variables specified in $params keys, init defaults */
    foreach ($params as $k => $v) {
        switch ($v[0]) {
            case XHPROF_STRING_PARAM:
                $p = xhprof_get_string_param($k, $v[1]);
                break;
            case XHPROF_UINT_PARAM:
                $p = xhprof_get_uint_param($k, $v[1]);
                break;
            case XHPROF_FLOAT_PARAM:
                $p = xhprof_get_float_param($k, $v[1]);
                break;
            case XHPROF_BOOL_PARAM:
                $p = xhprof_get_bool_param($k, $v[1]);
                break;
            default:
                xhprof_error("Invalid param type passed to xhprof_param_init: " . $v[0]);
                exit;
        }
        if ($k === 'run') {
            $p = implode(',', array_filter(explode(',', $p), 'ctype_xdigit'));
        }
        // create a global variable using the parameter name.
        $GLOBALS[$k] = $p;
    }
}