\MonologUtils

Summary

Methods
Properties
Constants
getClass()
substr()
canonicalizePath()
jsonEncode()
handleJsonError()
expandIniShorthandBytes()
getRecordMessageForException()
No public properties found
DEFAULT_JSON_FLAGS
No protected methods found
No protected properties found
N/A
throwEncodeError()
detectAndCleanUtf8()
No private properties found
N/A

Constants

DEFAULT_JSON_FLAGS

DEFAULT_JSON_FLAGS = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_INVALID_UTF8_SUBSTITUTE | JSON_PARTIAL_OUTPUT_ON_ERROR

Methods

getClass()

getClass(object  $object) : string

Parameters

object $object

Returns

string —

substr()

substr(string  $string, int  $start, ?int  $length = null) : string

Parameters

string $string
int $start
?int $length

Returns

string —

canonicalizePath()

canonicalizePath(string  $streamUrl) : string

Makes sure if a relative path is passed in it is turned into an absolute path

Parameters

string $streamUrl

stream URL or path without protocol

Returns

string —

jsonEncode()

jsonEncode(mixed  $data, int  $encodeFlags = null, bool  $ignoreErrors = false) : string

Return the JSON representation of a value

Parameters

mixed $data
int $encodeFlags

flags to pass to json encode, defaults to DEFAULT_JSON_FLAGS

bool $ignoreErrors

whether to ignore encoding errors or to throw on error, when ignored and the encoding fails, "null" is returned which is valid json for null

Throws

\RuntimeException

if encoding fails and errors are not ignored

Returns

string —

when errors are ignored and the encoding fails, "null" is returned which is valid json for null

handleJsonError()

handleJsonError(int  $code, mixed  $data, int  $encodeFlags = null) : string

Handle a json_encode failure.

If the failure is due to invalid string encoding, try to clean the input and encode again. If the second encoding attempt fails, the initial error is not encoding related or the input can't be cleaned then raise a descriptive exception.

Parameters

int $code

return code of json_last_error function

mixed $data

data that was meant to be encoded

int $encodeFlags

flags to pass to json encode, defaults to JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION

Throws

\RuntimeException

if failure can't be corrected

Returns

string —

JSON encoded data after error correction

expandIniShorthandBytes()

expandIniShorthandBytes(string|false  $val) : int|false

Converts a string with a valid 'memory_limit' format, to bytes.

Parameters

string|false $val

Returns

int|false —

Returns an integer representing bytes. Returns FALSE in case of error.

getRecordMessageForException()

getRecordMessageForException(array  $record) : string

Parameters

array $record

Returns

string —

throwEncodeError()

throwEncodeError(int  $code, mixed  $data) : never

Throws an exception according to a given code with a customized message

Parameters

int $code

return code of json_last_error function

mixed $data

data that was meant to be encoded

Throws

\RuntimeException

Returns

never —

detectAndCleanUtf8()

detectAndCleanUtf8(mixed  $data) : void

Detect invalid UTF-8 string characters and convert to valid UTF-8.

Valid UTF-8 input will be left unmodified, but strings containing invalid UTF-8 codepoints will be reencoded as UTF-8 with an assumed original encoding of ISO-8859-15. This conversion may result in incorrect output if the actual encoding was not ISO-8859-15, but it will be clean UTF-8 output and will not rely on expensive and fragile detection algorithms.

Function converts the input in place in the passed variable so that it can be used as a callback for array_walk_recursive.

Parameters

mixed $data

Input to check and convert if needed, passed by ref