Elgg\Http\Input::get PHP Метод

get() публичный Метод

If using any data obtained from get_input() in a web page, please be aware that it is a possible vector for a reflected XSS attack. If you are expecting an integer, cast it to an int. If it is a string, escape quotes. Note: this function does not handle nested arrays (ex: form input of param[m][n]) because of the filtering done in htmlawed from the filter_tags call.
public get ( string $variable, mixed $default = null, boolean $filter_result = true ) : mixed
$variable string The variable name we want.
$default mixed A default value for the variable if it is not found.
$filter_result boolean If true, then the result is filtered for bad tags.
Результат mixed
    function get($variable, $default = null, $filter_result = true)
    {
        $result = $default;
        elgg_push_context('input');
        if (isset($this->CONFIG->input[$variable])) {
            // a plugin has already set this variable
            $result = $this->CONFIG->input[$variable];
            if ($filter_result) {
                $result = filter_tags($result);
            }
        } else {
            $request = _elgg_services()->request;
            $value = $request->get($variable);
            if ($value !== null) {
                $result = $value;
                if (is_string($result)) {
                    // @todo why trim
                    $result = trim($result);
                }
                if ($filter_result) {
                    $result = filter_tags($result);
                }
            }
        }
        elgg_pop_context();
        return $result;
    }

Usage Example

Пример #1
0
 /**
  * Filter an AjaxResponse through a plugin hook
  *
  * @param AjaxResponse $api_response The API Response
  * @param string       $hook_type    The hook type. If given, the response will be filtered by hook
  *
  * @return AjaxResponse
  */
 private function filterApiResponse(AjaxResponse $api_response, $hook_type = '')
 {
     $api_response->setTtl($this->input->get('response_ttl', 0, false));
     if ($hook_type) {
         $hook = AjaxResponse::RESPONSE_HOOK;
         $api_response = $this->hooks->trigger($hook, $hook_type, null, $api_response);
         if (!$api_response instanceof AjaxResponse) {
             throw new \RuntimeException("The value returned by hook [{$hook}, {$hook_type}] was not an ApiResponse");
         }
     }
     return $api_response;
 }