Utils
in package
This is the Utils class.
This class is the responsible to encapsulate the various useful generic methods.
Tags
Table of Contents
SORT_ASC | = 'asc' | |
---|---|---|
SORT_DESC | = 'desc' | |
TYPE_ARRAY | = 'array' | |
TYPE_BOOLEAN | = 'boolean' | |
TYPE_CALLABLE | = 'callable' | |
TYPE_FLOAT | = 'float' | |
TYPE_INT | = 'int' | |
TYPE_NUMERIC | = 'numeric' | |
TYPE_OBJECT | = 'object' | |
TYPE_OBJECT_CLASS | = 'object class' | |
TYPE_RESOURCE | = 'resource' | |
TYPE_STRING | = 'string' | |
addParamsToRequest() | This function returns an string with the params of the request concatenating to it the 'newParams' parameters given by parameter as part of the request parameters. | : array<string|int, mixed> |
addTimerDebugFlag() | This method adds a debug timer flag. | : mixed |
addTimerDebugTag() | This method adds a debug timer tag. | : mixed |
calculateLocale() | This method returns the locale string if it is found (based on the given country and language) in the list of locales supported by the bundle (see ResourceBundle::getLocales()), otherwise it returns $country. | : string |
cleanHtmlTags() | This method returns the string given without html tags. | : string |
deleteParamsFromRequest() | This function returns an string with the params of the request eliminating from it the parameters given by parameter. | : array<string|int, mixed> |
getCamelFromSnake() | This method returns a string in camel format from a string in snake format . | : array<string|int, mixed> |
getCountryNameByCountryCode() | : string | |
getDevice() | This method returns the user device. | : string |
getDirMap() | This method returns a mapping of the given directory path. | : array<string|int, mixed> |
getErrorLabelValue() | : string | |
getJSDatePatternByLocale() | This method returns the pattern for the given locale. | : string |
getPdfContent() | This method returns the pdf content from a PDFDocument. | : string |
getQueryStringParameters() | This method returns the query string parameters. | : array<string|int, mixed> |
getSnakeFromCamel() | This method returns a string in snake format from a string in camel format . | : array<string|int, mixed> |
getUserName() | This method returns the user name from the given User using the configured user key criteria. | : string |
isSalesAgent() | This method returns true if the session user is sales agent, false otherwise. | : bool |
isSessionLoggedIn() | This method returns true if the session user is logged, false otherwise. | : bool |
isSimulatedUser() | This method returns true if the session user is sales agent, false otherwise. | : bool |
minifyHtml() | This method minifies the given html text and returns it. | : string |
outputJsonHtmlString() | This method returns the given value in json format with html compatibility. | : string |
outputTimerDebug() | This method outputs the debug timer. | : mixed |
paserArrayToPathParameters() | This method returns a Twig function named 'paserArrayToPathParameters'. | : string |
removeAccents() | : mixed | |
setValidateType() | This method checks that the given value corresponds to the given data type. | : mixed |
sortArrayObjects() | This method sorts an array of abjects by the property sended | : array<string|int, mixed> |
stopTimerDebug() | This method stops the debug timer. | : mixed |
Constants
SORT_ASC
public
mixed
SORT_ASC
= 'asc'
SORT_DESC
public
mixed
SORT_DESC
= 'desc'
TYPE_ARRAY
public
mixed
TYPE_ARRAY
= 'array'
TYPE_BOOLEAN
public
mixed
TYPE_BOOLEAN
= 'boolean'
TYPE_CALLABLE
public
mixed
TYPE_CALLABLE
= 'callable'
TYPE_FLOAT
public
mixed
TYPE_FLOAT
= 'float'
TYPE_INT
public
mixed
TYPE_INT
= 'int'
TYPE_NUMERIC
public
mixed
TYPE_NUMERIC
= 'numeric'
TYPE_OBJECT
public
mixed
TYPE_OBJECT
= 'object'
TYPE_OBJECT_CLASS
public
mixed
TYPE_OBJECT_CLASS
= 'object class'
TYPE_RESOURCE
public
mixed
TYPE_RESOURCE
= 'resource'
TYPE_STRING
public
mixed
TYPE_STRING
= 'string'
Methods
addParamsToRequest()
This function returns an string with the params of the request concatenating to it the 'newParams' parameters given by parameter as part of the request parameters.
public
static addParamsToRequest(array<string|int, mixed>|null $newParams) : array<string|int, mixed>
Parameters
- $newParams : array<string|int, mixed>|null
Return values
array<string|int, mixed> —addTimerDebugFlag()
This method adds a debug timer flag.
public
static addTimerDebugFlag(string $flag, string $sufix) : mixed
Parameters
- $flag : string
-
Name of the flag.
- $sufix : string
-
Possible values: Timer::START_SUFFIX, Timer::END_SUFFIX.
Return values
mixed —addTimerDebugTag()
This method adds a debug timer tag.
public
static addTimerDebugTag(string $tag, string $value) : mixed
Parameters
- $tag : string
- $value : string
Return values
mixed —calculateLocale()
This method returns the locale string if it is found (based on the given country and language) in the list of locales supported by the bundle (see ResourceBundle::getLocales()), otherwise it returns $country.
public
static calculateLocale(string $country[, string $language = '' ]) : string
Parameters
- $country : string
- $language : string = ''
Tags
Return values
string —cleanHtmlTags()
This method returns the string given without html tags.
public
static cleanHtmlTags(string $text) : string
Parameters
- $text : string
Return values
string —deleteParamsFromRequest()
This function returns an string with the params of the request eliminating from it the parameters given by parameter.
public
static deleteParamsFromRequest(array<string|int, mixed>|null $parameters) : array<string|int, mixed>
Parameters
- $parameters : array<string|int, mixed>|null
Return values
array<string|int, mixed> —getCamelFromSnake()
This method returns a string in camel format from a string in snake format .
public
static getCamelFromSnake(string $snakeName[, mixed $separator = "_" ]) : array<string|int, mixed>
Parameters
- $snakeName : string
-
string in snake mode.
- $separator : mixed = "_"
Return values
array<string|int, mixed> —getCountryNameByCountryCode()
public
static getCountryNameByCountryCode(string $countryCode) : string
Parameters
- $countryCode : string
Return values
string —getDevice()
This method returns the user device.
public
static getDevice() : string
Return values
string —getDirMap()
This method returns a mapping of the given directory path.
public
static getDirMap(string $dir) : array<string|int, mixed>
Parameters
- $dir : string
-
Path to analyze.
Return values
array<string|int, mixed> —getErrorLabelValue()
public
static getErrorLabelValue(Element $response) : string
Parameters
- $response : Element
Return values
string —getJSDatePatternByLocale()
This method returns the pattern for the given locale.
public
static getJSDatePatternByLocale(string $locale) : string
Parameters
- $locale : string
Tags
Return values
string —getPdfContent()
This method returns the pdf content from a PDFDocument.
public
static getPdfContent(PDFDocument $pdfDocument) : string
Parameters
- $pdfDocument : PDFDocument
Return values
string —getQueryStringParameters()
This method returns the query string parameters.
public
static getQueryStringParameters() : array<string|int, mixed>
Return values
array<string|int, mixed> —getSnakeFromCamel()
This method returns a string in snake format from a string in camel format .
public
static getSnakeFromCamel(string $CamelName[, mixed $separator = "_" ]) : array<string|int, mixed>
Parameters
- $CamelName : string
-
string in snake mode.
- $separator : mixed = "_"
Return values
array<string|int, mixed> —getUserName()
This method returns the user name from the given User using the configured user key criteria.
public
static getUserName(User $user) : string
Parameters
- $user : User
Return values
string —isSalesAgent()
This method returns true if the session user is sales agent, false otherwise.
public
static isSalesAgent(Session|null $session) : bool
Parameters
- $session : Session|null
Return values
bool —isSessionLoggedIn()
This method returns true if the session user is logged, false otherwise.
public
static isSessionLoggedIn(Session|null $session) : bool
Parameters
- $session : Session|null
Return values
bool —isSimulatedUser()
This method returns true if the session user is sales agent, false otherwise.
public
static isSimulatedUser(Session|null $session) : bool
Parameters
- $session : Session|null
Return values
bool —minifyHtml()
This method minifies the given html text and returns it.
public
static minifyHtml(string $html) : string
Parameters
- $html : string
Return values
string —outputJsonHtmlString()
This method returns the given value in json format with html compatibility.
public
static outputJsonHtmlString([mixed $value = null ]) : string
Parameters
- $value : mixed = null
Return values
string —outputTimerDebug()
This method outputs the debug timer.
public
static outputTimerDebug() : mixed
Return values
mixed —paserArrayToPathParameters()
This method returns a Twig function named 'paserArrayToPathParameters'.
public
static paserArrayToPathParameters(array<string|int, mixed> $queryParams) : string
This function returns an string containing the given parameters in the format of an url request (Example: ?param1=value1¶m2=value2).
Parameters
- $queryParams : array<string|int, mixed>
Return values
string —removeAccents()
public
static removeAccents(string $string) : mixed
Parameters
- $string : string
Return values
mixed —setValidateType()
This method checks that the given value corresponds to the given data type.
public
static setValidateType(string $type, mixed $value[, string $className = '' ]) : mixed
If the ckeck is ok then it returns the same given value, otherwise it throws a CommerceException of type CommerceException::UTILS_VALIDATE_TYPE_ERROR.
Allowed values for type parameter:
- Utils::TYPE_ARRAY
- Utils::TYPE_BOOLEAN
- Utils::TYPE_FLOAT
- Utils::TYPE_INT
- Utils::TYPE_NUMERIC
- Utils::TYPE_OBJECT
- Utils::TYPE_OBJECT_CLASS
- Utils::TYPE_RESOURCE
- Utils::TYPE_STRING
- Utils::TYPE_CALLABLE
Parameters
- $type : string
- $value : mixed
- $className : string = ''
-
It has to be provided only in case of type = Utils::TYPE_OBJECT_CLASS to indicate the name of the class.
Tags
Return values
mixed —sortArrayObjects()
This method sorts an array of abjects by the property sended
public
static sortArrayObjects(string $arrayObj, string $propertySort[, string $order = self::SORT_ASC ]) : array<string|int, mixed>
Parameters
- $arrayObj : string
-
Array of objetcs
- $propertySort : string
-
Name of property to sort
- $order : string = self::SORT_ASC
-
Order to apply, must be Utils::SORT_ASC or Utils::SORT_DESC
Return values
array<string|int, mixed> —stopTimerDebug()
This method stops the debug timer.
public
static stopTimerDebug() : mixed