Documentation

Utils
in package

AbstractYes

Class Utils

Table of Contents

Constants

ROOTURL_REGEX  = '{^((?:http[s]?:\/\/[^\/]+)|(?:\/\/[^\/]+))(.*)}'

Properties

$nonces  : array<string|int, mixed>

Methods

arrayCombine()  : array<string|int, mixed>|false
Array combine but supports different array lengths
arrayDiffMultidimensional()  : array<string|int, mixed>
Returns an array with the differences between $array1 and $array2
arrayFilterRecursive()  : array<string|int, mixed>
Recursively filter an array, filtering values by processing them through the $fn function argument
arrayFlatten()  : array<string|int, mixed>
Flatten an array
arrayFlattenDotNotation()  : array<string|int, mixed>
Flatten a multi-dimensional associative array into dot notation
arrayIsAssociative()  : bool
Array is associative or not
arrayLower()  : array<string|int, mixed>|false
Lowercase an entire array. Useful when combined with `in_array()`
arrayMergeRecursiveUnique()  : array<string|int, mixed>
Recursive Merge with uniqueness
arrayRemoveValue()  : array<string|int, mixed>
Simple function to remove item/s in an array by value
arrayToQueryParams()  : array<string|int, mixed>
Flatten a multi-dimensional associative array into query params.
arrayUnflattenDotNotation()  : array<string|int, mixed>
Opposite of flatten, convert flat dot notation array to multi dimensional array.
basename()  : string
Unicode-safe version of the PHP basename() function.
checkFilename()  : bool
Returns true if filename is considered safe.
contains()  : bool
Check if the $haystack string contains the substring $needle
convertSize()  : int
Convert bytes to the unit specified by the $to parameter.
date2timestamp()  : int
Get the timestamp of a date
dateFormats()  : array<string|int, mixed>
Return the Grav date formats allowed
dateNow()  : string
Get current date/time
download()  : mixed
Provides the ability to download a file to the browser
endsWith()  : bool
Check if the $haystack string ends with the substring $needle
fullPath()  : string
Helper method to find the full path to a file, be it a stream, a relative path, or already a full path
functionExists()  : bool
Check whether a function exists.
generateRandomString()  : string
Generate a random string of a given length
getDotNotation()  : mixed
Get a portion of an array (passed by reference) with dot-notation key
getExtensionByMime()  : string
Return the mimetype based on filename extension
getExtensions()  : array<string|int, mixed>
Get all the extensions for an array of mimetypes
getExtensionsByMime()  : array<string|int, string>
Return all extensions for given mimetype. The first extension is the default one.
getMimeByExtension()  : string
Return the mimetype based on filename extension
getMimeByFilename()  : string
Return the mimetype based on filename
getMimeByLocalFile()  : string|bool
Return the mimetype based on existing local file
getMimeTypes()  : array<string|int, mixed>
Get all the mimetypes for an array of extensions
getNonce()  : string
Creates a hashed nonce tied to the passed action. Tied to the current user and time. The nonce for a given action is the same for 12 hours.
getPageFormat()  : string
Returns the output render format, usually the extension provided in the URL. (e.g. `html`, `json`, `xml`, etc).
getPagePathFromToken()  : string
Get relative page path based on a token.
getPathFromToken()  : string
Get relative path based on a token.
getSubnet()  : string
Find the subnet of an ip with CIDR prefix size
getSupportPageTypes()  : array<string|int, mixed>
Wrapper to ensure html, htm in the front of the supported page types
getUploadLimit()  : int
isAdminPlugin()  : bool
Simple helper method to get whether or not the admin plugin is active
isApache()  : bool
Utility to determine if the server running PHP is Apache
isAssoc()  : bool
isDangerousFunction()  : bool
isFilesystemFunction()  : bool
isFunctionDisabled()  : bool
Check whether a function is disabled in the PHP settings
isNegative()  : bool
Checks if a value is negative (false)
isPositive()  : bool
Checks if a value is positive (true)
isWindows()  : bool
Utility method to determine if the current OS is Windows
matchWildcard()  : false|int
Function that can match wildcards
mb_substr_replace()  : string
Multibyte compatible substr_replace
mergeObjects()  : object
Merge two objects into one.
multibyteParseUrl()  : array<string|int, mixed>
Multibyte-safe Parse URL function
normalizePath()  : string
Normalize path by processing relative `.` and `..` syntax and merging path
parseSize()  : int
Parse a readable file size and return a value in bytes
pathinfo()  : array<string|int, mixed>|string
Unicode-safe version of PHP’s pathinfo() function.
pathPrefixedByLangCode()  : bool|string
Checks if the passed path contains the language code prefix
prettySize()  : string
Return a pretty size based on bytes
processMarkdown()  : string
Process a string as markdown
replaceFirstOccurrence()  : string
Utility method to replace only the first occurrence in a string
replaceLastOccurrence()  : string
Utility method to replace only the last occurrence in a string
resolve()  : mixed
safeTruncate()  : string
Truncate text by number of characters in a "word-safe" manor.
safeTruncateHtml()  : string
Truncate HTML by number of characters in a "word-safe" manor.
setDotNotation()  : mixed
Set portion of array (passed by reference) for a dot-notation key and set the value
simpleTemplate()  : string
Render simple template filling up the variables in it. If value is not defined, leave it as it was.
sortArrayByArray()  : array<string|int, mixed>
Sort a multidimensional array by another array of ordered keys
sortArrayByKey()  : array<string|int, mixed>
Sort an array by a key value in the array
startsWith()  : bool
Check if the $haystack string starts with the substring $needle
substrToString()  : string
Returns the substring of a string up to a specified needle. if not found, return the whole haystack
timezones()  : array<string|int, mixed>
Get the formatted timezones list
toAscii()  : string
truncate()  : string
Truncate text by number of characters but can cut off words.
truncateHtml()  : string
Truncate HTML by number of characters. not "word-safe"!
uniqueId()  : string
Generates a random string with configurable length, prefix and suffix.
url()  : string|false
Simple helper method to make getting a Grav URL easier
verifyNonce()  : bool
Verify the passed nonce for the give action
resolveTokenPath()  : array<string|int, string>|null
Returns [token, route, path] from '@token/route:/path'. Route and path are optional. If pattern does not match, return null.
generateNonceString()  : string
Generates a nonce string to be hashed. Called by self::getNonce() We removed the IP portion in this version because it causes too many inconsistencies with reverse proxy setups.
nonceTick()  : int
Get the time-dependent variable for nonce creation.

Constants

ROOTURL_REGEX

protected mixed ROOTURL_REGEX = '{^((?:http[s]?:\/\/[^\/]+)|(?:\/\/[^\/]+))(.*)}'

Properties

$nonces

protected static array<string|int, mixed> $nonces = []

Methods

arrayCombine()

Array combine but supports different array lengths

public static arrayCombine(array<string|int, mixed> $arr1, array<string|int, mixed> $arr2) : array<string|int, mixed>|false
Parameters
$arr1 : array<string|int, mixed>
$arr2 : array<string|int, mixed>
Return values
array<string|int, mixed>|false

arrayDiffMultidimensional()

Returns an array with the differences between $array1 and $array2

public static arrayDiffMultidimensional(array<string|int, mixed> $array1, array<string|int, mixed> $array2) : array<string|int, mixed>
Parameters
$array1 : array<string|int, mixed>
$array2 : array<string|int, mixed>
Return values
array<string|int, mixed>

arrayFilterRecursive()

Recursively filter an array, filtering values by processing them through the $fn function argument

public static arrayFilterRecursive(array<string|int, mixed> $source, callable $fn) : array<string|int, mixed>
Parameters
$source : array<string|int, mixed>

the Array to filter

$fn : callable

the function to pass through each array item

Return values
array<string|int, mixed>

arrayFlatten()

Flatten an array

public static arrayFlatten(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

arrayFlattenDotNotation()

Flatten a multi-dimensional associative array into dot notation

public static arrayFlattenDotNotation(array<string|int, mixed> $array[, string $prepend = '' ]) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
$prepend : string = ''
Return values
array<string|int, mixed>

arrayIsAssociative()

Array is associative or not

public static arrayIsAssociative(array<string|int, mixed> $arr) : bool
Parameters
$arr : array<string|int, mixed>
Return values
bool

arrayLower()

Lowercase an entire array. Useful when combined with `in_array()`

public static arrayLower(array<string|int, mixed> $a) : array<string|int, mixed>|false
Parameters
$a : array<string|int, mixed>
Return values
array<string|int, mixed>|false

arrayMergeRecursiveUnique()

Recursive Merge with uniqueness

public static arrayMergeRecursiveUnique(array<string|int, mixed> $array1, array<string|int, mixed> $array2) : array<string|int, mixed>
Parameters
$array1 : array<string|int, mixed>
$array2 : array<string|int, mixed>
Return values
array<string|int, mixed>

arrayRemoveValue()

Simple function to remove item/s in an array by value

public static arrayRemoveValue(array<string|int, mixed> $search, string|array<string|int, mixed> $value) : array<string|int, mixed>
Parameters
$search : array<string|int, mixed>
$value : string|array<string|int, mixed>
Return values
array<string|int, mixed>

arrayToQueryParams()

Flatten a multi-dimensional associative array into query params.

public static arrayToQueryParams(array<string|int, mixed> $array[, string $prepend = '' ]) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
$prepend : string = ''
Return values
array<string|int, mixed>

arrayUnflattenDotNotation()

Opposite of flatten, convert flat dot notation array to multi dimensional array.

public static arrayUnflattenDotNotation(array<string|int, mixed> $array[, string $separator = '.' ]) : array<string|int, mixed>

If any of the parent has a scalar value, all children get ignored:

admin.pages=true admin.pages.read=true

becomes

admin: pages: true

Parameters
$array : array<string|int, mixed>
$separator : string = '.'
Return values
array<string|int, mixed>

checkFilename()

Returns true if filename is considered safe.

public static checkFilename(string $filename) : bool
Parameters
$filename : string
Return values
bool

contains()

Check if the $haystack string contains the substring $needle

public static contains(string $haystack, string|array<string|int, string> $needle[, bool $case_sensitive = true ]) : bool
Parameters
$haystack : string
$needle : string|array<string|int, string>
$case_sensitive : bool = true
Return values
bool

convertSize()

Convert bytes to the unit specified by the $to parameter.

public static convertSize(int $bytes, string $to[, int $decimal_places = 1 ]) : int
Parameters
$bytes : int

The filesize in Bytes.

$to : string

The unit type to convert to. Accepts K, M, or G for Kilobytes, Megabytes, or Gigabytes, respectively.

$decimal_places : int = 1

The number of decimal places to return.

Return values
int

Returns only the number of units, not the type letter. Returns 0 if the $to unit type is out of scope.

date2timestamp()

Get the timestamp of a date

public static date2timestamp(string $date[, string|null $format = null ]) : int
Parameters
$date : string

a String expressed in the system.pages.dateformat.default format, with fallback to a strtotime argument

$format : string|null = null

a date format to use if possible

Return values
int

the timestamp

dateFormats()

Return the Grav date formats allowed

public static dateFormats() : array<string|int, mixed>
Return values
array<string|int, mixed>

dateNow()

Get current date/time

public static dateNow([string|null $default_format = null ]) : string
Parameters
$default_format : string|null = null
Tags
throws
Exception
Return values
string

download()

Provides the ability to download a file to the browser

public static download(string $file[, bool $force_download = true ][, int $sec = 0 ][, int $bytes = 1024 ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$file : string

the full path to the file to be downloaded

$force_download : bool = true

as opposed to letting browser choose if to download or render

$sec : int = 0

Throttling, try 0.1 for some speed throttling of downloads

$bytes : int = 1024

Size of chunks to send in bytes. Default is 1024

$options : array<string|int, mixed> = []

Extra options: [mime, download_name, expires]

Tags
throws
Exception

endsWith()

Check if the $haystack string ends with the substring $needle

public static endsWith(string $haystack, string|array<string|int, string> $needle[, bool $case_sensitive = true ]) : bool
Parameters
$haystack : string
$needle : string|array<string|int, string>
$case_sensitive : bool = true
Return values
bool

fullPath()

Helper method to find the full path to a file, be it a stream, a relative path, or already a full path

public static fullPath(string $path) : string
Parameters
$path : string
Return values
string

functionExists()

Check whether a function exists.

public static functionExists(string $function) : bool

Disabled functions count as non-existing functions, just like in PHP 8+.

Parameters
$function : string

the name of the function to check

Return values
bool

generateRandomString()

Generate a random string of a given length

public static generateRandomString([int $length = 5 ]) : string
Parameters
$length : int = 5
Return values
string

getDotNotation()

Get a portion of an array (passed by reference) with dot-notation key

public static getDotNotation(array<string|int, mixed> $array, string|int|null $key[, null $default = null ]) : mixed
Parameters
$array : array<string|int, mixed>
$key : string|int|null
$default : null = null

getExtensionByMime()

Return the mimetype based on filename extension

public static getExtensionByMime(string $mime[, string $default = 'html' ]) : string
Parameters
$mime : string

mime type (eg "text/html")

$default : string = 'html'

default value

Return values
string

getExtensions()

Get all the extensions for an array of mimetypes

public static getExtensions(array<string|int, mixed> $mimetypes) : array<string|int, mixed>
Parameters
$mimetypes : array<string|int, mixed>
Return values
array<string|int, mixed>

getExtensionsByMime()

Return all extensions for given mimetype. The first extension is the default one.

public static getExtensionsByMime(string $mime) : array<string|int, string>
Parameters
$mime : string

Mime type (eg 'image/jpeg')

Return values
array<string|int, string>

List of extensions eg. ['jpg', 'jpe', 'jpeg']

getMimeByExtension()

Return the mimetype based on filename extension

public static getMimeByExtension(string $extension[, string $default = 'application/octet-stream' ]) : string
Parameters
$extension : string

Extension of file (eg "txt")

$default : string = 'application/octet-stream'
Return values
string

getMimeByFilename()

Return the mimetype based on filename

public static getMimeByFilename(string $filename[, string $default = 'application/octet-stream' ]) : string
Parameters
$filename : string

Filename or path to file

$default : string = 'application/octet-stream'

default value

Return values
string

getMimeByLocalFile()

Return the mimetype based on existing local file

public static getMimeByLocalFile(string $filename[, string $default = 'application/octet-stream' ]) : string|bool
Parameters
$filename : string

Path to the file

$default : string = 'application/octet-stream'
Return values
string|bool

getMimeTypes()

Get all the mimetypes for an array of extensions

public static getMimeTypes(array<string|int, mixed> $extensions) : array<string|int, mixed>
Parameters
$extensions : array<string|int, mixed>
Return values
array<string|int, mixed>

getNonce()

Creates a hashed nonce tied to the passed action. Tied to the current user and time. The nonce for a given action is the same for 12 hours.

public static getNonce(string $action[, bool $previousTick = false ]) : string
Parameters
$action : string

the action the nonce is tied to (e.g. save-user-admin or move-page-homepage)

$previousTick : bool = false

if true, generates the token for the previous tick (the previous 12 hours)

Return values
string

the nonce

getPageFormat()

Returns the output render format, usually the extension provided in the URL. (e.g. `html`, `json`, `xml`, etc).

public static getPageFormat() : string
Return values
string

getPagePathFromToken()

Get relative page path based on a token.

public static getPagePathFromToken(string $path[, PageInterface|null $page = null ]) : string
Parameters
$path : string
$page : PageInterface|null = null
Tags
throws
RuntimeException
Return values
string

getPathFromToken()

Get relative path based on a token.

public static getPathFromToken(string $path[, FlexObjectInterface|PageInterface|null $object = null ]) : string

Path supports following syntaxes:

'self@', 'self@/path' 'page@:/route', 'page@:/route/filename.ext' 'theme@:', 'theme@:/path'

Parameters
$path : string
$object : FlexObjectInterface|PageInterface|null = null
Tags
throws
RuntimeException
Return values
string

getSubnet()

Find the subnet of an ip with CIDR prefix size

public static getSubnet(string $ip[, int $prefix = 64 ]) : string
Parameters
$ip : string
$prefix : int = 64
Return values
string

getSupportPageTypes()

Wrapper to ensure html, htm in the front of the supported page types

public static getSupportPageTypes([array<string|int, mixed>|null $defaults = null ]) : array<string|int, mixed>
Parameters
$defaults : array<string|int, mixed>|null = null
Return values
array<string|int, mixed>

getUploadLimit()

public static getUploadLimit() : int
Return values
int

isAdminPlugin()

Simple helper method to get whether or not the admin plugin is active

public static isAdminPlugin() : bool
Return values
bool

isApache()

Utility to determine if the server running PHP is Apache

public static isApache() : bool
Return values
bool

isAssoc()

public static isAssoc(array<string|int, mixed> $array) : bool
Parameters
$array : array<string|int, mixed>
Return values
bool

isDangerousFunction()

public static isDangerousFunction(string|array<string|int, mixed>|Closure $name) : bool
Parameters
$name : string|array<string|int, mixed>|Closure
Return values
bool

isFilesystemFunction()

public static isFilesystemFunction(string $name) : bool
Parameters
$name : string
Return values
bool

isFunctionDisabled()

Check whether a function is disabled in the PHP settings

public static isFunctionDisabled(string $function) : bool
Parameters
$function : string

the name of the function to check

Return values
bool

isNegative()

Checks if a value is negative (false)

public static isNegative(string $value) : bool
Parameters
$value : string
Return values
bool

isPositive()

Checks if a value is positive (true)

public static isPositive(string $value) : bool
Parameters
$value : string
Return values
bool

isWindows()

Utility method to determine if the current OS is Windows

public static isWindows() : bool
Return values
bool

matchWildcard()

Function that can match wildcards

public static matchWildcard(string $wildcard_pattern, string $haystack) : false|int

match_wildcard('foo*', $test), // TRUE match_wildcard('bar*', $test), // FALSE match_wildcard('bar', $test), // TRUE match_wildcard('blob', $test), // TRUE match_wildcard('a?d', $test), // TRUE match_wildcard('etc*', $test) // TRUE

Parameters
$wildcard_pattern : string
$haystack : string
Return values
false|int

mb_substr_replace()

Multibyte compatible substr_replace

public static mb_substr_replace(string $original, string $replacement, int $position, int $length) : string
Parameters
$original : string
$replacement : string
$position : int
$length : int
Return values
string

mergeObjects()

Merge two objects into one.

public static mergeObjects(object $obj1, object $obj2) : object
Parameters
$obj1 : object
$obj2 : object
Return values
object

multibyteParseUrl()

Multibyte-safe Parse URL function

public static multibyteParseUrl(string $url) : array<string|int, mixed>
Parameters
$url : string
Tags
throws
InvalidArgumentException
Return values
array<string|int, mixed>

normalizePath()

Normalize path by processing relative `.` and `..` syntax and merging path

public static normalizePath(string $path) : string
Parameters
$path : string
Return values
string

parseSize()

Parse a readable file size and return a value in bytes

public static parseSize(string|int|float $size) : int
Parameters
$size : string|int|float
Return values
int

pathinfo()

Unicode-safe version of PHP’s pathinfo() function.

public static pathinfo(string $path[, int|null $flags = null ]) : array<string|int, mixed>|string
Parameters
$path : string
$flags : int|null = null
Tags
link
https://www.php.net/manual/en/function.pathinfo.php
Return values
array<string|int, mixed>|string

pathPrefixedByLangCode()

Checks if the passed path contains the language code prefix

public static pathPrefixedByLangCode(string $string) : bool|string
Parameters
$string : string

The path

Return values
bool|string

Either false or the language

prettySize()

Return a pretty size based on bytes

public static prettySize(int $bytes[, int $precision = 2 ]) : string
Parameters
$bytes : int
$precision : int = 2
Return values
string

processMarkdown()

Process a string as markdown

public static processMarkdown(string $string[, bool $block = true ][, PageInterface|null $page = null ]) : string
Parameters
$string : string
$block : bool = true

Block or Line processing

$page : PageInterface|null = null
Tags
throws
Exception
Return values
string

replaceFirstOccurrence()

Utility method to replace only the first occurrence in a string

public static replaceFirstOccurrence(string $search, string $replace, string $subject) : string
Parameters
$search : string
$replace : string
$subject : string
Return values
string

replaceLastOccurrence()

Utility method to replace only the last occurrence in a string

public static replaceLastOccurrence(string $search, string $replace, string $subject) : string
Parameters
$search : string
$replace : string
$subject : string
Return values
string

resolve()

public static resolve(array<string|int, mixed> $array, string $path[, null $default = null ]) : mixed

Use ->getDotNotation() method instead.

Parameters
$array : array<string|int, mixed>
$path : string
$default : null = null

safeTruncate()

Truncate text by number of characters in a "word-safe" manor.

public static safeTruncate(string $string[, int $limit = 150 ]) : string
Parameters
$string : string
$limit : int = 150
Return values
string

safeTruncateHtml()

Truncate HTML by number of characters in a "word-safe" manor.

public static safeTruncateHtml(string $text[, int $length = 25 ][, string $ellipsis = '...' ]) : string
Parameters
$text : string
$length : int = 25

in words

$ellipsis : string = '...'
Return values
string

setDotNotation()

Set portion of array (passed by reference) for a dot-notation key and set the value

public static setDotNotation(array<string|int, mixed> &$array, string|int|null $key, mixed $value[, bool $merge = false ]) : mixed
Parameters
$array : array<string|int, mixed>
$key : string|int|null
$value : mixed
$merge : bool = false

simpleTemplate()

Render simple template filling up the variables in it. If value is not defined, leave it as it was.

public static simpleTemplate(string $template, array<string|int, mixed> $variables[, array<string|int, mixed> $brackets = ['{', '}'] ]) : string
Parameters
$template : string

Template string

$variables : array<string|int, mixed>

Variables with values

$brackets : array<string|int, mixed> = ['{', '}']

Optional array of opening and closing brackets or symbols

Return values
string

Final string filled with values

sortArrayByArray()

Sort a multidimensional array by another array of ordered keys

public static sortArrayByArray(array<string|int, mixed> $array, array<string|int, mixed> $orderArray) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
$orderArray : array<string|int, mixed>
Return values
array<string|int, mixed>

sortArrayByKey()

Sort an array by a key value in the array

public static sortArrayByKey(mixed $array, string|int $array_key[, int $direction = SORT_DESC ][, int $sort_flags = SORT_REGULAR ]) : array<string|int, mixed>
Parameters
$array : mixed
$array_key : string|int
$direction : int = SORT_DESC
$sort_flags : int = SORT_REGULAR
Return values
array<string|int, mixed>

startsWith()

Check if the $haystack string starts with the substring $needle

public static startsWith(string $haystack, string|array<string|int, string> $needle[, bool $case_sensitive = true ]) : bool
Parameters
$haystack : string
$needle : string|array<string|int, string>
$case_sensitive : bool = true
Return values
bool

substrToString()

Returns the substring of a string up to a specified needle. if not found, return the whole haystack

public static substrToString(string $haystack, string $needle[, bool $case_sensitive = true ]) : string
Parameters
$haystack : string
$needle : string
$case_sensitive : bool = true
Return values
string

timezones()

Get the formatted timezones list

public static timezones() : array<string|int, mixed>
Return values
array<string|int, mixed>

toAscii()

public static toAscii(string $string) : string
Parameters
$string : string
Return values
string

truncate()

Truncate text by number of characters but can cut off words.

public static truncate(string $string[, int $limit = 150 ][, bool $up_to_break = false ][, string $break = ' ' ][, string $pad = '…' ]) : string
Parameters
$string : string
$limit : int = 150

Max number of characters.

$up_to_break : bool = false

truncate up to breakpoint after char count

$break : string = ' '

Break point.

$pad : string = '…'

Appended padding to the end of the string.

Return values
string

truncateHtml()

Truncate HTML by number of characters. not "word-safe"!

public static truncateHtml(string $text[, int $length = 100 ][, string $ellipsis = '...' ]) : string
Parameters
$text : string
$length : int = 100

in characters

$ellipsis : string = '...'
Return values
string

uniqueId()

Generates a random string with configurable length, prefix and suffix.

public static uniqueId([int $length = 13 ][, array<string|int, mixed> $options = [] ]) : string

Unlike the built-in uniqid(), this string is non-conflicting and safe

Parameters
$length : int = 13
$options : array<string|int, mixed> = []
Tags
throws
Exception
Return values
string

url()

Simple helper method to make getting a Grav URL easier

public static url(string|object $input[, bool $domain = false ][, bool $fail_gracefully = false ]) : string|false
Parameters
$input : string|object
$domain : bool = false
$fail_gracefully : bool = false
Return values
string|false

verifyNonce()

Verify the passed nonce for the give action

public static verifyNonce(string|array<string|int, string> $nonce, string $action) : bool
Parameters
$nonce : string|array<string|int, string>

the nonce to verify

$action : string

the action to verify the nonce to

Return values
bool

verified or not

resolveTokenPath()

Returns [token, route, path] from '@token/route:/path'. Route and path are optional. If pattern does not match, return null.

protected static resolveTokenPath(string $path) : array<string|int, string>|null
Parameters
$path : string
Return values
array<string|int, string>|null

generateNonceString()

Generates a nonce string to be hashed. Called by self::getNonce() We removed the IP portion in this version because it causes too many inconsistencies with reverse proxy setups.

private static generateNonceString(string $action[, bool $previousTick = false ]) : string
Parameters
$action : string
$previousTick : bool = false

if true, generates the token for the previous tick (the previous 12 hours)

Return values
string

the nonce string

nonceTick()

Get the time-dependent variable for nonce creation.

private static nonceTick() : int

Now a tick lasts a day. Once the day is passed, the nonce is not valid any more. Find a better way to ensure nonces issued near the end of the day do not expire in that small amount of time

Return values
int

the time part of the nonce. Changes once every 24 hours


        
On this page

Search results