109 private static $memcache =
null;
133 if (is_null($host)) {
134 $useMemcache = !empty(self::$memcache);
136 $useMemcache = !empty($host);
138 if (!class_exists(
'Memcache')) {
139 $useMemcache =
false;
143 self::$memcache = memcache_connect($host);
145 self::$memcache = memcache_connect($host, $port);
147 $useMemcache = !empty(self::$memcache);
152 Util::logError(
"Unable to connect to memcache at {$host}:{$port}");
158 self::$memcache =
null;
181 Util::logDebug(
'Method ceLTIc\LTI\DataConnector\DataConnector::loadToolConsumer() has been deprecated; please use ceLTIc\LTI\DataConnector\DataConnector::loadPlatform() instead.',
198 Util::logDebug(
'Method ceLTIc\LTI\DataConnector\DataConnector::saveToolConsumer() has been deprecated; please use ceLTIc\LTI\DataConnector\DataConnector::savePlatform() instead.',
215 Util::logDebug(
'Method ceLTIc\LTI\DataConnector\DataConnector::deleteToolConsumer() has been deprecated; please use ceLTIc\LTI\DataConnector\DataConnector::deletePlatform() instead.',
230 Util::logDebug(
'Method ceLTIc\LTI\DataConnector\DataConnector::getToolConsumers() has been deprecated; please use ceLTIc\LTI\DataConnector\DataConnector::getPlatforms() instead.',
244 $platform->secret =
'secret';
245 $platform->enabled =
true;
247 $platform->created = $now;
248 $platform->updated = $now;
262 $platform->updated = time();
276 $platform->initialize();
305 $context->created = $now;
306 $context->updated = $now;
320 $context->updated = time();
334 $context->initialize();
340### ResourceLink methods
353 $resourceLink->created = $now;
354 $resourceLink->updated = $now;
368 $resourceLink->updated = time();
382 $resourceLink->initialize();
417### PlatformNonce methods
432 Util::logDebug(
'Method ceLTIc\LTI\DataConnector\DataConnector::loadConsumerNonce() has been deprecated; please use ceLTIc\LTI\DataConnector\DataConnector::loadPlatformNonce() instead.',
449 Util::logDebug(
'Method ceLTIc\LTI\DataConnector\DataConnector::saveConsumerNonce() has been deprecated; please use ceLTIc\LTI\DataConnector\DataConnector::savePlatformNonce() instead.',
466 Util::logDebug(
'Method ceLTIc\LTI\DataConnector\DataConnector::deleteConsumerNonce() has been deprecated; please use ceLTIc\LTI\DataConnector\DataConnector::deletePlatformNonce() instead.',
481 if (!empty(self::$memcache)) {
482 $id = $nonce->getPlatform()->getRecordId();
483 $value = $nonce->getValue();
484 $name = self::NONCE_TABLE_NAME .
"_{$id}_{$value}";
485 $ok = self::$memcache->get($name) !==
false;
501 if (!empty(self::$memcache)) {
503 $id = $nonce->getPlatform()->getRecordId();
504 $value = $nonce->getValue();
505 $expires = $nonce->expires;
506 $name = self::NONCE_TABLE_NAME .
"_{$id}_{$value}";
507 $current = self::$memcache->get($name);
508 if ($current ===
false) {
509 $ok = self::$memcache->set($name,
true, 0, $expires);
526 if (!empty(self::$memcache)) {
527 $id = $nonce->getPlatform()->getRecordId();
528 $value = $nonce->getValue();
529 $name = self::NONCE_TABLE_NAME .
"_{$id}_{$value}";
530 $ok = self::$memcache->get($name);
532 $ok = self::$memcache->delete($name);
540### AccessToken methods
553 if (!empty(self::$memcache)) {
554 $id = $accessToken->getPlatform()->getRecordId();
555 $value = $accessToken->token;
556 $name = self::ACCESS_TOKEN_TABLE_NAME .
"_{$id}_{$value}";
557 $current = self::$memcache->get($name);
558 $ok = is_array($current);
560 $accessToken->scopes = $current[
'scopes'];
561 $accessToken->token = $current[
'token'];
562 $accessToken->expires = $current[
'expires'];
563 $accessToken->created = $current[
'created'];
564 $accessToken->updated = $current[
'updated'];
581 if (!empty(self::$memcache)) {
583 $id = $accessToken->getPlatform()->getRecordId();
584 $value = $accessToken->token;
585 $expires = $accessToken->expires;
586 $name = self::ACCESS_TOKEN_TABLE_NAME .
"_{$id}_{$value}";
587 $current = self::$memcache->get($name);
588 if ($current ===
false) {
590 'scopes' => $accessToken->scopes,
592 'expires' => $expires,
593 'created' => $accessToken->created,
594 'updated' => $accessToken->updated
596 $ok = self::$memcache->set($name, $current, 0, $expires);
604### ResourceLinkShareKey methods
644### UserResult methods
657 $userresult->created = $now;
658 $userresult->updated = $now;
672 $userresult->updated = time();
686 $userresult->initialize();
704 $tool->secret =
'secret';
705 $tool->enabled =
true;
707 $tool->created = $now;
708 $tool->updated = $now;
722 $tool->updated = time();
776 if (!is_null(
$db) && empty($type)) {
777 if (is_object(
$db)) {
778 $type = get_class(
$db);
779 } elseif (is_resource(
$db)) {
780 $type = strtok(get_resource_type(
$db),
' ');
783 $type = strtolower($type);
784 if ($type ===
'pdo') {
785 if (
$db->getAttribute(\PDO::ATTR_DRIVER_NAME) ===
'pgsql') {
787 } elseif (
$db->getAttribute(\PDO::ATTR_DRIVER_NAME) ===
'oci') {
792 $type =
"DataConnector_{$type}";
794 $type =
'DataConnector';
796 $type =
"\\ceLTIc\\LTI\\DataConnector\\{$type}";
799 return $dataConnector;
816 Util::logDebug(
'Method ceLTIc\LTI\DataConnector::getRandomString() has been deprecated; please use ceLTIc\LTI\Util::getRandomString() instead.',
832 public function escape($value, $addQuotes =
true)
834 return static::quoted($value, $addQuotes);
848 public static function quoted($value, $addQuotes =
true)
850 if (is_null($value)) {
853 $value = str_replace(
'\'',
'\'\
'', $value);
855 $value =
"'{$value}'";
871 $platform->authorizationServerId = $platform->getSetting(
'_authorization_server_id', $platform->authorizationServerId);
872 $platform->setSetting(
'_authorization_server_id');
873 $platform->authenticationUrl = $platform->getSetting(
'_authentication_request_url', $platform->authenticationUrl);
874 $platform->setSetting(
'_authentication_request_url');
875 $platform->accessTokenUrl = $platform->getSetting(
'_oauth2_access_token_url', $platform->accessTokenUrl);
876 $platform->setSetting(
'_oauth2_access_token_url');
877 $platform->jku = $platform->getSetting(
'_jku', $platform->jku);
878 $platform->setSetting(
'_jku');
879 $platform->encryptionMethod = $platform->getSetting(
'_encryption_method', $platform->encryptionMethod);
880 $platform->setSetting(
'_encryption_method');
881 $platform->debugMode = $platform->getSetting(
'_debug', $platform->debugMode ?
'true' :
'false') ===
'true';
882 $platform->setSetting(
'_debug');
883 if ($platform->debugMode) {
887 $platform->setSetting(
'_authorization_server_id',
888 !empty($platform->authorizationServerId) ? $platform->authorizationServerId :
null);
889 $platform->setSetting(
'_authentication_request_url',
890 !empty($platform->authenticationUrl) ? $platform->authenticationUrl :
null);
891 $platform->setSetting(
'_oauth2_access_token_url', !empty($platform->accessTokenUrl) ? $platform->accessTokenUrl :
null);
892 $platform->setSetting(
'_jku', !empty($platform->jku) ? $platform->jku :
null);
893 $platform->setSetting(
'_encryption_method', !empty($platform->encryptionMethod) ? $platform->encryptionMethod :
null);
894 $platform->setSetting(
'_debug', $platform->debugMode ?
'true' :
null);
907 $tool->encryptionMethod = $tool->getSetting(
'_encryption_method', $tool->encryptionMethod);
908 $tool->setSetting(
'_encryption_method');
909 $tool->debugMode = $tool->getSetting(
'_debug', $tool->debugMode ?
'true' :
'false') ===
'true';
910 $tool->setSetting(
'_debug');
911 if ($tool->debugMode) {
915 $tool->setSetting(
'_encryption_method', !empty($tool->encryptionMethod) ? $tool->encryptionMethod :
null);
916 $tool->setSetting(
'_debug', $tool->debugMode ?
'true' :
null);
Class to represent an HTTP message.
Class to represent a platform context.
Class to provide a connection to a persistent store for LTI objects.
loadResourceLinkShareKey($shareKey)
Load resource link share key object.
escape($value, $addQuotes=true)
Escape a string for use in a database query.
saveUserResult($userresult)
Save user object.
loadContext($context)
Load context object.
deleteTool($tool)
Delete tool object.
const RESOURCE_LINK_SHARE_KEY_TABLE_NAME
Default name for database table used to store resource link share keys.
const CONTEXT_TABLE_NAME
Default name for database table used to store contexts.
savePlatform($platform)
Save platform object.
saveConsumerNonce($nonce)
Save nonce object.
const NONCE_TABLE_NAME
Default name for database table used to store nonce values.
getToolConsumers()
Load tool consumer objects.
deletePlatform($platform)
Delete platform object.
saveAccessToken($accessToken)
Save access token object.
deletePlatformNonce($nonce)
Delete nonce object.
static getDataConnector($db=null, $dbTableNamePrefix='', $type='')
Create data connector object.
saveResourceLinkShareKey($shareKey)
Save resource link share key object.
deleteConsumerNonce($nonce)
Delete nonce object.
saveContext($context)
Save context object.
loadPlatformNonce($nonce)
Load nonce object.
static getRandomString($length=8)
Generate a random string.
loadAccessToken($accessToken)
Load access token object.
loadTool($tool)
Load tool object.
loadConsumerNonce($nonce)
Load nonce object.
const PLATFORM_TABLE_NAME
Default name for database table used to store platforms.
getTools()
Load tool objects.
const ACCESS_TOKEN_TABLE_NAME
Default name for database table used to store access token values.
$dbTableNamePrefix
Prefix for database table names.
saveToolConsumer($consumer)
Save tool consumer object.
fixToolSettings($tool, $isSave)
Adjust the settings for any tool properties being stored as a setting value.
loadPlatform($platform)
Load platform object.
getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
Get array of user objects.
__construct($db, $dbTableNamePrefix='')
Class constructor.
$dateFormat
SQL date format (default = 'Y-m-d')
$timeFormat
SQL time format (default = 'H:i:s')
getPlatforms()
Load platform objects.
getSharesResourceLink($resourceLink)
Get array of shares defined for this resource link.
loadResourceLink($resourceLink)
Load resource link object.
static quoted($value, $addQuotes=true)
Quote a string for use in a database query.
savePlatformNonce($nonce)
Save nonce object.
const CONSUMER_TABLE_NAME
Default name for database table used to store platforms.
saveResourceLink($resourceLink)
Save resource link object.
loadToolConsumer($consumer)
Load tool consumer object.
deleteContext($context)
Delete context object.
loadUserResult($userresult)
Load user object.
static useMemcache($host=null, $port=-1)
Set/check whether memcached should be used when available.
const USER_RESULT_TABLE_NAME
Default name for database table used to store users.
deleteUserResult($userresult)
Delete user object.
deleteResourceLinkShareKey($shareKey)
Delete resource link share key object.
const RESOURCE_LINK_TABLE_NAME
Default name for database table used to store resource links.
const TOOL_TABLE_NAME
Default name for database table used to store tools.
fixPlatformSettings($platform, $isSave)
Adjust the settings for any platform properties being stored as a setting value.
deleteToolConsumer($consumer)
Delete tool consumer object.
saveTool($tool)
Save tool object.
deleteResourceLink($resourceLink)
Delete resource link object.
Class to represent a platform resource link share key.
Class to represent a platform resource link share.
Class to represent a platform resource link.
Class to represent a platform user association with a resource link.
Class to implement utility methods.
static getRandomString($length=8)
Generate a random string.
static $logLevel
Current logging level.
static logError($message, $showSource=true)
Log an error message.
const LOGLEVEL_DEBUG
Log all messages.
static logDebug($message, $showSource=false)
Log a debug message.