54 private $platform =
null;
71 $this->platform = $platform;
85 Util::logDebug(
'Method ceLTIc\LTI\Service::getConsumer() has been deprecated; please use ceLTIc\LTI\Service::getPlatform() instead.',
97 return $this->platform;
119 public function send($method, $parameters = array(), $body =
null)
121 $url = $this->endpoint;
122 if (!empty($parameters)) {
123 if (strpos($url,
'?') ===
false) {
128 foreach ($parameters as $name => $value) {
129 $url .= $sep . urlencode($name) .
'=' . urlencode($value);
134 $retry = !$this->platform->useOAuth1();
138 if (!$this->
unsigned) {
139 $accessToken = $this->platform->getAccessToken();
140 if (!$this->platform->useOAuth1()) {
141 if (empty($accessToken)) {
143 $this->platform->setAccessToken($accessToken);
145 if (!$accessToken->hasScope($this->scope)) {
146 $accessToken->get($this->scope);
148 if (!$accessToken->hasScope($this->scope)) {
149 $accessToken->expires = time();
150 $accessToken->get($this->scope,
true);
152 if (!$accessToken->hasScope($this->scope)) {
153 if (empty($this->http)) {
155 $this->http->error =
"Unable to obtain an access token for scope: {$this->scope}";
162 $header = $this->platform->signServiceRequest($url, $method, $this->mediaType, $body);
165 $this->http =
new HttpMessage($url, $method, $body, $header);
166 if ($this->http->send() && !empty($this->http->response)) {
168 $this->http->ok = !is_null($this->http->responseJson);
170 $retry = $retry && !$retried && !$this->http->ok;
173 $accessToken->expires = time();
175 } elseif (count($accessToken->scopes) !== 1) {
176 $accessToken->expires = time();
177 $accessToken->get($this->scope,
true);
212 if (is_array($contexts)) {
213 $contextdefs = array();
214 foreach ($contexts as $context) {
215 if (is_object($context)) {
216 $contextdefs = array_merge(get_object_vars($context), $contexts);
220 foreach ($arr as $key => $value) {
221 $parts = explode(
':', $value, 2);
222 if (count($parts) > 1) {
223 if (array_key_exists($parts[0], $contextdefs)) {
224 $parsed[$key] = $contextdefs[$parts[0]] . $parts[1];
228 $parsed[$key] = $value;
Class to represent an HTTP message.
Class to represent an HTTP message request.
Class to implement a service.
getScope()
Get access scope.
__construct($platform, $endpoint)
Class constructor.
$scope
Service access scope.
getConsumer()
Get tool consumer.
getHttpMessage()
Get HttpMessage object for last request.
send($method, $parameters=array(), $body=null)
Send a service request.
getPlatform()
Get platform.
$mediaType
Media type of message body.
$unsigned
Whether service request should be sent unsigned.
$endpoint
Service endpoint.
parseContextsInArray($contexts, $arr)
Parse the JSON for context references.
Class to implement utility methods.
static jsonDecode($str, $associative=false)
Decode a JSON string.
static logDebug($message, $showSource=false)
Log a debug message.