Skip to content

classes_base_args.class

Daniel Spors edited this page Dec 19, 2023 · 2 revisions

Classes in file base/args.class.php

class Args

Generic Argument wrapper class Provides functionality to savely get values from the $_GET, $_POST,... superglobals. Supports:

  • GET
  • POST
  • COOKIE
  • SERVER
  • ENV
  • SESSION

Use the shortcut methods if you want to query a specific (of the) variables (above). Args::get(...), Args::post(...),... You may use the Args::request method to query a mix of the superglobals defined by the Args::setOrder() method (default is GPC -> Cookie overrides Post overrides Get).

See method commets for details.

clearBuffer

Clears all internal buffers. In some cases it may be usefule to let Args parse again instead of relying on previously calculated values.

Definition: public static function clearBuffer()

Returns: void

cookie

SHORTCUT To access COOKIE values.

env

SHORTCUT To access ENV values.

get

SHORTCUT To access GET values.

post

SHORTCUT To access POST values.

request

SHORTCUT To access REQUEST values. Uses the default (or set via setOrder) superglobal query order.

sanitize

Performs value sanitation. Sanitizes a value with a given filter. Valid values for $filter are all PHP defined FILTER_SANITIZE_* constants or a string value. If $filter is one of those constants, $filter_options apply as in PHP documentation. See http://www.php.net/manual/en/filter.filters.sanitize.php for details on that. If $filter is a string see code below for details. Mentionable here:

  • 'array': Will treat value as an array. You may provide filter_options to be a string (like 'int') defining a type for all array elements or to be an array that should contain the same keys (count and name) as the value and each filter_option[key] value defines another type. Sample: $filter='array', $filter_options=array('int','bool','string')
  • 'object': Will treat the value as object and simply return it if it is one. May also be a string defining the storage_id of an object in object store. In that case restore_object($value) will be returned.

Another note: sanitize will fill the log with messages severity WARN if something unexpected happen. This is especially the case when default values are returned for invalid inputs. So have an eye on the logs!

Definition: public static function sanitize($value, $filter, $filter_options=null)

Returns: mixed The sanitized value

Parameters:

  • mixed $value The value to be sanitized

  • int|string $filter Type of filter

  • mixed $filter_options Optional options for the filter

sanitized

Returns a names variable Queries the Superglobals for a variable named $name and optionally filters it for a specific type. Superglobals to be included in the query and their order may be given optionally.

For details on the possible values for $filter see Args::sanitize below.

Definition: public static function sanitized($name=false, $default=null, $order=null, $filter=null, $filter_options=null)

Returns: mixed Sanitized value or a list of requested array's keys

Parameters:

  • string $name Name of the variable, if false a list of keys in the requested array is returned

  • mixed $default Default value, null if none

  • string $order Specific Superglobals order. NULL if default shall be used. See setOrder for details

  • int|string $filter Specifies a filter to apply on the value. See description above

  • mixed $filter_options Optional options for the $filter argument

server

SHORTCUT To access SERVER values.

session

SHORTCUT To access SESSION values.

setCultureInfo

Sets a CultureInfo object. This is optional but will allow you to parse inputs correctly in a given Cultures format. So if the user enters a number like this 1,042.23 (one thousant fourty two point twenty three) this is US formatting and can pe parsed successfully to 1042.23 if you provide an en-US culture. If not it will result in an invalid float value.

Definition: public static function setCultureInfo($cultureInfo)

Returns: void

Parameters:

  • CultureInfo $cultureInfo Ci to set

setIgnoreCase

Sets ignore case flag. If true, Args class will ignore the case of the argument names. If false will respect case.

Definition: public static function setIgnoreCase($ignore)

Returns: void

Parameters:

  • bool $ignore true|false

setOrder

Sets the default superglobal query range. Supported values and their meanings: G - GET P - POST C - COOKIE S - SERVER E - ENV O - SESSION (use O to have the S for PHP compatibility as it means SERVER there)

Note: GPC is default. This will use Cookie before Post before Get, so order is reversed!

Definition: public static function setOrder($order)

Returns: void

Parameters:

  • string $order Order string (sample: GPCSEO)

strip_tags

Strips given tags from request data.

Definition: public static function strip_tags()

Returns: void

Clone this wiki locally