LTI Integration Library 4.10.3
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 isLtiMessage ()
 Check whether the request received could be an LTI message.
 
static getRequestParameters ()
 Return GET and POST request parameters (POST parameters take precedence).
 
static logError ($message, $showSource=true)
 Log an error message.
 
static logInfo ($message, $showSource=false)
 Log an information message.
 
static logDebug ($message, $showSource=false)
 Log a debug message.
 
static logRequest ($debugLevel=false)
 Log a request received.
 
static logForm ($url, $params, $method='POST', $debugLevel=false)
 Log a form submission.
 
static log ($message, $showSource=false)
 Log an error message irrespective of the logging level.
 
static sendForm ($url, $params, $target='', $javascript='')
 Generate a web page containing an auto-submitted form of parameters.
 
static redirect ($url, $params)
 Redirect to a URL with query parameters.
 
static setTestCookie ($delete=false)
 Set or delete a test cookie.
 
static getRandomString ($length=8)
 Generate a random string.
 
static stripHtml ($html)
 Strip HTML tags from a string.
 
static jsonDecode ($str, $associative=false)
 Decode a JSON string.
 
static cloneObject ($obj)
 Clone an object and any objects it contains.
 

Data Fields

const LTI_VERSION1 = 'LTI-1p0'
 LTI version 1 for messages.
 
const LTI_VERSION1P3 = '1.3.0'
 LTI version 1.3 for messages.
 
const LTI_VERSION2 = 'LTI-2p0'
 LTI version 2 for messages.
 
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 LOGLEVEL_NONE = 0
 No logging.
 
const LOGLEVEL_ERROR = 1
 Log errors only.
 
const LOGLEVEL_INFO = 2
 Log error and information messages.
 
const LOGLEVEL_DEBUG = 3
 Log all messages.
 
const TEST_COOKIE_NAME = 'celtic_lti_test_cookie'
 Name of test cookie.
 

Static Public Attributes

static $LTI_VERSIONS = array(self::LTI_VERSION1, self::LTI_VERSION1P3, self::LTI_VERSION2)
 Permitted LTI versions for messages.
 
static $METHOD_NAMES
 List of supported message types and associated class methods.
 
static $requestParameters = null
 GET and POST request parameters.
 
static $logLevel = self::LOGLEVEL_NONE
 Current logging level.
 
static $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

Definition at line 14 of file Util.php.

Member Function Documentation

◆ cloneObject()

static cloneObject (   $obj)
static

Clone an object and any objects it contains.

Parameters
object$objObject to be cloned
Returns
object

Definition at line 578 of file Util.php.

References Util\cloneObject().

Referenced by Util\cloneObject().

◆ getRandomString()

static getRandomString (   $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

Definition at line 523 of file Util.php.

Referenced by Tool\doToolProxyService(), DataConnector\getRandomString(), and ResourceLinkShareKey\save().

◆ getRequestParameters()

static getRequestParameters ( )
static

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

Returns
array

Definition at line 233 of file Util.php.

References Util\$requestParameters.

Referenced by Tool\getPlatformConfiguration(), Tool\handleRequest(), Platform\handleRequest(), and Tool\sendRegistration().

◆ isLtiMessage()

static isLtiMessage ( )
static

Check whether the request received could be an LTI message.

Returns
bool

Definition at line 216 of file Util.php.

◆ jsonDecode()

static jsonDecode (   $str,
  $associative = false 
)
static

Decode a JSON string.

Parameters
string | null$strThe JSON string to be decoded
bool$associativeTrue to return JSON objects as associative arrays
Returns
mixed

Definition at line 560 of file Util.php.

Referenced by System\doServiceRequest(), ToolSettings\get(), AccessToken\get(), System\getMessageClaims(), Tool\getPlatformConfiguration(), DataConnector_mysql\getPlatforms(), DataConnector_mysqli\getPlatforms(), DataConnector_oci\getPlatforms(), DataConnector_pdo\getPlatforms(), DataConnector_pg\getPlatforms(), DataConnector_sqlsrv\getPlatforms(), DataConnector_mysql\getTools(), DataConnector_mysqli\getTools(), DataConnector_oci\getTools(), DataConnector_pdo\getTools(), DataConnector_pg\getTools(), DataConnector_sqlsrv\getTools(), FirebaseClient\load(), SpomkyLabsClient\load(), WebTokenClient\load(), DataConnector_mysql\loadAccessToken(), DataConnector_mysqli\loadAccessToken(), DataConnector_oci\loadAccessToken(), DataConnector_pdo\loadAccessToken(), DataConnector_pg\loadAccessToken(), DataConnector_sqlsrv\loadAccessToken(), DataConnector_mysql\loadContext(), DataConnector_mysqli\loadContext(), DataConnector_oci\loadContext(), DataConnector_pdo\loadContext(), DataConnector_pg\loadContext(), DataConnector_sqlsrv\loadContext(), DataConnector_mysql\loadPlatform(), DataConnector_mysqli\loadPlatform(), DataConnector_oci\loadPlatform(), DataConnector_pdo\loadPlatform(), DataConnector_pg\loadPlatform(), DataConnector_sqlsrv\loadPlatform(), DataConnector_mysql\loadResourceLink(), DataConnector_mysqli\loadResourceLink(), DataConnector_oci\loadResourceLink(), DataConnector_pdo\loadResourceLink(), DataConnector_pg\loadResourceLink(), DataConnector_sqlsrv\loadResourceLink(), DataConnector_mysql\loadTool(), DataConnector_mysqli\loadTool(), DataConnector_oci\loadTool(), DataConnector_pdo\loadTool(), DataConnector_pg\loadTool(), DataConnector_sqlsrv\loadTool(), Service\send(), and Tool\sendRegistration().

◆ log()

static log (   $message,
  $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

Definition at line 348 of file Util.php.

Referenced by Util\logDebug(), Util\logError(), and Util\logInfo().

◆ logDebug()

static logDebug (   $message,
  $showSource = false 
)
static

◆ logError()

static logError (   $message,
  $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

Definition at line 248 of file Util.php.

References Util\log().

Referenced by DataConnector_pdo\executeQuery(), Tool\handleRequest(), Platform\handleRequest(), HttpMessage\send(), and DataConnector\useMemcache().

◆ logForm()

static logForm (   $url,
  $params,
  $method = 'POST',
  $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)

Definition at line 320 of file Util.php.

References Util\$logLevel, Util\logDebug(), Util\logInfo(), and Util\LOGLEVEL_DEBUG.

Referenced by Util\sendForm().

◆ logInfo()

static logInfo (   $message,
  $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

Definition at line 261 of file Util.php.

References Util\log().

Referenced by Util\logForm(), Util\logRequest(), and HttpMessage\send().

◆ logRequest()

static logRequest (   $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)

Definition at line 286 of file Util.php.

References Util\$logLevel, OAuthRequest\$POST_INPUT, Util\logDebug(), Util\logInfo(), Util\LOGLEVEL_DEBUG, and Util\LOGLEVEL_INFO.

Referenced by Tool\handleRequest(), and Platform\handleRequest().

◆ redirect()

static redirect (   $url,
  $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

Definition at line 454 of file Util.php.

◆ sendForm()

static sendForm (   $url,
  $params,
  $target = '',
  $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

Definition at line 378 of file Util.php.

References Util\logForm().

Referenced by Tool\onAuthenticate(), Tool\sendForm(), and System\sendMessage().

◆ setTestCookie()

static setTestCookie (   $delete = false)
static

Set or delete a test cookie.

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

Definition at line 488 of file Util.php.

◆ stripHtml()

static stripHtml (   $html)
static

Strip HTML tags from a string.

Parameters
string$htmlHTML string to be stripped
Returns
string

Definition at line 544 of file Util.php.

Field Documentation

◆ $formSubmissionTimeout

int $formSubmissionTimeout = 2
static

Delay (in seconds) before a manual button is displayed in case a browser is blocking a form submission.

Definition at line 209 of file Util.php.

◆ $logLevel

◆ $LTI_VERSIONS

$LTI_VERSIONS = array(self::LTI_VERSION1, self::LTI_VERSION1P3, self::LTI_VERSION2)
static

Permitted LTI versions for messages.

Definition at line 169 of file Util.php.

Referenced by System\checkMessage().

◆ $METHOD_NAMES

array $METHOD_NAMES
static
Initial value:
= array(
'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.

Definition at line 176 of file Util.php.

◆ $requestParameters

array null $requestParameters = null
static

GET and POST request parameters.

Definition at line 195 of file Util.php.

Referenced by Util\getRequestParameters().

◆ JWT_CLAIM_MAPPING

const JWT_CLAIM_MAPPING

Mapping for standard message parameters to JWT claim.

Definition at line 50 of file Util.php.

Referenced by System\getMessageClaims().

◆ JWT_CLAIM_PREFIX

const JWT_CLAIM_PREFIX = 'https://purl.imsglobal.org/spec/lti'

Prefix for standard JWT message claims.

Definition at line 35 of file Util.php.

Referenced by System\getMessageClaims().

◆ LOGLEVEL_DEBUG

◆ LOGLEVEL_ERROR

const LOGLEVEL_ERROR = 1

Log errors only.

Definition at line 149 of file Util.php.

Referenced by DataConnector_pdo\executeQuery().

◆ LOGLEVEL_INFO

const LOGLEVEL_INFO = 2

Log error and information messages.

Definition at line 154 of file Util.php.

Referenced by Util\logRequest().

◆ LOGLEVEL_NONE

const LOGLEVEL_NONE = 0

No logging.

Definition at line 144 of file Util.php.

Referenced by HttpMessage\send().

◆ LTI_VERSION1

const LTI_VERSION1 = 'LTI-1p0'

LTI version 1 for messages.

Definition at line 20 of file Util.php.

Referenced by System\parseRoles().

◆ LTI_VERSION1P3

const LTI_VERSION1P3 = '1.3.0'

LTI version 1.3 for messages.

Definition at line 25 of file Util.php.

Referenced by Tool\getPlatformToRegister(), System\parseRoles(), System\signMessage(), and Item\toJson().

◆ LTI_VERSION2

const LTI_VERSION2 = 'LTI-2p0'

LTI version 2 for messages.

Definition at line 30 of file Util.php.

Referenced by System\parseRoles().

◆ MESSAGE_TYPE_MAPPING

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

Mapping for standard message types.

Definition at line 40 of file Util.php.

Referenced by Tool\getConfiguration(), and System\getMessageClaims().

◆ TEST_COOKIE_NAME

const TEST_COOKIE_NAME = 'celtic_lti_test_cookie'

Name of test cookie.

Definition at line 164 of file Util.php.


The documentation for this class was generated from the following file: