/** * Update a Toolbox instance from a configuration file * * @see Toolbox::fromConfiguration() Use `Toolbox::fromConfiguration()` * * @param string $configFilePath * @param boolean $forceRecache * @return void */ protected function loadConfiguration($configFilePath, $forceRecache = false) { parent::loadConfiguration($configFilePath, $forceRecache); $config = new ConfigXML($configFilePath); /* configure database connections */ $this->setCustomPrefs($config->newInstanceOf(mysqli::class, '/config/customprefs')); }
public function __construct($config) { $this->config = new ConfigXML($config); $this->sql = $this->config->newInstanceOf(mysqli::class, '//mysql'); parent::__construct(LTI_Data_Connector::getDataConnector($this->sql)); $this->setParameterConstraint('oauth_consumer_key', TRUE, 50); $this->setParameterConstraint('resource_link_id', TRUE, 50, array('basic-lti-launch-request')); $this->setParameterConstraint('user_id', TRUE, 50, array('basic-lti-launch-request')); $this->setParameterConstraint('roles', TRUE, NULL, array('basic-lti-launch-request')); $this->metadata = new AppMetadata($this->sql, ''); $this->opentok = $this->config->newInstanceOf(OpenTok::class, '//tokbox'); }
/** * Update a Toolbox instance from a configuration file * * @see Toolbox::fromConfiguration() Use `Toolbox::fromConfiguration()` * * @param string $configFilePath * @param boolean $forceRecache * @return void */ protected function loadConfiguration($configFilePath, $forceRecache = false) { $logQueue = []; /* load the configuration file */ $config = new ConfigXML($configFilePath); /* configure database connections */ $this->setMySQL($config->newInstanceOf(mysqli::class, '/config/mysql')); /* configure metadata caching */ $id = $config->toString('/config/tool/id'); if (empty($id)) { $id = basename(dirname($configFilePath)) . '_' . md5(__DIR__ . file_get_contents($configFilePath)); $logQueue[] = " Automatically generated ID {$id}"; } $this->setMetadata(new AppMetadata($this->mysql, $id, self::TOOL_METADATA_TABLE)); /* update metadata */ if ($forceRecache || empty($this->metadata['TOOL_ID']) || empty($this->metadata['TOOL_LAUNCH_URL']) || empty($this->metadata['TOOL_CONFIG_FILE'])) { $tool = $config->toArray('/config/tool')[0]; $this->metadata['TOOL_ID'] = $id; $this->metadata['TOOL_NAME'] = empty($tool['name']) ? $id : $tool['name']; $this->metadata['TOOL_CONFIG_FILE'] = realpath($configFilePath); $configPath = dirname($this->metadata['TOOL_CONFIG_FILE']); if (!empty($tool['description'])) { $this->metadata['TOOL_DESCRIPTION'] = $tool['description']; } elseif (isset($this->metadata['TOOL_DESCRIPTION'])) { unset($this->metadata['TOOL_DESCRIPTION']); } if (!empty($tool['icon'])) { $this->metadata['TOOL_ICON_URL'] = file_exists("{$configPath}/{$tool['icon']}") ? DataUtilities::URLfromPath("{$configPath}/{$tool['icon']}") : $tool[self::ICON]; } elseif (isset($this->metadata['TOOL_ICON_URL'])) { unset($this->metadata['TOOL_ICON_URL']); } $this->metadata['TOOL_LAUNCH_PRIVACY'] = empty($tool['launch-privacy']) ? self::DEFAULT_LAUNCH_PRIVACY : $tool['launch-privacy']; if (!empty($tool['domain'])) { $this->metadata['TOOL_DOMAIN'] = $tool['domain']; } elseif (isset($this->metadata['TOOL_DOMAIN'])) { unset($this->metadata['TOOL_DOMAIN']); } $this->metadata['TOOL_LAUNCH_URL'] = empty($tool['authenticate']) ? DataUtilities::URLfromPath($_SERVER['SCRIPT_FILENAME']) : DataUtilities::URLfromPath("{$configPath}/{$tool['authenticate']}"); $logQueue[] = " Tool metadata configured"; } $configPath = dirname($this->metadata['TOOL_CONFIG_FILE']); /* configure logging */ if ($forceRecache || empty($this->metadata['TOOL_LOG'])) { $log = "{$configPath}/" . $config->toString('/config/tool/log'); shell_exec("touch \"{$log}\""); $this->metadata['TOOL_LOG'] = realpath($log); } $this->setLog(Log::singleton('file', $this->metadata['TOOL_LOG'])); if ($forceRecache) { $this->log("Resetting LTI configuration from {$configFilePath}"); } if (!empty($logQueue)) { foreach ($logQueue as $message) { $this->log($message); } unset($logQueue); } /* configure tool provider */ if ($forceRecache || empty($this->metadata['TOOL_HANDLER_URLS'])) { $handlers = $config->toArray('/config/tool/handlers')[0]; if (empty($handlers) || !is_array($handlers)) { throw new ConfigurationException('At least one handler/URL pair must be specified', ConfigurationException::TOOL_PROVIDER); } foreach ($handlers as $request => $path) { $handlers[$request] = DataUtilities::URLfromPath("{$configPath}/{$path}"); } $this->metadata['TOOL_HANDLER_URLS'] = $handlers; $this->log(' Tool provider handler URLs configured'); } /* configure API access */ if ($forceRecache || empty($this->metadata['TOOL_CANVAS_API'])) { $this->metadata['TOOL_CANVAS_API'] = $config->toArray('/config/canvas')[0]; if (empty($this->metadata['TOOL_CANVAS_API'])) { throw new ConfigurationException('Canvas API credentials must be provided', ConfigurationException::CANVAS_API_MISSING); } $this->log(' Canvas API credentials configured'); } }