Q_Utils Class
Functions for doing various things
Item Index
Methods
- canWriteToPath static
- chr static
- copy static
- csvLines
- get static
- hash static
- hmac static
- nodeUrl static
- normalize static
- normalizePath static
- obfuscate static
- ord static
- parts static
- post static
- postAsync static
- queryExternal static
- queryInternal static
- request static
- sendToNode static
- sign static
- signature static
- socketPath static
- splitId static
- symlink static
- unique static
- unserializeSession static
- uuid static
Events
Methods
canWriteToPath
-
$path
-
[$throwIfNotWritable=false]
-
[$mkdirIfMissing]
Checks whether the path can be used for writing files by the current session
Parameters:
-
$path
StringThe path to check
-
[$throwIfNotWritable=false]
Mixed optionalDefaults to false. Set to true to throw a Q_Exception_CantWriteToPath if no user is logged in. Set to null to skip firing the "before" event, thereby skipping custom access checks. The null value is useful for when the filename is generated by the app, not the user.
-
[$mkdirIfMissing]
Boolean optionalDefaults to false. Pass true here to make a directory at the specified path, if it's writeable but missing. Pass a string here to override the umask before making the directory.
Returns:
chr
-
$intval
Like chr but handles utf-8 encoding
Parameters:
-
$intval
Integer
Returns:
copy
-
$source
-
$dest
Copies a file or directory from path to another. May overwrite existing files.
Parameters:
-
$source
String -
$dest
String
csvLines
-
$input
-
[$enclosure='"']
-
[$escape="\\"]
Get the lines from a csv file
Parameters:
-
$input
String -
[$enclosure='"']
String optional -
[$escape="\\"]
String optional
Returns:
array
get
-
$url
-
[$user_agent=null]
-
[$follow_redirects=true]
-
[$header=null]
Issues a GET request, and returns the response
Parameters:
-
$url
String | ArrayThe URL to post to This can also be an array of ($url, $ip) to send the request to a particular IP, while retaining the hostname and request URI
-
[$user_agent=null]
String optionalThe user-agent string to send. Defaults to Mozilla.
-
[$follow_redirects=true]
String optionalWhether to follow redirects when getting a response.
-
[$header=null]
String optionalOptional string to replace the entire GET header
Returns:
The response.
NOTE: The function waits for it, which might take a while!
hash
-
$test
Hashes text in a standard way. It uses md5, which is fast and irreversible, so it's good for things like indexes, but not for obscuring information.
Parameters:
-
$test
String
Returns:
hmac
-
$algo
-
$data
-
$key
-
[$raw_output=false]
Calculates hmac
Parameters:
-
$algo
String -
$data
String -
$key
String -
[$raw_output=false]
Boolean optional
Returns:
nodeUrl
()
static
Returns base url for node.js requests
normalize
-
$text
-
[$replacement='_']
-
[$characters=null]
-
[$numChars=200]
-
[$keepCaseIntact=false]
Normalizes text by converting it to lower case, and replacing all non-accepted characters with underscores.
Parameters:
-
$text
StringThe text to normalize
-
[$replacement='_']
String optionalA string to replace one or more unacceptable characters. You can also change this default using the config Db/normalize/replacement
-
[$characters=null]
String optionalDefaults to '/[^A-Za-z0-9]+/'. A regexp characters that are not acceptable. You can also change this default using the config Db/normalize/characters
-
[$numChars=200]
Integer optionalDefaults to 200, maximum length of normalized string
-
[$keepCaseIntact=false]
Boolean optionalIf true, doesn't convert to lowercase
normalizePath
-
$path
Normalize paths to use DS, used mostly on Windows
Parameters:
-
$path
String | Arraythe path or paths to normalize
obfuscate
-
$text
-
[$key="blah"]
Some basic obfuscation to thwart scrapers from getting emails, phone numbers, etc.
Parameters:
-
$text
StringThe text to obfuscate
-
[$key="blah"]
String optionalSome key to use for obfuscation
Returns:
ord
-
$text
Like ord but handles utf-8 encoding
Parameters:
-
$text
String
Returns:
parts
-
$source
-
$ofset
-
$length
-
$separator
Takes parts of a string
Parameters:
-
$source
Stringthe string to split by the separator
-
$ofset
Integerjust like in array_slice
-
$length
Integerjust like in array_slice
-
$separator
Stringthe separator, defaults to '/'
Returns:
the extracted parts, joined together again by the separator
post
-
$url
-
$data
-
[$user_agent=null]
-
[$follow_redirects=true]
-
[$header=null]
Issues a POST request, and returns the response
Parameters:
-
$url
String | ArrayThe URL to post to This can also be an array of ($url, $ip) to send the request to a particular IP, while retaining the hostname and request URI
-
$data
Array | StringThe data content to post or an array of ($field => $value) pairs
-
[$user_agent=null]
String optionalThe user-agent string to send. Defaults to Mozilla.
-
[$follow_redirects=true]
String optionalWhether to follow redirects when getting a response.
-
[$header=null]
String optionalOptional string to replace the entire POST header
Returns:
The response.
NOTE: The function waits for it, which might take a while!
postAsync
-
$uri
-
$params
-
[$user_agent=null]
-
[$timeout=Q_UTILS_CONNECTION_TIMEOUT]
-
[$throwIfRefused=false]
-
[$closeSocket=false]
Sends a post and returns right away. In the url being called, make sure it ignores user aborts. For example, in PHP call ignore_user_abort(true) at the top of that script.
Parameters:
-
$uri
String | ArrayThe url to post to
-
$params
ArrayAn associative array of params
-
[$user_agent=null]
String optionalThe user-agent string to send. If null, is replaced by default of "Mozilla/5.0 ..." If false, not sent.
-
[$timeout=Q_UTILS_CONNECTION_TIMEOUT]
Integer optional -
[$throwIfRefused=false]
Boolean optionalPass true here to throw an exception whenever Node process is not running or refuses the request
-
[$closeSocket=false]
Boolean optionalPass true to close the socket after sending. The default is to do HTTP pipelining.
Returns:
Returns whether the post succeeded.
queryExternal
-
$handler
-
[$data=array()]
-
[$url=null]
Queries a server externally to the specified handler. Expects json array with either ['slots']['data'] or ['error'] fields filled
Parameters:
-
$handler
Stringthe handler to call
-
[$data=array()]
Array optionalAssociative array of data of the message to send.
-
[$url=null]
String | Array optionaland url to query. Default to 'Q/web/appRootUrl' config value
Returns:
The response from the server
queryInternal
-
$handler
-
[$data=array()]
-
[$url=null]
Sends a query to Node.js internal server and gets the response This method shall make communications behind firewal
Parameters:
-
$handler
Stringis used as 'Q/method' while querying $url
-
[$data=array()]
Array optionalAssociative array of data of the message to send.
-
[$url=null]
String | Array optionaland url to query. Default to 'Q/nodeInternal' config value and path '/Q_Utils/query'
Returns:
The response from the server
request
-
$method
-
$url
-
$data
-
[$user_agent=null]
-
[$follow_redirects=true]
-
[$header=null]
Issues an http request, and returns the response
Parameters:
-
$method
StringThe http method to use
-
$url
String | ArrayThe URL to request This can also be an array of ($url, $ip) to send the request to a particular IP, while retaining the hostname and request URI
-
$data
Array | StringThe data content to post or an array of ($field => $value) pairs
-
[$user_agent=null]
String optionalThe user-agent string to send. Defaults to Mozilla.
-
[$follow_redirects=true]
String optionalWhether to follow redirects when getting a response.
-
[$header=null]
String optionalOptional string to replace the entire header
Returns:
The response.
NOTE: The function waits for it, which might take a while!
sendToNode
-
$data
-
[$url=null]
-
[$throwIfRefused=false]
Sends asynchronous internal message to Node.js If "Q.clientId" is in $_REQUEST, adds it into the data
Parameters:
-
$data
ArrayAssociative array of data of the message to send. It should contain the key "Q/method" so Node can decide what to do with the message.
-
[$url=null]
String | Array optionaland url to query. Default to 'Q/nodeInternal' config value and path '/Q/node'
-
[$throwIfRefused=false]
Boolean optionalPass true here to throw an exception whenever Node process is not running or refuses the request
sign
-
$data
-
[$fieldKeys]
Sign the data
Parameters:
-
$data
ArrayThe array of data
-
[$fieldKeys]
Array | String optionalPath of the key under which to save signature
Returns:
signature
-
$data
-
$secret
Generates signature for the data
Parameters:
-
$data
Array | String -
$secret
String
Returns:
socketPath
()
static
Returns path option for socket.io connection
splitId
-
$id
-
[$lengths=3]
-
[$delimiter=DIRECTORY_SEPARATOR]
-
[$internalDelimiter='/']
Used to split ids into one or more segments, in order to store millions of files under a directory, without running into limits of various filesystems on the number of files in a directory. Consider using Amazon S3 or another service for uploading files in production.
Parameters:
-
$id
Stringthe id to split
-
[$lengths=3]
Integer optionalthe lengths of each segment (the last one can be smaller)
-
[$delimiter=DIRECTORY_SEPARATOR]
String optionalthe delimiter to put between segments
-
[$internalDelimiter='/']
String optionalthe internal delimiter, if it is set then only the last part is split, and instances of internalDelimiter are replaced by delimiter
Returns:
the segments, delimited by the delimiter
symlink
-
$target
-
$link
-
[$skipIfExists=false]
Create a symlink
Parameters:
-
$target
String -
$link
String -
[$skipIfExists=false]
Boolean optional
Returns:
true if link was created, false if it already exists
unique
-
[$len=8]
-
[$characters='abcdefghijklmnopqrstuvwxyz']
Generates random letter sequence
Parameters:
-
[$len=8]
Integer optional -
[$characters='abcdefghijklmnopqrstuvwxyz']
String optionalAll the characters from which to construct possible ids
Returns:
unserializeSession
-
$val
Unserializes session stored in PHP 5.2 and 5.3 format
Parameters:
-
$val
String
Returns:
uuid
()
String
static
Generates a Universally Unique IDentifier, version 4. This function generates a truly random UUID.
Returns:
A UUID, made up of 32 hex digits and 4 hyphens.
Events
Q/Utils/sendToNode
Before
Event Payload:
-
data
Array -
'url'
String | Array