phramework doc
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Namespaces

  • Phramework
    • Authentication
    • Database
      • Operations
    • Exceptions
    • Extensions
    • Models
    • URIStrategy
    • Validate
    • Viewers

Classes

  • Cache
  • Compress
  • Email
  • Execute
  • Filter
  • Language
  • Operator
  • Request
  • Response
  • Upload
  • Util

Class Util

Utility class

Provides a set of methods that perform common, often re-used functions.

Namespace: Phramework\Models
License: Apache-2.0
Author: Xenofon Spafaridis nohponex@gmail.com
Since 0
Todo: add defined settings
Located at Models/Util.php

Methods summary

public static string
# url( string $endpoint = null, string $suffix = '' )

Get url of the API resource.

Get url of the API resource.

This method uses api_base setting to create the url.

Parameters

$endpoint
[Optional]
$suffix
[Optional] Will append to the end of url

Returns

string
Returns the created url
public static string
# toAscii( string $str )

Clears all non ASCII characters from a string and replaces /,_,|,+, ,- charaters to '-'

Clears all non ASCII characters from a string and replaces /,_,|,+, ,- charaters to '-'

Parameters

$str
The input string

Returns

string
Returns the clean string
public static boolean
# beginsWith( string $string, string $search )

Check if the string begins with the search

Check if the string begins with the search

Parameters

$string
The string that used check
$search
The string to search

Returns

boolean
Returns true if the string begins with the search
public static
# _dateFormatted( $datetime, $format = 'j M Y G:i' )

Print formatted date

Print formatted date

public static
# dateFormatted( $datetime, $format = 'j M Y G:i' )
public static string
# userContent( string $content )

Applies htmlentities

Applies htmlentities

Parameters

$content

Returns

string
public static string
# token( $prefix = '' )

Generate a random 40 character hex token

Generate a random 40 character hex token

Returns

string
Returns a random token
public static boolean
# isAjaxRequest( )

Check if incoming request is send using ajax

Check if incoming request is send using ajax

Returns

boolean
public static boolean
# isHTTPS( )

Check if incoming request is send using HTTPS protocol

Check if incoming request is send using HTTPS protocol

Returns

boolean
public static string|false
# getIPAddress( )

Get the ip address of the client

Get the ip address of the client

Returns

string|false
Returns fails on failure
public static
# directoryToArray( string $directory, boolean $recursive = false, boolean $listDirs = false, boolean $listFiles = true, string $exclude = '', array $allowed_filetypes = [], boolean $relative_path = false )

Get an array that represents directory tree

Get an array that represents directory tree

Parameters

$directory
Directory path
$recursive
[Optional] Include sub directories
$listDirs
[Optional] Include directories on listing
$listFiles
[Optional] Include files on listing
$exclude

[Optional] Exclude paths that matches this regular expression

$allowed_filetypes

[Optional] Allowed file extensions, default `[]`` (allow all)

$relative_path

[Optional] Return paths in relative form, default false

public static
# deleteDirectoryContents( string $directory, boolean $DELETE_DIRECTORY = false )

Delete all contents from a directory

Delete all contents from a directory

Parameters

$directory
Directory path
$DELETE_DIRECTORY
[Optional], if is set directory will be deleted too.
public static string
# readableRandomString( integer $length = 8 )

Create a random readable word

Create a random readable word

Parameters

$length
[Optional] String's length

Returns

string
public static array
# curlHeaders( string $url, & $data )

Get Headers from a remote link

Get Headers from a remote link

Parameters

$url
$data

Returns

array
Return headers
public static boolean
# curlDownload( string $url, string $path, $timeout = 3600 )

Download a file from a remote link

Download a file from a remote link

Parameters

$url
$path
$timeout

Returns

boolean
True if download succeed
public static string
# tempfile( string $prefix )

Create a temporary file path

Create a temporary file path

Parameters

$prefix
Prefix of the filename

Returns

string
The path of the temporary filename
public static string
# extension( string $filePath )

Extract extension from file's path

Extract extension from file's path

Parameters

$filePath
The file path

Returns

string
The extension without dot prefix
public static string
# getPath( array $array, string $glue = DIRECTORY_SEPARATOR )

Join directories and filename to create path

Join directories and filename to create path

Parameters

$array
Array with directories and filename for example array( '/tmp', 'me', 'file.tmp' )
$glue
[Optional]

Returns

string
Path
public static
# toSingleSlashes( $input )
public static
# parseRegexp( $input, $pattern )
public static
# getFileSize( string $path )

Get the size of a file Works for large files too (>2GB)

Get the size of a file Works for large files too (>2GB)

Parameters

$path
File's path
public static string
# generateUUID( )

Generate UUID

Generate UUID

Returns

string
Returns a 36 characters string

Since

1.2.0
phramework doc API documentation generated by ApiGen