LTI Integration Library  3.1.0
PHP class library for building LTI integrations
ToolConsumer Class Reference

Class to represent a tool consumer. More...

Public Member Functions

 __construct ($key=null, $dataConnector=null, $autoEnable=false)
 Class constructor. More...
 
 initialize ()
 Initialise the tool consumer. More...
 
 initialise ()
 Initialise the tool consumer. More...
 
 save ()
 Save the tool consumer to the database. More...
 
 delete ()
 Delete the tool consumer from the database. More...
 
 getRecordId ()
 Get the tool consumer record ID. More...
 
 setRecordId ($id)
 Sets the tool consumer record ID. More...
 
 getKey ()
 Get the tool consumer key. More...
 
 setKey ($key)
 Set the tool consumer key. More...
 
 getFamilyCode ()
 Get tool consumer family code (as reported by last tool consumer connection). More...
 
 getDataConnector ()
 Get the data connector. More...
 
 getIsAvailable ()
 Is the consumer key available to accept launch requests? More...
 
 getSetting ($name, $default='')
 Get a setting value. More...
 
 setSetting ($name, $value=null)
 Set a setting value. More...
 
 getSettings ()
 Get an array of all setting values. More...
 
 setSettings ($settings)
 Set an array of all setting values. More...
 
 saveSettings ()
 Save setting values. More...
 
 hasToolSettingsService ()
 Check if the Tool Settings service is supported. More...
 
 getToolSettings ($simple=true)
 Get Tool Settings. More...
 
 setToolSettings ($settings=array())
 Perform a Tool Settings service request. More...
 
 signParameters ($url, $type, $version, $params)
 Add the signature to an LTI message. More...
 
 signServiceRequest ($url, $method, $type, $data=null)
 Generates the headers for an LTI service request. More...
 
 addSignature ($endpoint, $data, $method='POST', $type=null, $forTP=false)
 Add the signature to an array of message parameters or to a header string. More...
 
 doServiceRequest ($service, $method, $format, $data)
 Perform a service request. More...
 

Static Public Member Functions

static fromRecordId ($id, $dataConnector)
 Load the tool consumer from the database by its record ID. More...
 

Data Fields

 $name = null
 Local name of tool consumer. More...
 
 $secret = null
 Shared secret. More...
 
 $ltiVersion = null
 LTI version (as reported by last tool consumer connection). More...
 
 $signatureMethod = 'HMAC-SHA1'
 Method used for signing messages. More...
 
 $consumerName = null
 Name of tool consumer (as reported by last tool consumer connection). More...
 
 $consumerVersion = null
 Tool consumer version (as reported by last tool consumer connection). More...
 
 $profile = null
 The consumer profile data. More...
 
 $consumerGuid = null
 Tool consumer GUID (as reported by first tool consumer connection). More...
 
 $cssPath = null
 Optional CSS path (as reported by last tool consumer connection). More...
 
 $protected = false
 Whether the tool consumer instance is protected by matching the consumer_guid value in incoming requests. More...
 
 $enabled = false
 Whether the tool consumer instance is enabled to accept incoming connection requests. More...
 
 $enableFrom = null
 Timestamp from which the the tool consumer instance is enabled to accept incoming connection requests. More...
 
 $enableUntil = null
 Timestamp until which the tool consumer instance is enabled to accept incoming connection requests. More...
 
 $lastAccess = null
 Timestamp for date of last connection from this tool consumer. More...
 
 $idScope = ToolProvider::ID_SCOPE_ID_ONLY
 Default scope to use when generating an Id value for a user. More...
 
 $defaultEmail = ''
 Default email address (or email domain) to use when no email address is provided for a user. More...
 
 $lastServiceRequest = null
 HTTPMessage object for last service request. More...
 
 $created = null
 Timestamp for when the object was created. More...
 
 $updated = null
 Timestamp for when the object was last updated. More...
 

Detailed Description

Class to represent a tool consumer.

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

Definition at line 18 of file ToolConsumer.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $key = null,
  $dataConnector = null,
  $autoEnable = false 
)

Class constructor.

Parameters
string$keyConsumer key
DataConnector$dataConnectorA data connector object
bool$autoEnabletrue if the tool consumers is to be enabled automatically (optional, default is false)

Definition at line 196 of file ToolConsumer.php.

References DataConnector\getDataConnector(), DataConnector\getRandomString(), and ToolConsumer\initialize().

Member Function Documentation

◆ addSignature()

addSignature (   $endpoint,
  $data,
  $method = 'POST',
  $type = null,
  $forTP = false 
)

Add the signature to an array of message parameters or to a header string.

Parameters
string$endpointURL to which message is being sent
mixed$dataData to be passed
string$methodHTTP method
string | null$typeContent type of data being passed
bool$forTPTrue of the signature is being signed for a Tool Provider request
Returns
mixed Array of signed message parameters or header string

Definition at line 552 of file ToolConsumer.php.

Referenced by ToolConsumer\doServiceRequest(), ToolConsumer\signParameters(), and ToolConsumer\signServiceRequest().

◆ delete()

delete ( )

Delete the tool consumer from the database.

Returns
bool True if the object was successfully deleted

Definition at line 268 of file ToolConsumer.php.

◆ doServiceRequest()

doServiceRequest (   $service,
  $method,
  $format,
  $data 
)

Perform a service request.

Parameters
object$serviceService object to be executed
string$methodHTTP action
string$formatMedia type
mixed$dataArray of parameters or body string
Returns
HTTPMessage HTTP object containing request and response details

Definition at line 578 of file ToolConsumer.php.

References ToolConsumer\addSignature().

◆ fromRecordId()

static fromRecordId (   $id,
  $dataConnector 
)
static

Load the tool consumer from the database by its record ID.

Parameters
string$idThe consumer key record ID
DataConnector$dataConnectorDatabase connection object
Returns
ToolConsumer The tool consumer object

Definition at line 601 of file ToolConsumer.php.

Referenced by Context\getConsumer(), and ResourceLink\getConsumer().

◆ getDataConnector()

getDataConnector ( )

Get the data connector.

Returns
DataConnector|null Data connector object or string

Definition at line 333 of file ToolConsumer.php.

◆ getFamilyCode()

getFamilyCode ( )

Get tool consumer family code (as reported by last tool consumer connection).

Returns
string Family code

Definition at line 318 of file ToolConsumer.php.

Referenced by ToolConsumer\getToolSettings(), ToolConsumer\hasToolSettingsService(), and ToolConsumer\setToolSettings().

◆ getIsAvailable()

getIsAvailable ( )

Is the consumer key available to accept launch requests?

Returns
bool True if the consumer key is enabled and within any date constraints

Definition at line 343 of file ToolConsumer.php.

References ToolConsumer\$enabled.

◆ getKey()

getKey ( )

Get the tool consumer key.

Returns
string Consumer key value

Definition at line 298 of file ToolConsumer.php.

◆ getRecordId()

getRecordId ( )

Get the tool consumer record ID.

Returns
int|null Consumer record ID value

Definition at line 278 of file ToolConsumer.php.

◆ getSetting()

getSetting (   $name,
  $default = '' 
)

Get a setting value.

Parameters
string$nameName of setting
string$defaultValue to return if the setting does not exist (optional, default is an empty string)
Returns
string Setting value

Definition at line 366 of file ToolConsumer.php.

References ToolConsumer\$name.

Referenced by ToolConsumer\getToolSettings(), ToolConsumer\hasToolSettingsService(), ToolConsumer\setSetting(), and ToolConsumer\setToolSettings().

◆ getSettings()

getSettings ( )

Get an array of all setting values.

Returns
array Associative array of setting values

Definition at line 401 of file ToolConsumer.php.

◆ getToolSettings()

getToolSettings (   $simple = true)

Get Tool Settings.

Parameters
bool$simpleTrue if all the simple media type is to be used (optional, default is true)
Returns
mixed The array of settings if successful, otherwise false

Definition at line 453 of file ToolConsumer.php.

References ToolConsumer\getFamilyCode(), and ToolConsumer\getSetting().

◆ hasToolSettingsService()

hasToolSettingsService ( )

Check if the Tool Settings service is supported.

Returns
bool True if this tool consumer supports the Tool Settings service

Definition at line 437 of file ToolConsumer.php.

References ToolConsumer\getFamilyCode(), and ToolConsumer\getSetting().

◆ initialise()

initialise ( )

Initialise the tool consumer.

Pseudonym for initialize().

Definition at line 243 of file ToolConsumer.php.

References ToolConsumer\initialize().

◆ initialize()

initialize ( )

Initialise the tool consumer.

Definition at line 213 of file ToolConsumer.php.

References ToolProvider\ID_SCOPE_ID_ONLY.

Referenced by ToolConsumer\__construct(), and ToolConsumer\initialise().

◆ save()

save ( )

Save the tool consumer to the database.

Returns
bool True if the object was successfully saved

Definition at line 253 of file ToolConsumer.php.

Referenced by ToolConsumer\saveSettings().

◆ saveSettings()

saveSettings ( )

Save setting values.

Returns
bool True if the settings were successfully saved

Definition at line 421 of file ToolConsumer.php.

References ToolConsumer\save().

◆ setKey()

setKey (   $key)

Set the tool consumer key.

Parameters
string$keyConsumer key value

Definition at line 308 of file ToolConsumer.php.

◆ setRecordId()

setRecordId (   $id)

Sets the tool consumer record ID.

Parameters
int$idConsumer record ID value

Definition at line 288 of file ToolConsumer.php.

◆ setSetting()

setSetting (   $name,
  $value = null 
)

Set a setting value.

Parameters
string$nameName of setting
string$valueValue to set, use an empty value to delete a setting (optional, default is null)

Definition at line 383 of file ToolConsumer.php.

References ToolConsumer\$name, and ToolConsumer\getSetting().

◆ setSettings()

setSettings (   $settings)

Set an array of all setting values.

Parameters
array$settingsAssociative array of setting values

Definition at line 411 of file ToolConsumer.php.

◆ setToolSettings()

setToolSettings (   $settings = array())

Perform a Tool Settings service request.

Parameters
array$settingsAn associative array of settings (optional, default is none)
Returns
bool True if action was successful, otherwise false

Definition at line 480 of file ToolConsumer.php.

References ToolConsumer\getFamilyCode(), and ToolConsumer\getSetting().

◆ signParameters()

signParameters (   $url,
  $type,
  $version,
  $params 
)

Add the signature to an LTI message.

Parameters
string$urlURL for message request
string$typeLTI message type
string$versionLTI version
array$paramsMessage parameters
Returns
array Array of signed message parameters

Definition at line 508 of file ToolConsumer.php.

References ToolConsumer\addSignature().

◆ signServiceRequest()

signServiceRequest (   $url,
  $method,
  $type,
  $data = null 
)

Generates the headers for an LTI service request.

Parameters
string$urlURL for message request
string$methodHTTP method
string$typeMedia type
string$dataData being passed in request body (optional)
Returns
string Headers to include with service request

Definition at line 531 of file ToolConsumer.php.

References ToolConsumer\addSignature().

Field Documentation

◆ $consumerGuid

string null $consumerGuid = null

Tool consumer GUID (as reported by first tool consumer connection).

Definition at line 75 of file ToolConsumer.php.

◆ $consumerName

string null $consumerName = null

Name of tool consumer (as reported by last tool consumer connection).

Definition at line 54 of file ToolConsumer.php.

◆ $consumerVersion

string null $consumerVersion = null

Tool consumer version (as reported by last tool consumer connection).

Definition at line 61 of file ToolConsumer.php.

◆ $created

int null $created = null

Timestamp for when the object was created.

Definition at line 145 of file ToolConsumer.php.

◆ $cssPath

string null $cssPath = null

Optional CSS path (as reported by last tool consumer connection).

Definition at line 82 of file ToolConsumer.php.

◆ $defaultEmail

string $defaultEmail = ''

Default email address (or email domain) to use when no email address is provided for a user.

Definition at line 131 of file ToolConsumer.php.

◆ $enabled

bool $enabled = false

Whether the tool consumer instance is enabled to accept incoming connection requests.

Definition at line 96 of file ToolConsumer.php.

Referenced by ToolConsumer\getIsAvailable().

◆ $enableFrom

int null $enableFrom = null

Timestamp from which the the tool consumer instance is enabled to accept incoming connection requests.

Definition at line 103 of file ToolConsumer.php.

◆ $enableUntil

int null $enableUntil = null

Timestamp until which the tool consumer instance is enabled to accept incoming connection requests.

Definition at line 110 of file ToolConsumer.php.

◆ $idScope

Default scope to use when generating an Id value for a user.

Definition at line 124 of file ToolConsumer.php.

◆ $lastAccess

int null $lastAccess = null

Timestamp for date of last connection from this tool consumer.

Definition at line 117 of file ToolConsumer.php.

◆ $lastServiceRequest

HTTPMessage null $lastServiceRequest = null

HTTPMessage object for last service request.

Definition at line 138 of file ToolConsumer.php.

◆ $ltiVersion

string null $ltiVersion = null

LTI version (as reported by last tool consumer connection).

Definition at line 40 of file ToolConsumer.php.

◆ $name

string null $name = null

Local name of tool consumer.

Definition at line 26 of file ToolConsumer.php.

Referenced by ToolConsumer\getSetting(), and ToolConsumer\setSetting().

◆ $profile

object null $profile = null

The consumer profile data.

Definition at line 68 of file ToolConsumer.php.

◆ $protected

bool $protected = false

Whether the tool consumer instance is protected by matching the consumer_guid value in incoming requests.

Definition at line 89 of file ToolConsumer.php.

◆ $secret

string null $secret = null

Shared secret.

Definition at line 33 of file ToolConsumer.php.

◆ $signatureMethod

string $signatureMethod = 'HMAC-SHA1'

Method used for signing messages.

Definition at line 47 of file ToolConsumer.php.

◆ $updated

int null $updated = null

Timestamp for when the object was last updated.

Definition at line 152 of file ToolConsumer.php.


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