/** * Class constructor. * * @param string $key Consumer key * @param mixed $storage String containing table name prefix, or database connection object, or array containing one or both values (optional, default is MySQL with an empty table name prefix) * @param boolean $autoEnable true if the tool consumers is to be enabled automatically (optional, default is false) */ public function __construct($key = null, $storage = '', $autoEnable = false) { $this->storage = AbstractStorage::getStorage($storage); if (!empty($key)) { $this->load($key, $autoEnable); } else { $this->secret = AbstractStorage::getRandomString(32); } }
/** * 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 = AbstractStorage::getRandomString($this->length); } return $this->data_connector->resourceLinkShareKeySave($this); }
/** * Get an array of defined tool consumers * * @return array Array of ToolConsumer objects */ public function getConsumers() { // Initialise data connector $this->storage = AbstractStorage::getStorage($this->storage); return $this->storage->toolConsumerList(); }