CRequest
in package
implements
IHttpStatus
It handles all input requests and provides facilities for their use.
Table of Contents
Interfaces
- IHttpStatus
- Interface defining HTTP status code constants.
Properties
- $action : string
- $attributes : array<int, string>
- $cache : ICache|null
- $charset : string
- $connection_manager : IConnectionManager|null
- $data_for_edit : bool
- $filters : array<string|int, array<string|int, mixed>>
- $format : string
- $full_info : bool
- $http_authorization : string
- $http_method : string
- $is_api_request : bool
- $items_per_page : int
- $logger : ILogger|null
- $module_info : array<string|int, mixed>
- $module_name : string
- $order_by : array<string|int, mixed>
- $origin_path_request : string
- $page : int
- $params : array<string|int, mixed>
- $path_request : string
- $permission : string
- $redirect_url : string
- $routes : CRoutes
- $section_name : string
- $table_name : string
- $upload_path : string
- $view : string
- $with_header_and_footer : bool
Methods
- __construct() : mixed
- Constructor for CRequest.
- CreateInstance() : CRequest
- Factory method to create a new CRequest instance.
- GetAction() : string
- Get the HTML Frame required (only for HTML response)
- GetAttribute() : string|array<string|int, mixed>|null
- Get a single attribute
- GetAttributes() : array<string|int, mixed>
- Get the attributes
- GetCharset() : string
- Get the Charset
- GetConnectionManager() : IConnectionManager|null
- GetConnectionManager( )
- GetCurrentPage() : int
- Get the current page requested
- GetDataForEdit() : string
- Get full info (without a resolved indexes if is true)
- GetFilter() : array<string|int, string>|null
- Get a single filter
- GetFilters() : array<string|int, array<string|int, mixed>>
- Get the filters
- GetFormat() : string
- Get the format
- GetFullInfo() : string
- Get full info (get a resolved indexes on a GET)
- GetHttpAuthorization() : string
- Get the token
- GetHttpMethod() : string
- Get the method (POST, GET, PATCH, DELETE, ...)
- GetItemsPerPage() : int
- Get the maximum of elements per page
- GetModuleInfo() : array<string|int, mixed>
- Get the module name
- GetModuleName() : string
- Get the module name
- GetOrderBy() : array<string|int, mixed>
- Get the order of output data
- GetOriginPathRequest() : string
- Get the type of original request
- GetPalette() : string
- Get the requested component palette name.
- GetParameter() : string|array<string|int, mixed>|null
- Get a single parameter
- GetParameters() : array<string|int, mixed>
- Get the parameters
- GetPathRequest() : string
- Get the type of final Request
- GetPermission() : string
- Get the current action
- GetRedirectUrl() : string
- Get the Redirect uri at the end of all
- GetRoutes() : the
- Return the CRoutes object
- GetSectionName() : string
- Get the section name (if exists else is a empty string) The section is the first name with starts any urls (/s/section/module/....)
- GetTableName() : string
- Get the module name
- GetUploadFolder() : string
- Return the current Upload folder (private or public)
- GetView() : string
- Get the view variation (normally is not necessary because is included in GetAction()) but it can use i.e. for download a document in a different format
- GetWithHeaderAndFooter() : bool
- Returns true if the header and footer must be present in the view
- GoRedirect() : void
- If there has been a redirect request via redirect it executes it when called
- InputFile() : void
- Import one or more files to upload
- IsApiRequest() : bool
- Get true if is an API Request
- RemoveUploadedFile() : void
- Remove newly uploaded files in case of any other errors
- SetAction() : void
- Set the HTML Frame required (only for HTML response) The central HTML frame can be changed here
- SetRedirectUrl() : void
- Set the Redirect uri at the end of all
- SetSectionName() : void
- Set the section_name (if exists else is a empty string)
- SetUploadFolder() : void
- Set the upload folder to private (private-files) or public area (public-files)
- SetView() : void
- Set the view variation
- SetWithHeaderAndFooter() : bool
- Set if the header and footer must be present in the view
- SetFilters() : void
- Determine which filters were requested
- SetFormat() : void
- Set format type of output
- SetHttpAuthorization() : void
- Look for the token sent in the request or from the session if one exists
- SetHttpMethod() : void
- Determine which HTTP method was requested
- SetParameters() : void
- Determine which parameters were requested
- SetModuleName() : void
- Set the module name and if not declared set the ITEM_ID value when the id of each table contains the name of table like: id_[table], [table]_id, [table]ID
Properties
$action
protected
string
$action
Type of form (new or modify) only for HTML response
$attributes
protected
array<int, string>
$attributes
= []
Other input parameters that are not filters
$cache
protected
ICache|null
$cache
= null
The cache instance
$charset
protected
string
$charset
= DEFAULT_CHARSET
Character set for output
$connection_manager
protected
IConnectionManager|null
$connection_manager
The connection manager instance
$data_for_edit
protected
bool
$data_for_edit
= false
True if data is requested for edit form
$filters
protected
array<string|int, array<string|int, mixed>>
$filters
= []
Filters as: id, name, etc. i.e $filters[ITEM_ID]['=',12]
$format
protected
string
$format
= DEFAULT_FORMAT_OUTPUT
Output format (json, xml, html, text)
$full_info
protected
bool
$full_info
= false
Table with names instead of indexes and other info for a GET
$http_authorization
protected
string
$http_authorization
= ''
The HTTP Authorization header value
$http_method
protected
string
$http_method
HTTP method (GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS)
$is_api_request
protected
bool
$is_api_request
= false
True if this is an API request
$items_per_page
protected
int
$items_per_page
= DEFAULT_ITEMS_PER_REQUEST
Number of items per page
$logger
protected
ILogger|null
$logger
= null
The logger instance
$module_info
protected
array<string|int, mixed>
$module_info
Array of data information for current module
$module_name
protected
string
$module_name
Name of the module to display
$order_by
protected
array<string|int, mixed>
$order_by
= []
Order table by item and type order (ASC or DESC)
$origin_path_request
protected
string
$origin_path_request
The current original URL (not routed URL)
$page
protected
int
$page
= 1
The current page number
$params
protected
array<string|int, mixed>
$params
= []
Parameters for input/update operations (from POST/PUT body)
$path_request
protected
string
$path_request
= ''
The request module name and filters
$permission
protected
string
$permission
Permission: insert, modify, delete, read
$redirect_url
protected
string
$redirect_url
= ''
URL to redirect after operation
$routes
protected
CRoutes
$routes
Object for changing the paths of QUERY_STRING
$section_name
protected
string
$section_name
= ''
Name of the section (if in the path è /a/SECTION_NAME)
$table_name
protected
string
$table_name
= ""
Name of the table on database for current module
$upload_path
protected
string
$upload_path
= DEFAULT_UPLOAD_FILE_PATH
The path where uploaded files are stored
$view
protected
string
$view
= ''
Alternative view for different variations of the same request
$with_header_and_footer
protected
bool
$with_header_and_footer
= true
True if the header and footer must be present in the view
Methods
__construct()
Constructor for CRequest.
public
__construct(IConnectionManager|null $connection_manager[, ICache|null $cache = null ][, ILogger|null $logger = null ]) : mixed
Initializes the request handler with dependencies and parses the incoming request.
Parameters
- $connection_manager : IConnectionManager|null
-
The connection manager instance.
- $cache : ICache|null = null
-
Optional cache instance.
- $logger : ILogger|null = null
-
Optional logger instance.
CreateInstance()
Factory method to create a new CRequest instance.
public
static CreateInstance(IConnectionManager $connection_manager[, ICache|null $cache = null ][, ILogger|null $logger = null ]) : CRequest
Parameters
- $connection_manager : IConnectionManager
-
The connection manager instance.
- $cache : ICache|null = null
-
Optional cache instance.
- $logger : ILogger|null = null
-
Optional logger instance.
Return values
CRequest —A new CRequest instance.
GetAction()
Get the HTML Frame required (only for HTML response)
public
GetAction() : string
Return values
string —the current html frame name (Read, InsertForm, ModifyForm,...)
GetAttribute()
Get a single attribute
public
GetAttribute(string $name) : string|array<string|int, mixed>|null
Parameters
- $name : string
-
the attribute name
Return values
string|array<string|int, mixed>|null —the attribute value
GetAttributes()
Get the attributes
public
GetAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —the list of the attributes (all requests excluding filters)
GetCharset()
Get the Charset
public
GetCharset() : string
Return values
string —the current charset
GetConnectionManager()
GetConnectionManager( )
public
GetConnectionManager() : IConnectionManager|null
Return values
IConnectionManager|null —The Connection Manager
GetCurrentPage()
Get the current page requested
public
GetCurrentPage() : int
Return values
int —the number of the current page
GetDataForEdit()
Get full info (without a resolved indexes if is true)
public
GetDataForEdit() : string
Return values
string —the current format
GetFilter()
Get a single filter
public
GetFilter(string $name) : array<string|int, string>|null
Parameters
- $name : string
-
the name of the filter
Return values
array<string|int, string>|null —the filter
GetFilters()
Get the filters
public
GetFilters() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>> —the list of all filters
GetFormat()
Get the format
public
GetFormat() : string
Return values
string —the current format
GetFullInfo()
Get full info (get a resolved indexes on a GET)
public
GetFullInfo() : string
Return values
string —the current format
GetHttpAuthorization()
Get the token
public
GetHttpAuthorization() : string
Return values
string —the token
GetHttpMethod()
Get the method (POST, GET, PATCH, DELETE, ...)
public
GetHttpMethod() : string
Return values
string —the current method request
GetItemsPerPage()
Get the maximum of elements per page
public
GetItemsPerPage() : int
Return values
int —The maximum of elements per page
GetModuleInfo()
Get the module name
public
GetModuleInfo() : array<string|int, mixed>
Return values
array<string|int, mixed> —containing information about the current module
GetModuleName()
Get the module name
public
GetModuleName() : string
Return values
string —the current module name//
GetOrderBy()
Get the order of output data
public
GetOrderBy() : array<string|int, mixed>
Return values
array<string|int, mixed> —the list of the columns order
GetOriginPathRequest()
Get the type of original request
public
GetOriginPathRequest() : string
Return values
string —the original request
GetPalette()
Get the requested component palette name.
public
GetPalette() : string
Checks for X-Component-Palette HTTP header, falls back to DEFAULT_COMPONENT_PALETTE.
Return values
string —The palette name (e.g., 'blue', 'gold', 'green').
GetParameter()
Get a single parameter
public
GetParameter(string $name) : string|array<string|int, mixed>|null
Parameters
- $name : string
-
the parameter name
Return values
string|array<string|int, mixed>|null —the parameter value
GetParameters()
Get the parameters
public
GetParameters() : array<string|int, mixed>
Return values
array<string|int, mixed> —the list of the parameters
GetPathRequest()
Get the type of final Request
public
GetPathRequest() : string
Return values
string —the routed request or original if not exists
GetPermission()
Get the current action
public
GetPermission() : string
Return values
string —the current action
GetRedirectUrl()
Get the Redirect uri at the end of all
public
GetRedirectUrl() : string
Return values
stringGetRoutes()
Return the CRoutes object
public
GetRoutes() : the
Return values
the —CRoutes object
GetSectionName()
Get the section name (if exists else is a empty string) The section is the first name with starts any urls (/s/section/module/....)
public
GetSectionName() : string
Return values
string —the current section name
GetTableName()
Get the module name
public
GetTableName() : string
Return values
string —the current module name//
GetUploadFolder()
Return the current Upload folder (private or public)
public
GetUploadFolder() : string
Return values
string —the token
GetView()
Get the view variation (normally is not necessary because is included in GetAction()) but it can use i.e. for download a document in a different format
public
GetView() : string
Return values
stringGetWithHeaderAndFooter()
Returns true if the header and footer must be present in the view
public
GetWithHeaderAndFooter() : bool
Return values
bool —truetrue if the header and footer must be present in the view, false otherwise
GoRedirect()
If there has been a redirect request via redirect it executes it when called
public
GoRedirect([bool $force = false ]) : void
Parameters
- $force : bool = false
-
force redirect when the redirect_url is not empy if $_SERVER['SCRIPT_URI'] exists
InputFile()
Import one or more files to upload
public
InputFile() : void
Tags
IsApiRequest()
Get true if is an API Request
public
IsApiRequest() : bool
Return values
bool —true if is an API Request
RemoveUploadedFile()
Remove newly uploaded files in case of any other errors
public
RemoveUploadedFile() : void
SetAction()
Set the HTML Frame required (only for HTML response) The central HTML frame can be changed here
public
SetAction(string $action) : void
Parameters
- $action : string
-
the current html frame name (Read, InsertForm, ModifyForm,...)
SetRedirectUrl()
Set the Redirect uri at the end of all
public
SetRedirectUrl([string|null $redirect_url = '' ]) : void
Parameters
- $redirect_url : string|null = ''
-
the url to redirect
SetSectionName()
Set the section_name (if exists else is a empty string)
public
SetSectionName(string $section_name) : void
Parameters
- $section_name : string
-
name to set (section_name)
SetUploadFolder()
Set the upload folder to private (private-files) or public area (public-files)
public
SetUploadFolder([bool $is_public = false ]) : void
Parameters
- $is_public : bool = false
-
true for public files or false for private files
SetView()
Set the view variation
public
SetView([string $view = '' ]) : void
Parameters
- $view : string = ''
-
the name of specific view (usually set by 'vw' o 'view' param on url)
SetWithHeaderAndFooter()
Set if the header and footer must be present in the view
public
SetWithHeaderAndFooter(bool $with_header_and_footer) : bool
Parameters
- $with_header_and_footer : bool
Return values
bool —true if the header and footer must be present in the view, false otherwise
SetFilters()
Determine which filters were requested
protected
SetFilters() : void
Tags
SetFormat()
Set format type of output
protected
SetFormat([string|null $format = null ]) : void
Parameters
- $format : string|null = null
-
the format type name (json, xml, html OR text) default is declared in config.php as DEFAULT_FORMAT_OUTPUT NOTE: If it is null it gets the value from HTTP_ACCEPT if it is valid otherwise it is the default value
SetHttpAuthorization()
Look for the token sent in the request or from the session if one exists
protected
SetHttpAuthorization() : void
SetHttpMethod()
Determine which HTTP method was requested
protected
SetHttpMethod() : void
SetParameters()
Determine which parameters were requested
protected
SetParameters() : void
SetModuleName()
Set the module name and if not declared set the ITEM_ID value when the id of each table contains the name of table like: id_[table], [table]_id, [table]ID
private
SetModuleName(string $module_name) : void
Parameters
- $module_name : string
-
the name of current module