示例#1
0
 /**
  * Class constructor.
  *
  * @param DataConnector   $dataConnector   Data connector
  * @param string                        $id              Tool Proxy ID (optional, default is null)
  */
 public function __construct($dataConnector, $id = null)
 {
     $this->initialize();
     $this->dataConnector = $dataConnector;
     if (!empty($id)) {
         $this->load($id);
     } else {
         $this->recordId = DataConnector::getRandomString(32);
     }
 }
示例#2
0
 /**
  * Save the resource link share key to the database.
  *
  * @return boolean True if the share key was successfully saved
  */
 public function save()
 {
     if (empty($this->life)) {
         $this->life = self::DEFAULT_SHARE_KEY_LIFE;
     } else {
         $this->life = max(min($this->life, self::MAX_SHARE_KEY_LIFE), 0);
     }
     $this->expires = time() + $this->life * 60 * 60;
     if (empty($this->id)) {
         if (empty($this->length) || !is_numeric($this->length)) {
             $this->length = self::MAX_SHARE_KEY_LENGTH;
         } else {
             $this->length = max(min($this->length, self::MAX_SHARE_KEY_LENGTH), self::MIN_SHARE_KEY_LENGTH);
         }
         $this->id = DataConnector::getRandomString($this->length);
     }
     return $this->dataConnector->saveResourceLinkShareKey($this);
 }
示例#3
0
 /**
  * Send the tool proxy to the Tool Consumer
  *
  * @return boolean True if the tool proxy was accepted
  */
 public function doToolProxyService()
 {
     // Create tool proxy
     $toolProxyService = $this->findService('application/vnd.ims.lti.v2.toolproxy+json', array('POST'));
     $secret = DataConnector::getRandomString(12);
     $toolProxy = new MediaType\ToolProxy($this, $toolProxyService, $secret);
     $http = $this->consumer->doServiceRequest($toolProxyService, 'POST', 'application/vnd.ims.lti.v2.toolproxy+json', json_encode($toolProxy));
     $ok = $http->ok && $http->status == 201 && isset($http->responseJson->tool_proxy_guid) && strlen($http->responseJson->tool_proxy_guid) > 0;
     if ($ok) {
         $this->consumer->setKey($http->responseJson->tool_proxy_guid);
         $this->consumer->secret = $toolProxy->security_contract->shared_secret;
         $this->consumer->toolProxy = json_encode($toolProxy);
         $this->consumer->save();
     }
     return $ok;
 }
示例#4
0
 /**
  * Class constructor.
  *
  * @param string  $key             Consumer key
  * @param DataConnector   $dataConnector   A data connector object
  * @param boolean $autoEnable      true if the tool consumers is to be enabled automatically (optional, default is false)
  */
 public function __construct($key = null, $dataConnector = null, $autoEnable = false)
 {
     $this->initialize();
     if (empty($dataConnector)) {
         $dataConnector = DataConnector::getDataConnector();
     }
     $this->dataConnector = $dataConnector;
     if (!empty($key)) {
         $this->load($key, $autoEnable);
     } else {
         $this->secret = DataConnector::getRandomString(32);
     }
 }