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

Class to represent an LTI Tool. More...

+ Inheritance diagram for Tool:

Public Member Functions

 __construct (?DataConnector $dataConnector=null)
 Class constructor.
 
void initialize ()
 Initialise the tool.
 
bool save ()
 Save the tool to the database.
 
bool delete ()
 Delete the tool from the database.
 
array null getMessageParameters (?bool $strictMode=null, bool $disableCookieCheck=false, bool $generateWarnings=false)
 Get the message parameters.
 
 handleRequest (bool $strictMode=null, bool $disableCookieCheck=false, bool $generateWarnings=false)
 Process an incoming request.
 
 setParameterConstraint (string $name, bool $required=true, ?int $maxLength=null, ?array $messageTypes=null)
 Add a parameter constraint to be checked on launch.
 
array getPlatforms ()
 Get an array of defined platforms.
 
ServiceDefinition bool findService (string $format, array $methods)
 Find an offered service based on a media type and HTTP action(s)
 
bool doToolProxyService ()
 Send the tool proxy to the platform.
 
- Public Member Functions inherited from System
int string null getRecordId ()
 Get the system record ID.
 
void setRecordId (int|string|null $id)
 Sets the system record ID.
 
string null getKey ()
 Get the consumer key.
 
void setKey (?string $key)
 Set the consumer key.
 
string null getSetting (string $name, ?string $default='')
 Get a setting value.
 
void setSetting (string $name, string|array|null $value=null)
 Set a setting value.
 
array getSettings ()
 Get an array of all setting values.
 
void setSettings (array $settings)
 Set an array of all setting values.
 
bool saveSettings ()
 Save setting values.
 
bool hasJwt ()
 Check whether a JWT exists.
 
ClientInterface getJwt ()
 Get the JWT.
 
array getRawParameters ()
 Get the raw POST parameters.
 
array getMessageClaims (bool $fullyQualified=false)
 Get the message claims.
 
array string signParameters (string $url, string $type, string $ltiVersionString, array $params)
 Add the signature to an LTI message.
 
array string signMessage (string &$url, string $type, string $ltiVersionString, array $params, ?string $loginHint=null, ?string $ltiMessageHint=null)
 Add the signature to an LTI message.
 
string sendMessage (string $url, string $type, array $messageParams, string $target='', ?string $userId=null, ?string $hint=null)
 Generate a web page containing an auto-submitted form of LTI message parameters.
 
array string signServiceRequest (string $url, string $method, string $type, array|string|null $data=null)
 Generates the headers for an LTI service request.
 
HttpMessage doServiceRequest (ServiceDefinition $service, string $method, string $format, array|string $data)
 Perform a service request.
 
bool useOAuth1 ()
 Determine whether this consumer is using the OAuth 1 security model.
 
array string addSignature (string $endpoint, array|string|null $data, string $method='POST', ?string $type=null, ?string $nonce='', ?string $hash=null, ?int $timestamp=null)
 Add the signature to an array of message parameters or to a header string.
 
string null getBaseString ()
 Get the last signature base string.
 
bool checkMessage (bool $generateWarnings=false)
 Verify the required properties of an LTI message.
 
bool verifySignature ()
 Verify the signature of a message.
 
bool setReason (string $reason)
 Set the error reason.
 

Static Public Member Functions

static Tool fromConsumerKey (?string $key=null, DataConnector $dataConnector=null, bool $autoEnable=false)
 Load the tool from the database by its consumer key.
 
static Tool fromInitiateLoginUrl (string $initiateLoginUrl, DataConnector $dataConnector=null, bool $autoEnable=false)
 Load the tool from the database by its initiate login URL.
 
static Tool fromRecordId (int $id, DataConnector $dataConnector)
 Load the tool from the database by its record ID.
 
- Static Public Member Functions inherited from System
static array parseRoles (array|string $roles, LtiVersion $ltiVersion=LtiVersion::V1, bool $addPrincipalRole=false)
 Parse a set of roles to comply with a specified version of LTI.
 
- Static Public Member Functions inherited from ApiHook
static void registerApiHook (string $hookName, string $familyCode, string $className)
 Register the availability of an API hook.
 

Public Attributes

const CONNECTION_ERROR_MESSAGE = 'Sorry, there was an error connecting you to the application.'
 Default connection error message.
 
Platform $platform = null
 Platform object.
 
string $returnUrl = null
 Return URL provided by platform.
 
UserResult $userResult = null
 UserResult object.
 
ResourceLink $resourceLink = null
 Resource link object.
 
Context $context = null
 Context object.
 
string $defaultEmail = ''
 Default email domain.
 
bool $allowSharing = false
 Whether shared resource link arrangements are permitted.
 
string $message = null
 Message for last request processed.
 
string $baseUrl = null
 Base URL for tool service.
 
Profile Item $vendor = null
 Vendor details.
 
Profile Item $product = null
 Product details.
 
array $requiredServices = null
 Services required by Tool.
 
array $optionalServices = null
 Optional services used by Tool.
 
array $resourceHandlers = null
 Resource handlers for Tool.
 
string $messageUrl = null
 Message URL for Tool.
 
string $initiateLoginUrl = null
 Initiate Login request URL for Tool.
 
array $redirectionUris = null
 Redirection URIs for Tool.
 
- Public Attributes inherited from System
bool $ok = true
 True if the last request was successful.
 
LtiVersion $ltiVersion = null
 LTI version.
 
string $name = null
 Local name of platform/tool.
 
string $secret = null
 Shared secret.
 
string $signatureMethod = 'HMAC-SHA1'
 Method used for signing messages.
 
string $encryptionMethod = ''
 Algorithm used for encrypting messages.
 
DataConnector $dataConnector = null
 Data connector object.
 
string $rsaKey = null
 RSA key in PEM or JSON format.
 
array $requiredScopes = []
 Scopes to request when obtaining an access token.
 
string $kid = null
 Key ID.
 
string $jku = null
 Endpoint for public key.
 
string $reason = null
 Error message for last request processed.
 
array $details = []
 Details for error message relating to last request processed.
 
array $warnings = []
 Warnings relating to last request processed.
 
bool $debugMode = false
 Whether debug level messages are to be reported.
 
bool $enabled = false
 Whether the system instance is enabled to accept connection requests.
 
int $enableFrom = null
 Timestamp from which the the system instance is enabled to accept connection requests.
 
int $enableUntil = null
 Timestamp until which the system instance is enabled to accept connection requests.
 
int $lastAccess = null
 Timestamp for date of last connection to this system.
 
int $created = null
 Timestamp for when the object was created.
 
int $updated = null
 Timestamp for when the object was last updated.
 
IdScope $idScope = IdScope::IdOnly
 Default scope to use when generating an Id value for a user.
 

Static Public Attributes

static array $MESSAGE_TYPES
 List of supported incoming message types.
 
static Tool $defaultTool = null
 Default tool for use with service requests.
 
static bool $authenticateUsingGet = false
 Use GET method for authentication request messages when true.
 
static int $stateLife = 10
 Life in seconds for the state value issued during the OIDC login process.
 
static int $postMessageTimeoutDelay = 20
 Period in milliseconds to wait for a response to a postMessage.
 
- Static Public Attributes inherited from ApiHook
static string $USER_ID_HOOK = "UserId"
 User Id hook name.
 
static string $CONTEXT_ID_HOOK = "ContextId"
 Context Id hook name.
 
static string $GROUPS_SERVICE_HOOK = "Groups"
 Course Groups service hook name.
 
static string $MEMBERSHIPS_SERVICE_HOOK = "Memberships"
 Memberships service hook name.
 
static string $OUTCOMES_SERVICE_HOOK = "Outcomes"
 Outcomes service hook name.
 
static string $TOOL_SETTINGS_SERVICE_HOOK = "ToolSettings"
 Tool Settings service hook name.
 
static string $ACCESS_TOKEN_SERVICE_HOOK = "AccessToken"
 Access Token service hook name.
 

Protected Member Functions

void onLaunch ()
 Process a valid launch request.
 
void onConfigure ()
 Process a valid configure request.
 
void onDashboard ()
 Process a valid dashboard request.
 
void onContentItem ()
 Process a valid content-item request.
 
void onContentItemUpdate ()
 Process a valid content-item update request.
 
void onSubmissionReview ()
 Process a valid submission review request.
 
void onRegistration ()
 Process a dynamic registration request.
 
 onLtiStartProctoring ()
 Process a valid start proctoring request.
 
void onLtiEndAssessment ()
 Process a valid end assessment request.
 
void onInitiateLogin (array $requestParameters, array &$authParameters)
 Process a login initiation request.
 
void onAuthenticate (string $state, string $nonce, bool $usePlatformStorage)
 Process response to an authentication request.
 
void onResetSessionId ()
 Process a change in the session ID.
 
void onError ()
 Process a response to an invalid request.
 
array null getPlatformConfiguration ()
 Fetch a platform's configuration data.
 
array getConfiguration (array $platformConfig)
 Prepare the tool's configuration data.
 
array null sendRegistration (array $platformConfig, array $toolConfig)
 Send the tool registration to the platform.
 
Platform getPlatformToRegister (array $platformConfig, array $registrationConfig, bool $doSave=true)
 Initialise the platform to be registered.
 
void getRegistrationResponsePage (array $toolConfig)
 Prepare the page to complete a registration request.
 

Protected Attributes

string $redirectUrl = null
 URL to redirect user to on successful completion of the request.
 
array $mediaTypes = null
 Media types accepted by the platform.
 
array $contentTypes = null
 Content item types accepted by the platform.
 
array $fileTypes = null
 File types accepted by the platform.
 
array $documentTargets = null
 Document targets accepted by the platform.
 
string $output = null
 Default HTML to be displayed on a successful completion of the request.
 
string $errorOutput = null
 HTML to be displayed on an unsuccessful completion of the request and no return URL is available.
 
- Protected Attributes inherited from System
ClientInterface $jwt = null
 JWT ClientInterface object.
 
array $rawParameters = null
 Raw message parameters.
 
array $messageParameters = null
 LTI message parameters.
 

Detailed Description

Class to represent an LTI Tool.

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

Constructor & Destructor Documentation

◆ __construct()

__construct ( ?DataConnector $dataConnector = null)

Class constructor.

Parameters
DataConnector$dataConnectorObject containing a database connection object

Member Function Documentation

◆ delete()

bool delete ( )

Delete the tool from the database.

Returns
bool True if the object was successfully deleted

◆ doToolProxyService()

bool doToolProxyService ( )

Send the tool proxy to the platform.

Returns
bool True if the tool proxy was accepted

◆ findService()

ServiceDefinition bool findService ( string $format,
array $methods )

Find an offered service based on a media type and HTTP action(s)

Parameters
string$formatMedia type required
array$methodsArray of HTTP actions required
Returns
ServiceDefinition|bool The service object if found, otherwise false

◆ fromConsumerKey()

static Tool fromConsumerKey ( ?string $key = null,
DataConnector $dataConnector = null,
bool $autoEnable = false )
static

Load the tool from the database by its consumer key.

Parameters
string | null$keyConsumer key
DataConnector$dataConnectorA data connector object
bool$autoEnableTrue if the tool is to be enabled automatically (optional, default is false)
Returns
Tool The tool object

◆ fromInitiateLoginUrl()

static Tool fromInitiateLoginUrl ( string $initiateLoginUrl,
DataConnector $dataConnector = null,
bool $autoEnable = false )
static

Load the tool from the database by its initiate login URL.

Parameters
string$initiateLoginUrlThe initiate login URL
DataConnector$dataConnectorA data connector object
bool$autoEnableTrue if the tool is to be enabled automatically (optional, default is false)
Returns
Tool The tool object

◆ fromRecordId()

static Tool fromRecordId ( int $id,
DataConnector $dataConnector )
static

Load the tool from the database by its record ID.

Parameters
int$idThe tool record ID
DataConnector$dataConnectorA data connector object
Returns
Tool The tool object

◆ getConfiguration()

array getConfiguration ( array $platformConfig)
protected

Prepare the tool's configuration data.

Parameters
array$platformConfigPlatform configuration data
Returns
array Tool configuration data

◆ getMessageParameters()

array null getMessageParameters ( ?bool $strictMode = null,
bool $disableCookieCheck = false,
bool $generateWarnings = false )

Get the message parameters.

Parameters
bool | null$strictModeTrue if full compliance with the LTI specification is required (optional, default is the Util::$strictMode setting)
bool$disableCookieCheckTrue if no cookie check should be made (optional, default is false)
bool$generateWarningsTrue if warning messages should be generated (optional, default is false)
Returns
array|null The message parameter array

◆ getPlatformConfiguration()

array null getPlatformConfiguration ( )
protected

Fetch a platform's configuration data.

Returns
array|null Platform configuration data

◆ getPlatforms()

array getPlatforms ( )

Get an array of defined platforms.

Returns
array Array of Platform objects

◆ getPlatformToRegister()

Platform getPlatformToRegister ( array $platformConfig,
array $registrationConfig,
bool $doSave = true )
protected

Initialise the platform to be registered.

Parameters
array$platformConfigPlatform configuration data
array$registrationConfigRegistration data
bool$doSaveTrue if the platform should be saved (optional, default is true)
Returns
Platform Platform object

◆ getRegistrationResponsePage()

void getRegistrationResponsePage ( array $toolConfig)
protected

Prepare the page to complete a registration request.

Parameters
array$toolConfigTool configuration data

◆ handleRequest()

handleRequest ( bool $strictMode = null,
bool $disableCookieCheck = false,
bool $generateWarnings = false )

Process an incoming request.

Parameters
bool | null$strictModeTrue if full compliance with the LTI specification is required (optional, default is the Util::$strictMode setting)
bool$disableCookieCheckTrue if no cookie check should be made (optional, default is false)
bool$generateWarningsTrue if warning messages should be generated (optional, default is false)

◆ onAuthenticate()

void onAuthenticate ( string $state,
string $nonce,
bool $usePlatformStorage )
protected

Process response to an authentication request.

Parameters
string$stateState value
string$nonceNonce value
bool$usePlatformStorageTrue if platform storage is being used

◆ onInitiateLogin()

void onInitiateLogin ( array $requestParameters,
array & $authParameters )
protected

Process a login initiation request.

Parameters
array$requestParametersRequest parameters
array$authParametersAuthentication request parameters

◆ save()

bool save ( )

Save the tool to the database.

Returns
bool True if the object was successfully saved

References Util\$logLevel.

◆ sendRegistration()

array null sendRegistration ( array $platformConfig,
array $toolConfig )
protected

Send the tool registration to the platform.

Parameters
array$platformConfigPlatform configuration data
array$toolConfigTool configuration data
Returns
array|null Registration data

◆ setParameterConstraint()

setParameterConstraint ( string $name,
bool $required = true,
?int $maxLength = null,
?array $messageTypes = null )

Add a parameter constraint to be checked on launch.

Parameters
string$nameName of parameter to be checked
bool$requiredTrue if parameter is required (optional, default is true)
int | null$maxLengthMaximum permitted length of parameter value (optional, default is null)
array | null$messageTypesArray of message types to which the constraint applies (optional, default is all)

Member Data Documentation

◆ $MESSAGE_TYPES

array $MESSAGE_TYPES
static
Initial value:
= [
'basic-lti-launch-request',
'ConfigureLaunchRequest',
'DashboardRequest',
'ContentItemSelectionRequest',
'ContentItemUpdateRequest',
'LtiSubmissionReviewRequest',
'ToolProxyRegistrationRequest',
'LtiStartProctoring',
'LtiEndAssessment'
]

List of supported incoming message types.