Combu Server  3.1.1
PHP API Documentation
Static Public Member Functions
Utils Class Reference

Static Public Member Functions

static IsIPv4 ($ip)
 
static IsIPv6 ($ip)
 
static DownloadUrl ($url, $saveTo=NULL)
 
static GetAllFiles ($root, $trimRoot=FALSE, $level=0)
 
static GetAllFolders ($root, $recursive=FALSE, $trimRoot=FALSE, $level=0)
 
static HttpErrorCode ($code=401, $message=NULL)
 
static GetServerName ()
 
static GetServerUrl ($url="")
 
static GetUploadUrl ($url="")
 
static CombineUrl ($path1, $path2)
 
static CombinePath ($path1, $path2, $separator=DIRECTORY_SEPARATOR)
 
static GetDateTimeZoneUTC ()
 
static GetCurrentDateTime ($timezone=NULL)
 
static GetCurrentDateTimeFormat ($format="Y-m-d H:i:s", $timezone=NULL)
 
static GetClientIP ()
 
static TicksToTime ($ticks)
 
static TimeToTicks ($time)
 
static StringToTicks ($str)
 
static NewGUID ()
 
static RedirectTo ($url="")
 
static RedirectToSelf ()
 
static ServerResponseRequired ()
 
static EchoJson ($text, $encodeJson=FALSE, $encryptResponse=FALSE)
 
static EchoXml ($xml, $encryptResponse=FALSE)
 
static EchoUnauthorized ($text="")
 
static StartsWith ($text, $search, $ignoreCase=false)
 
static EndsWith ($text, $search, $ignoreCase=false)
 
static GetTimestamp ($data, $add_days=0)
 
static IsValidDate ($text)
 
static IsValidTime ($text)
 
static ConvertSizeFromBytes ($bytes, $to=NULL)
 
static ExtractSearchKeywords ($searchText)
 
static CalcPercentage ($total, $count)
 
static GetPageOffset ($page, $limit)
 
static GetPagesCount ($count, $limit)
 
static GetValidFilename ($oldName, $newExt="")
 
static GetFilenameExtension ($filename)
 
static GetTempname ($fileExt=".tmp")
 
static GenerateRandomCode ($length=0)
 
static IsValidEmail ($email)
 
static JsonEncodeRowsMessage ($rows, $count, $pagesCount=NULL, $extraParams=NULL)
 
static JsonEncodeSuccessMessage ($success=true, $message="", $errors=array())
 
static FillObjectFromRequest (&$obj)
 
static FillObjectFromRow (&$obj, $row, $stripSlashes=false, $callbackOnExists=false)
 
static ObjectToArray ($obj)
 

Detailed Description

Definition at line 5 of file Utils.php.

Member Function Documentation

◆ CalcPercentage()

static CalcPercentage (   $total,
  $count 
)
static

Definition at line 410 of file Utils.php.

◆ CombinePath()

static CombinePath (   $path1,
  $path2,
  $separator = DIRECTORY_SEPARATOR 
)
static

Definition at line 153 of file Utils.php.

◆ CombineUrl()

static CombineUrl (   $path1,
  $path2 
)
static

Definition at line 149 of file Utils.php.

◆ ConvertSizeFromBytes()

static ConvertSizeFromBytes (   $bytes,
  $to = NULL 
)
static

Definition at line 371 of file Utils.php.

◆ DownloadUrl()

static DownloadUrl (   $url,
  $saveTo = NULL 
)
static

Definition at line 15 of file Utils.php.

◆ EchoJson()

static EchoJson (   $text,
  $encodeJson = FALSE,
  $encryptResponse = FALSE 
)
static

Definition at line 262 of file Utils.php.

◆ EchoUnauthorized()

static EchoUnauthorized (   $text = "")
static

Definition at line 299 of file Utils.php.

◆ EchoXml()

static EchoXml (   $xml,
  $encryptResponse = FALSE 
)
static

Definition at line 282 of file Utils.php.

◆ EndsWith()

static EndsWith (   $text,
  $search,
  $ignoreCase = false 
)
static

Definition at line 317 of file Utils.php.

◆ ExtractSearchKeywords()

static ExtractSearchKeywords (   $searchText)
static

Definition at line 392 of file Utils.php.

◆ FillObjectFromRequest()

static FillObjectFromRequest ( $obj)
static

Initialize the object properties from the POST/GET request

Parameters
type$objObject to initialize

Definition at line 578 of file Utils.php.

◆ FillObjectFromRow()

static FillObjectFromRow ( $obj,
  $row,
  $stripSlashes = false,
  $callbackOnExists = false 
)
static

Initialize the object properties from an associative array

Parameters
mixed$objObject to initialize
array$rowAssociative array from to load the properties
boolean$stripSlashesUse stripslashes() on $row (usually if $row is $_REQUEST/$_GET/$_POST
mixed$callbackOnExists(Optional) Callback to call when setting a property, it overrides the common property value assignment

Definition at line 599 of file Utils.php.

◆ GenerateRandomCode()

static GenerateRandomCode (   $length = 0)
static

Generate a random sequence of characters

Parameters
int$lengthThe length of the random code to generate
Returns
string A random code

Definition at line 493 of file Utils.php.

◆ GetAllFiles()

static GetAllFiles (   $root,
  $trimRoot = FALSE,
  $level = 0 
)
static

Definition at line 52 of file Utils.php.

◆ GetAllFolders()

static GetAllFolders (   $root,
  $recursive = FALSE,
  $trimRoot = FALSE,
  $level = 0 
)
static

Definition at line 85 of file Utils.php.

◆ GetClientIP()

static GetClientIP ( )
static

Definition at line 180 of file Utils.php.

◆ GetCurrentDateTime()

static GetCurrentDateTime (   $timezone = NULL)
static

Definition at line 168 of file Utils.php.

◆ GetCurrentDateTimeFormat()

static GetCurrentDateTimeFormat (   $format = "Y-m-d H:i:s",
  $timezone = NULL 
)
static

Definition at line 175 of file Utils.php.

◆ GetDateTimeZoneUTC()

static GetDateTimeZoneUTC ( )
static

Definition at line 164 of file Utils.php.

◆ GetFilenameExtension()

static GetFilenameExtension (   $filename)
static

Get the extension of a file path

Parameters
string$filenameThe file path to check
Returns
string The file extension

Definition at line 469 of file Utils.php.

◆ GetPageOffset()

static GetPageOffset (   $page,
  $limit 
)
static

Definition at line 424 of file Utils.php.

◆ GetPagesCount()

static GetPagesCount (   $count,
  $limit 
)
static

Definition at line 431 of file Utils.php.

◆ GetServerName()

static GetServerName ( )
static

Definition at line 120 of file Utils.php.

◆ GetServerUrl()

static GetServerUrl (   $url = "")
static

Definition at line 128 of file Utils.php.

◆ GetTempname()

static GetTempname (   $fileExt = ".tmp")
static

Generate a random temporary filename with ".tmp" extension

Returns
string Temporary file name

Definition at line 482 of file Utils.php.

◆ GetTimestamp()

static GetTimestamp (   $data,
  $add_days = 0 
)
static

Returns UNIX timestamp from the specified date string

Parameters
DateTime$dataDate to check
int$add_daysNumber of days to add to the date
Returns
int Date/time UNIX timestamp

Definition at line 333 of file Utils.php.

◆ GetUploadUrl()

static GetUploadUrl (   $url = "")
static

Definition at line 145 of file Utils.php.

◆ GetValidFilename()

static GetValidFilename (   $oldName,
  $newExt = "" 
)
static

Get a normalized string to use as filename starting from a specified file path, replacing all the non alphanumeric characters with an underscore

Parameters
string$oldNameString to normalize
type$newExtNew extension to append to the returned string
Returns
string A valid filename

Definition at line 445 of file Utils.php.

◆ HttpErrorCode()

static HttpErrorCode (   $code = 401,
  $message = NULL 
)
static

Definition at line 111 of file Utils.php.

◆ IsIPv4()

static IsIPv4 (   $ip)
static

Definition at line 7 of file Utils.php.

◆ IsIPv6()

static IsIPv6 (   $ip)
static

Definition at line 11 of file Utils.php.

◆ IsValidDate()

static IsValidDate (   $text)
static

Definition at line 353 of file Utils.php.

◆ IsValidEmail()

static IsValidEmail (   $email)
static

Verify if a string is a valid email address

Parameters
string$emailString to check
Returns
boolean TRUE if is a valid email address

Definition at line 518 of file Utils.php.

◆ IsValidTime()

static IsValidTime (   $text)
static

Definition at line 361 of file Utils.php.

◆ JsonEncodeRowsMessage()

static JsonEncodeRowsMessage (   $rows,
  $count,
  $pagesCount = NULL,
  $extraParams = NULL 
)
static

Returns a pre-formatted JSON string: {total: < $count>="">, results: < $rows>="">}

Parameters
array$rowsArray of associative arrays
int$countTotal value
Returns
string JSON formatted string

Definition at line 529 of file Utils.php.

◆ JsonEncodeSuccessMessage()

static JsonEncodeSuccessMessage (   $success = true,
  $message = "",
  $errors = array() 
)
static

Returns a pre-formatted JSON string: {success: < $success>="">, message: < $message>="">, errors: < $errors>="">}

Parameters
boolean$successSuccess value
string$messageMessage value
array$errorsArray of error strings
Returns
string JSON formatted string

Definition at line 569 of file Utils.php.

◆ NewGUID()

static NewGUID ( )
static

Definition at line 219 of file Utils.php.

◆ ObjectToArray()

static ObjectToArray (   $obj)
static

Returns an associative array from object properties (the property name will be the key)

Parameters
mixed$objObject to convert
Returns
array Associative array filled with properties names and values

Definition at line 623 of file Utils.php.

◆ RedirectTo()

static RedirectTo (   $url = "")
static

Definition at line 237 of file Utils.php.

◆ RedirectToSelf()

static RedirectToSelf ( )
static

Definition at line 245 of file Utils.php.

◆ ServerResponseRequired()

static ServerResponseRequired ( )
static

Definition at line 258 of file Utils.php.

◆ StartsWith()

static StartsWith (   $text,
  $search,
  $ignoreCase = false 
)
static

Definition at line 309 of file Utils.php.

◆ StringToTicks()

static StringToTicks (   $str)
static

Converts a given string into C# DateTime.Ticks. Uses strings valid in PHP

String $str Integer

Definition at line 215 of file Utils.php.

◆ TicksToTime()

static TicksToTime (   $ticks)
static

Converts from C# DateTime.Ticks to a Unix Timestamp

Parameters
Integer$ticks
Returns
Integer

Definition at line 194 of file Utils.php.

◆ TimeToTicks()

static TimeToTicks (   $time)
static

Converts from a Unix Timestamp to C# DateTime.Ticks

Parameters
Integer$time
Returns
Integer

Definition at line 204 of file Utils.php.