LTI Integration Library 5.1.4
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
Util Class Reference

Class to implement utility methods. More...

Static Public Member Functions

static bool isLtiMessage ()
 Check whether the request received could be an LTI message.
 
static array getRequestParameters ()
 Return GET and POST request parameters (POST parameters take precedence).
 
static void logError (string $message, bool $showSource=true)
 Log an error message.
 
static void logInfo (string $message, bool $showSource=false)
 Log an information message.
 
static void logDebug (string $message, bool $showSource=false)
 Log a debug message.
 
static void logRequest (bool $debugLevel=false)
 Log a request received.
 
static void logForm (string $url, array $params, string $method='POST', bool $debugLevel=false)
 Log a form submission.
 
static void log (string $message, bool $showSource=false)
 Log an error message irrespective of the logging level.
 
static void setMessage (bool $isError, string $message)
 Set an error or warning message.
 
static array getMessages (bool $isError)
 Get the system error or warning messages.
 
static string sendForm (string $url, array $params, string $target='', string $javascript='')
 Generate a web page containing an auto-submitted form of parameters.
 
static never redirect (string $url, array $params)
 Redirect to a URL with query parameters.
 
static void setTestCookie (bool $delete=false)
 Set or delete a test cookie.
 
static string getRandomString (int $length=8)
 Generate a random string.
 
static string stripHtml (string $html)
 Strip HTML tags from a string.
 
static string urlEncode (?string $val)
 URL encode a value.
 
static string valToString (mixed $val, ?string $default='')
 Convert a value to a string.
 
static int float null valToNumber (mixed $val)
 Convert a value to a numeric.
 
static bool valToBoolean (mixed $val)
 Convert a value to a boolean.
 
static object null checkObject (object $obj, string $fullname, bool $required=false, bool $stringValues=false)
 Get the named object element from object.
 
static array checkArray (object $obj, string $fullname, bool $required=false, bool $notEmpty=false)
 Get the named array element from object.
 
static string checkString (object $obj, string $fullname, bool $required=false, bool $notEmpty=false, string|array $fixedValue='', bool $overrideStrictMode=false, ?string $default='')
 Get the named string element from object.
 
static int float null checkNumber (object $obj, string $fullname, bool $required=false, int|false $minimum=false, bool $minimumExclusive=false, bool $overrideStrictMode=false)
 Get the named number element from object.
 
static int null checkInteger (object $obj, string $fullname, bool $required=false, int|false $minimum=false, bool $minimumExclusive=false, bool $overrideStrictMode=false)
 Get the named integer element from object.
 
static bool null checkBoolean (object $obj, string $fullname, bool $required=false, ?bool $default=null)
 Get the named boolean element from object.
 
static int checkDateTime (object $obj, string $fullname, bool $required=false)
 Get the named number element from object.
 
static mixed jsonDecode (?string $str, bool $associative=false)
 Decode a JSON string.
 
static object cloneObject (object $obj)
 Clone an object and any objects it contains.
 

Public Attributes

const JWT_CLAIM_PREFIX = 'https://purl.imsglobal.org/spec/lti'
 Prefix for standard JWT message claims.
 
const MESSAGE_TYPE_MAPPING
 Mapping for standard message types.
 
const JWT_CLAIM_MAPPING
 Mapping for standard message parameters to JWT claim.
 
const TEST_COOKIE_NAME = 'celtic_lti_test_cookie'
 Name of test cookie.
 

Static Public Attributes

static array $METHOD_NAMES
 List of supported message types and associated class methods.
 
static array $requestParameters = null
 GET and POST request parameters.
 
static LogLevel $logLevel = LogLevel::None
 Current logging level.
 
static bool $strictMode = false
 Whether full compliance with the LTI specification is required.
 
static bool $disableFetchedPublicKeysSave = false
 Whether the automatic saving of fetched valid public keys should be disabled.
 
static int $formSubmissionTimeout = 2
 Delay (in seconds) before a manual button is displayed in case a browser is blocking a form submission.
 

Detailed Description

Class to implement utility methods.

Author
Stephen P Vickers steph.nosp@m.en@s.nosp@m.pvsof.nosp@m.twar.nosp@m.eprod.nosp@m.ucts.nosp@m..com
Licence: http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3

Member Function Documentation

◆ checkArray()

static array checkArray ( object $obj,
string $fullname,
bool $required = false,
bool $notEmpty = false )
static

Get the named array element from object.

Parameters
object$objObject containing the element
string$fullnameName of element
bool$requiredTrue if the element must be present
bool$notEmptyTrue if the element must not have an empty value
Returns
array Value of element (or empty string if not found)

Referenced by Groups\get().

◆ checkBoolean()

static bool null checkBoolean ( object $obj,
string $fullname,
bool $required = false,
?bool $default = null )
static

Get the named boolean element from object.

Parameters
object$objObject containing the element
string$fullnameName of element (may include a path)
bool$requiredTrue if the element must be present
string | null$defaultValue to return when a conversion is not possible (optional, default is an empty string)
Returns
bool|null Value of element (or null if not found or valid)

Referenced by Groups\get(), and FileItem\toJsonldObject().

◆ checkDateTime()

static int checkDateTime ( object $obj,
string $fullname,
bool $required = false )
static

Get the named number element from object.

Parameters
object$objObject containing the element
string$fullnameName of element (may include a path)
bool$requiredTrue if the element must be present
Returns
int Value of element (or 0 if not found or valid)

Referenced by LineItem\get().

◆ checkInteger()

static int null checkInteger ( object $obj,
string $fullname,
bool $required = false,
int|false $minimum = false,
bool $minimumExclusive = false,
bool $overrideStrictMode = false )
static

Get the named integer element from object.

Parameters
object$objObject containing the element
string$fullnameName of element (may include a path)
bool$requiredTrue if the element must be present
int | false$minimumMinimum value (or false is none)
bool$minimumExclusiveTrue if value must exceed the minimum
bool$overrideStrictModeIgnore strict mode setting
Returns
int|null Value of element (or null if not found or valid)

Referenced by Image\toJsonldObject().

◆ checkNumber()

static int float null checkNumber ( object $obj,
string $fullname,
bool $required = false,
int|false $minimum = false,
bool $minimumExclusive = false,
bool $overrideStrictMode = false )
static

Get the named number element from object.

Parameters
object$objObject containing the element
string$fullnameName of element (may include a path)
bool$requiredTrue if the element must be present
int | false$minimumMinimum value (or false is none)
bool$minimumExclusiveTrue if value must exceed the minimum
bool$overrideStrictModeIgnore strict mode setting
Returns
int|float|null Value of element (or null if not found or valid)

Referenced by LineItem\get().

◆ checkObject()

static object null checkObject ( object $obj,
string $fullname,
bool $required = false,
bool $stringValues = false )
static

Get the named object element from object.

Parameters
object$objObject containing the element
string$fullnameName of element
bool$requiredTrue if the element must be present
bool$stringValuesTrue if the values must be strings
Returns
object|null Value of element (or null if not found)

◆ checkString()

static string checkString ( object $obj,
string $fullname,
bool $required = false,
bool $notEmpty = false,
string|array $fixedValue = '',
bool $overrideStrictMode = false,
?string $default = '' )
static

Get the named string element from object.

Parameters
object$objObject containing the element
string$fullnameName of element (may include a path)
bool$requiredTrue if the element must be present
bool$notEmptyTrue if the element must not have an empty value
string$fixedValueRequired value of element (empty string if none)
bool$overrideStrictModeIgnore strict mode setting
string | null$defaultValue to return when a conversion is not possible (optional, default is an empty string)
Returns
string Value of element (or default value if not found or valid)

Referenced by Groups\get(), LineItem\get(), and Image\toJsonldObject().

◆ cloneObject()

static object cloneObject ( object $obj)
static

Clone an object and any objects it contains.

Parameters
object$objObject to be cloned
Returns
object

◆ getMessages()

static array getMessages ( bool $isError)
static

Get the system error or warning messages.

Parameters
bool$isErrorTrue if error messages are to be returned
Returns
array Array of messages

◆ getRandomString()

static string getRandomString ( int $length = 8)
static

Generate a random string.

The generated string will only comprise letters (upper- and lower-case) and digits.

Parameters
int$lengthLength of string to be generated (optional, default is 8 characters)
Returns
string Random string

◆ getRequestParameters()

static array getRequestParameters ( )
static

Return GET and POST request parameters (POST parameters take precedence).

Returns
array

◆ isLtiMessage()

static bool isLtiMessage ( )
static

Check whether the request received could be an LTI message.

Returns
bool

References Util\log(), and Util\logInfo().

◆ jsonDecode()

static mixed jsonDecode ( ?string $str,
bool $associative = false )
static

◆ log()

static void log ( string $message,
bool $showSource = false )
static

Log an error message irrespective of the logging level.

Parameters
string$messageMessage to be logged
bool$showSourceTrue if the name and line number of the current file are to be included

Referenced by Util\isLtiMessage().

◆ logDebug()

static void logDebug ( string $message,
bool $showSource = false )
static

Log a debug message.

Parameters
string$messageMessage to be logged
bool$showSourceTrue if the name and line number of the current file are to be included

Referenced by Util\logRequest().

◆ logError()

static void logError ( string $message,
bool $showSource = true )
static

Log an error message.

Parameters
string$messageMessage to be logged
bool$showSourceTrue if the name and line number of the current file are to be included

◆ logForm()

static void logForm ( string $url,
array $params,
string $method = 'POST',
bool $debugLevel = false )
static

Log a form submission.

Parameters
string$urlURL to which the form should be submitted
array$paramsArray of form parameters
string$methodHTTP Method used to submit form (optional, default is POST)
bool$debugLevelTrue if the form details should always be logged (optional, default is false to use current log level)

◆ logInfo()

static void logInfo ( string $message,
bool $showSource = false )
static

Log an information message.

Parameters
string$messageMessage to be logged
bool$showSourceTrue if the name and line number of the current file are to be included

Referenced by Util\isLtiMessage().

◆ logRequest()

static void logRequest ( bool $debugLevel = false)
static

Log a request received.

Parameters
bool$debugLevelTrue if the request details should be logged at the debug level (optional, default is false for information level)

References Util\logDebug().

◆ redirect()

static never redirect ( string $url,
array $params )
static

Redirect to a URL with query parameters.

Parameters
string$urlURL to which the form should be submitted
array$paramsArray of form parameters
Returns
never

◆ sendForm()

static string sendForm ( string $url,
array $params,
string $target = '',
string $javascript = '' )
static

Generate a web page containing an auto-submitted form of parameters.

Parameters
string$urlURL to which the form should be submitted
array$paramsArray of form parameters
string$targetName of target (optional)
string$javascriptJavascript to be inserted (optional, default is to just auto-submit form)
Returns
string

◆ setMessage()

static void setMessage ( bool $isError,
string $message )
static

Set an error or warning message.

Parameters
bool$isErrorTrue if the message represents an error
string$messageMessage

Referenced by Groups\get(), and ToolSettings\set().

◆ setTestCookie()

static void setTestCookie ( bool $delete = false)
static

Set or delete a test cookie.

Parameters
bool$deleteTrue if the cookie is to be deleted (optional, default is false)

◆ stripHtml()

static string stripHtml ( string $html)
static

Strip HTML tags from a string.

Parameters
string$htmlHTML string to be stripped
Returns
string

◆ urlEncode()

static string urlEncode ( ?string $val)
static

URL encode a value.

Parameters
string | null$valThe value to be encoded
Returns
string

◆ valToBoolean()

static bool valToBoolean ( mixed $val)
static

Convert a value to a boolean.

Parameters
mixed$valThe value to be converted
Returns
bool

◆ valToNumber()

static int float null valToNumber ( mixed $val)
static

Convert a value to a numeric.

Parameters
mixed$valThe value to be converted
Returns
int|float|null

◆ valToString()

static string valToString ( mixed $val,
?string $default = '' )
static

Convert a value to a string.

Parameters
mixed$valThe value to be converted
string | null$defaultValue to return when a conversion is not possible (optional, default is an empty string)
Returns
string

Referenced by ToolSettings\set(), and TimePeriod\toJsonldObject().

Member Data Documentation

◆ $METHOD_NAMES

array $METHOD_NAMES
static
Initial value:
= [
'basic-lti-launch-request' => 'onLaunch',
'ConfigureLaunchRequest' => 'onConfigure',
'DashboardRequest' => 'onDashboard',
'ContentItemSelectionRequest' => 'onContentItem',
'ContentItemSelection' => 'onContentItem',
'ContentItemUpdateRequest' => 'onContentItemUpdate',
'LtiSubmissionReviewRequest' => 'onSubmissionReview',
'ToolProxyRegistrationRequest' => 'onRegister',
'LtiStartProctoring' => 'onLtiStartProctoring',
'LtiStartAssessment' => 'onLtiStartAssessment',
'LtiEndAssessment' => 'onLtiEndAssessment'
]

List of supported message types and associated class methods.

◆ MESSAGE_TYPE_MAPPING

const MESSAGE_TYPE_MAPPING
Initial value:
= [
'basic-lti-launch-request' => 'LtiResourceLinkRequest',
'ContentItemSelectionRequest' => 'LtiDeepLinkingRequest',
'ContentItemSelection' => 'LtiDeepLinkingResponse',
'ContentItemUpdateRequest' => 'LtiDeepLinkingUpdateRequest'
]

Mapping for standard message types.

Referenced by System\hasJwt().