WebFioriAPI ReferenceLearnDownloadContributeLearn{{result.parent_page}} > {{result.title}}{{result.title}}Classes{{result.class_name}}{{result.summary}}Methods{{result.name}}{{result.summary}}

namespace \webfiori\http

class RequestParameter

Class Methods Summary

public function __construct(string$name, string$type, boolean$isOptional)Creates new instance of the class.public function __toString()Returns a string that represents the object.public function applyBasicFilter()Checks if we need to apply basic filter or not before applying custom filter callback.public static function createParam(array$options)Creates an object of the class given an associative array of options.public function getCustomFilterFunction()Returns the function that is used as a custom filter for the parameter.public function getDefault()Returns the default value to use in case the parameter is not provided.public function getDescription()Returns the description of the parameter.public function getMaxVal()Returns the maximum numeric value the parameter can accept.public function getMinVal()Returns the minimum numeric value the parameter can accept.public function getName()Returns the name of the parameter.public function getType()Returns the type of the parameter.public function isEmptyStringAllowed()Checks if empty strings are allowed as values for the parameter.public function isOptional()Returns a boolean value that can be used to tell if the parameter is optional or not.public function setCustomFilterFunction(callback$function, boolean$applyBasicFilter)Sets a callback method to work as a filter for request parameter.public function setDefault(mixed$val)Sets a default value for the parameter to use if the parameter is not provided Or when the filter fails.public function setDescription(string$desc)Sets the description of the parameter.public function setIsEmptyStringAllowed(boolean$bool)Allow or disallow empty strings as values for the parameter.public function setIsOptional(boolean$bool)Sets the value of the property 'isOptional'.public function setMaxVal(int$val)Sets the maximum value.public function setMinVal(int$val)Sets the minimum value that the parameter can accept.public function setName(string$name)Sets the name of the parameter.public function setType(string$type)Sets the type of the parameter.public function toJSON()Returns a Json object that represents the request parameter.

Class Methods Details

public function __construct(string$name, string$type, boolean$isOptional)Creates new instance of the class.

Parameters:

  • string $name The name of the parameter as it appears in the request body. It must be a valid name. If the given name is invalid, the parameter name will be set to 'a-parameter'. Valid name must comply with the following rules:
    • It can contain the letters [A-Z] and [a-z].
    • It can contain the numbers [0-9].
    • It can have the character '-' and the character '_'.
  • string $type The type of the data that will be in the parameter stored by the parameter. Supported types are:
    • string
    • integer
    • email
    • float
    • url
    • boolean
    • array
    • json-obj
    If invalid type is given or no type is provided, 'string' will be used by default.
  • boolean $isOptional Set to true if the parameter is optional. Default is false.
public function __toString()Returns a string that represents the object. Returns: stringA string in the following format:

RequestParameter[
    Name =
    Type =
    Description =
    Is Optional =
    Default =
    Minimum Value =
    Maximum Value =
]

If any of the values is null, the value will be shown as 'null'.
public function applyBasicFilter()Checks if we need to apply basic filter or not before applying custom filter callback. Returns: booleanThe method will return true if the basic filter will be applied before applying custom filter. If no custom filter is set, the method will return true by default.public static function createParam(array$options)Creates an object of the class given an associative array of options.

Parameters:

  • array $options An associative array of options. The array can have the following indices:
    • name: The name of the parameter. If invalid name is provided, the value 'a-parameter' is used. If it is not provided, no parameter will be created.
    • type: The datatype of the parameter. If not provided, 'string' is used.
    • optional: A boolean. If set to true, it means the parameter is optional. If not provided, 'false' is used.
    • min: Minimum value of the parameter. Applicable only for numeric types.
    • max: Maximum value of the parameter. Applicable only for numeric types.
    • allow-empty: A boolean. If the type of the parameter is string or string-like type and this is set to true, then empty strings will be allowed. If not provided, 'false' is used.
    • custom-filter: A PHP function that can be used to filter the parameter even further
    • default: An optional default value to use if the parameter is not provided and is optional.
    • description: The description of the attribute.
Returns: null|RequestParameterIf the given request parameter is created, the method will return an object of type 'RequestParameter'. If it was not created for any reason, the method will return null.
public function getCustomFilterFunction()Returns the function that is used as a custom filter for the parameter. Returns: callback|nullThe function that is used as a custom filter for the parameter. If not set, the method will return null.public function getDefault()Returns the default value to use in case the parameter is not provided. Returns: mixed|nullThe default value to use in case the parameter is not provided. If no default value is provided, the method will return null.public function getDescription()Returns the description of the parameter. Returns: string|nullThe description of the parameter. If the description is not set, the method will return null.public function getMaxVal()Returns the maximum numeric value the parameter can accept. This method apply only to integer type.Returns: int|nullThe maximum numeric value the parameter can accept. If the request parameter type is not numeric, the method will return null.public function getMinVal()Returns the minimum numeric value the parameter can accept. This method apply only to and integer type.Returns: int|nullThe minimum numeric value the parameter can accept. If the request parameter type is not numeric, the method will return null.public function getName()Returns the name of the parameter. Returns: stringThe name of the parameter.public function getType()Returns the type of the parameter. Returns: stringThe type of the parameter (Such as 'string', 'email', 'integer').public function isEmptyStringAllowed()Checks if empty strings are allowed as values for the parameter. If the property value is not updated using the method RequestParameter::setIsEmptyStringAllowed(), The method will return default value which is false.Returns: booleantrue if empty strings are allowed as values for the parameter. false if not.public function isOptional()Returns a boolean value that can be used to tell if the parameter is optional or not. Returns: booleantrue if the parameter is optional and false if not.public function setCustomFilterFunction(callback$function, boolean$applyBasicFilter)
Sets a callback method to work as a filter for request parameter. The callback method will have 3 parameters passed to it:
  • Original value without filtering.
  • The value with basic filtering rules applied to it.
  • An object of type RequestParameter.

If the parameter $applyBasicFilter is set to false, the second parameter will have the value 'NOT_APLICABLE'.

The object of type RequestParameter will contain original information for the filter.

The method must be implemented in a way that makes it return false or null if the parameter has invalid value. If the parameter is filtered and was validated, the method must return the valid and filtered value.

Parameters:

  • callback $function A callback function.
  • boolean $applyBasicFilter If set to true, the basic filter will be applied to the parameter. Default is true.
Returns: booleanIf the callback is set, the method will return true. If not set, the method will return false.
public function setDefault(mixed$val)Sets a default value for the parameter to use if the parameter is not provided Or when the filter fails. This method can be used to include a default value for the parameter if it is optional or in case the filter was not able to filter given value.

Parameters:

  • mixed $val default value for the parameter to use.
Returns: booleanIf the default value is set, the method will return true. If it is not set, the method will return false.
public function setDescription(string$desc)Sets the description of the parameter. This method is used to document the API. Used to help front-end developers.

Parameters:

  • string $desc Parameter description.
public function setIsEmptyStringAllowed(boolean$bool)Allow or disallow empty strings as values for the parameter. The value of the attribute will be updated only if the type of the parameter is set to 'string'.

Parameters:

  • boolean $bool true to allow empty strings and false to disallow empty strings.
Returns: booleanThe method will return true if the property is updated. If datatype of the request parameter is not string, The method will not update the property value and will return false.
public function setIsOptional(boolean$bool)Sets the value of the property 'isOptional'.

Parameters:

  • boolean $bool True to make the parameter optional. False to make it mandatory.
public function setMaxVal(int$val)
Sets the maximum value. The value will be updated only if:
  • The request parameter type is numeric ('integer' or 'float').
  • The given value is greater than RequestParameter::getMinVal()

Parameters:

  • int $val The maximum value to set.
Returns: booleanThe method will return true once the maximum value is updated. false if not.
public function setMinVal(int$val)
Sets the minimum value that the parameter can accept. The value will be updated only if:
  • The request parameter type is numeric ('integer' or 'float').
  • The given value is less than RequestParameter::getMaxVal()

Parameters:

  • int $val The minimum value to set.
Returns: booleanThe method will return true once the minimum value is updated. false if not.
public function setName(string$name)
Sets the name of the parameter. A valid parameter name must follow the following rules:
  • It can contain the letters [A-Z] and [a-z].
  • It can contain the numbers [0-9].
  • It can have the character '-' and the character '_'.

Parameters:

  • string $name The name of the parameter.
Returns: booleanIf the given name is valid, the method will return true once the name is set. false is returned if the given name is invalid.
public function setType(string$type)Sets the type of the parameter.

Parameters:

  • string $type The type of the parameter. It must be a value form the contats which exist in the class 'ParamTypes'.
Returns: booleantrue is returned if the type is updated. false if not.
public function toJSON()
Returns a Json object that represents the request parameter. This method is used to help front-end developers in showing the documentation of the request parameter. The format of JSON string will be as follows:

{
  "name":"a-param",
  "type":"string",
  "description":null,
  "is-optional":true,
  "default-value":null,
  "min-val":null,
  "max-val":null
}

Returns: JsonAn object of type Json.
mdi-menuAll Classesmdi-chevron-leftAnchorBrCodeSnippetHTMLDocHTMLListHTMLNodeHTMLTableHeadNodeInputJsCodeLabelListItemOrderedListParagraphRadioGroupTableCellTableRowUnorderedListInvalidNodeNameExceptionTemplateNotFoundExceptionCaseConverterJsonJsonConverterJsonIJsonTypesPropertyAPIFilterAbstractWebServiceManagerInfoServiceParamTypesRequestRequestParameterResponseUriWebServicesManagerAccessAutoLoaderConfigConfigControllerDBEAbstractWebServiceExtendedWebServicesManagerFileLoggerPrivilegePrivilegesGroupThemeThemeLoaderUploadFileUploaderUserUtilWebFioriAppLanguageErrorBoxHTTPCodeViewMessageBoxServerErrViewStarterPageWebPageDatabaseSessionStorageDefaultSessionStorageMSSQLSessionDataTableMSSQLSessionsTableMySQLSessionDataTableMySQLSessionsTableSessionSessionOperationsSessionStorageSessionsManagerRouterRouterUriAbstractMiddlewareMiddlewareManagerEmailMessageSMTPAccountSMTPServerClassLoaderExceptionFileExceptionInitializationExceptionInvalidCRONExprExceptionMissingLangExceptionNoSuchThemeExceptionRoutingExceptionSMTPExceptionSessionExceptionUIExceptionAbstractJobCronCronEmailCronJobJobArgumentCronLoginViewCronTasksViewCronViewCronLoginServiceCronLogoutServiceCronServicesManagerForceCronExecutionServiceGetJobsServiceCLICLICommandInputStreamOutputStreamStdInStdOutClassWriterLangClassWriterQueryClassWriterServiceHolderThemeClassWriterWebServiceWriterCreateCLIClassHelperCreateCronJobCreateMiddlewareCreateTableCreateTableObjCreateThemeHelperCreateWebServiceAddCommandCreateCommandCronCommandHelpCommandListCronCommandListRoutesCommandListThemesCommandRunSQLQueryCommandSettingsCommandTestRouteCommandUpdateSettingsCommandUpdateTableCommandVersionCommandAbstractQueryColumnColumnFactoryConditionConnectionConnectionInfoDatabaseDatabaseExceptionDateTimeValidatorEntityMapperExpressionForeignKeyJoinTableResultSetSelectExpressionTableWhereExpressionMySQLColumnMySQLConnectionMySQLQueryMySQLTableMSSQLColumnMSSQLConnectionMSSQLQueryMSSQLTableAbstractCollectionComparableLinkedListNodeQueueStack
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024