Return a value from template context, optionally set a default and filter.

@param  string       $var     Variable name
@param  mixed        $default Default
@param  string|array $filter  Array or pipe-separated list of filters
@return mixed
339811
public function raw($var, $default = '', $filter = null)
    {
        $data = $this->get($var);
        if (is_null($data['data'])) {
            $data['data'] = $this->returnDefault($default);
        }
        if (is_string($filter)) {
            $filter = explode('|', $filter);
        }
        $filters = array_merge($data['filters'], (array) $filter);
        if (empty($filters)) {
            return $data['data'];
        }

        return $this->template()->filter($filters, $data['data']);
    }
363431
public function getArgument($num, $filter = null, $default = false)
  {
    if (!$this->hasArgument($num)) {
      return $default;
    }

    $v = $this->arguments[$num];

    return Filter::Value($v, $filter, $default);
  }
1252882
protected function createSearchFilter($filter, $value)
    {
        // Field name is always the first component
        $fieldArgs = explode(':', $filter);
        $fieldName = array_shift($fieldArgs);

        // Inspect type of second argument to determine context
        $secondArg = array_shift($fieldArgs);
        $modifiers = $fieldArgs;
        if (!$secondArg) {
            // Use default filter if none specified. E.g. `->filter(['Name' => $myname])`
            $filterServiceName = 'DataListFilter.default';
        } else {
            // The presence of a second argument is by default ambiguous; We need to query
            // Whether this is a valid modifier on the default filter, or a filter itself.
            /** @var SearchFilter $defaultFilterInstance */
            $defaultFilterInstance = Injector::inst()->get('DataListFilter.default');
            if (in_array(strtolower($secondArg), $defaultFilterInstance->getSupportedModifiers())) {
                // Treat second (and any subsequent) argument as modifiers, using default filter
                $filterServiceName = 'DataListFilter.default';
                array_unshift($modifiers, $secondArg);
            } else {
                // Second argument isn't a valid modifier, so assume is filter identifier
                $filterServiceName = "DataListFilter.{$secondArg}";
            }
        }

        // Build instance
        return Injector::inst()->create($filterServiceName, $fieldName, $value, $modifiers);
    }
271125
private function filter($variable, $filter, $options = null)
    {

        //gets a specific external variable and filter it
        //determine what variable name is being used here;
        $this->sanitized = true;

        //@TODO To trust or not to trust?
        return filter_var($variable, $filter, $options);
    }
1235917
public function filter($var, $filters, $type = null)
    {
        if (!is_array($filters)) {
            $filters = $filters ? explode('|', $filters) : [];
        }

        $value = &$this->data[$var] ?? null;
        if ($value === null) {
            return null;
        }
        foreach ($filters as $key => $filter) {
            $params = explode(':', $filter);
            $filter = is_string($key) ? $key : array_shift($params);
            $filter = $this->filters[$filter] ?? function (&$data) use ($filter, $params) {
                $data = $filter($data, ...$params);
            };

            $errors = $filter($value, ...$params);
            if ($errors) {
                $this->errors[$var] = $errors;
                break;
            }
            if ($value === null) {
                return null;
            }
        }

        if ($type) {
            settype($value, $type);
        }

        return $value;
    }
372378
public function cookie($name = '', $default = null, $filter = '')
    {
        if (empty($this->cookie)) {
            $this->cookie = $_COOKIE;
        }
        if (is_array($name)) {
            return $this->cookie = array_merge($this->cookie, $name);
        }
        return $this->input($this->cookie, $name, $default, $filter);
    }
593178
public function getField(string $name, $default = null, bool $filter = true)
    {
        $value = $this->hasField($name) ? $this->fields[$name] : $default;

        if ($value instanceof AccessorInterface || (is_null($value) && $this->isNullable($name))) {
            //Direct access to value when value is accessor or null and declared as nullable
            return $value;
        }

        //Checking if field have accessor (decorator)
        $accessor = $this->getMutator($name, self::MUTATOR_ACCESSOR);

        if (!empty($accessor)) {
            return $this->fields[$name] = $this->createAccessor($accessor, $name, $value);
        }

        //Getting value though getter
        return $this->getMutated($name, $filter, $value);
    }
602548
public function cookie( $name = '', $default = null, $filter = '' )
	{
		if( empty( $this->cookie ) ){
			$this->cookie = Cookie::get();
		}
		if( is_array( $name ) ){
			return $this->cookie = array_merge( $this->cookie, $name );
		} elseif( !empty( $name ) ){
			$data = Cookie::has( $name ) ? Cookie::get( $name ) : $default;
		} else{
			$data = $this->cookie;
		}

		// 解析过滤器
		$filter = $this->getFilter( $filter, $default );

		if( is_array( $data ) ){
			array_walk_recursive( $data, [$this, 'filterValue'], $filter );
			reset( $data );
		} else{
			$this->filterValue( $data, $name, $filter );
		}
		return $data;
	}
586587
public function server($name = "", $default = null, $filter = null) {
        if (empty($this->server)) {
            $this->server = $this->swooleRequest->server;
        }
        if (!$name) {
            $value = $this->server;
        } else {
            $value = $this->server[ $name ];
        }
        return $this->value($value, $default, $filter);
    }
497986
public static function Value(&$val, $filter = null, $default = false)
  {
    $ok = true;
    if (is_callable($filter)) {
      $ok = call_user_func_array($filter, array(&$val));
    } elseif (is_array($filter)) {
      $ok = in_array($val, $filter);
    } elseif (!empty($filter)) {
      $ok = preg_match($filter, $val);
    }

    return $ok ? $val : $default;
  }
939622
public static function getVar($name,$default,$vartype=''){
		switch($vartype){
			case 'post':
				return self::getVarPost($name,$default);
			case 'get':
				return self::getVarGet($name,$default);
			case 'cookie':
				return self::getVarCookie($name,$default);
				}
		$v=self::getVarGet($name,NULL);
		if($v===NULL){
			$v=self::getVarPost($name,NULL);
			}
		if(($v===NULL)||($v===false)){
			return $default;
			}
		return $v;
		}
278116
public static function get($key, $default = null)
    {
        return isset(self::$variables[$key]) ? self::$variables[$key] : $default;
    }
50338
public function getState($var, $default = null)
	{
		$key = str_replace('\\', '.', $this->getModelNamespace()) . '.' . $this->getModelName() . ".{$var}";
		return \User::getState($key, $default);
	}
567914
static function GetData($name, $filter = FILTER_DEFAULT, $options = null)
    {
        return filter_input(INPUT_GET, $name, $filter, $options);
    }
155066
public function qvar($name, $default = NULL) {
    $query = (array) $this->request->getQuery();
    return array_key_exists($name, $query) ? $query[$name] : $default;
  }
1131799
private function getDefaultValue($key, $default = null)
    {
        $value = null === $default && \array_key_exists($key, $this->defaults)
            ? $this->defaults[$key]
            : $default;

        return $this->getByManager($key, $value, $default);
    }
199202
public static function get($name, $default = '') {
        $_GET = self::paramFilter($_GET);
        if (isset($_GET[$name])) {
            if (empty($_GET[$name])) {
                return $default;
            }
            return $_GET[$name];
        }
        return false;
    }