19 declare(strict_types=1);
33 $this->log()->debug($this->msg(
'proxy initialized'));
38 preg_match(self::PARTS_REG, (
string) $request->getUri(), $this->cmdParts);
53 return $this->lrsType;
58 return $this->replacedValues;
63 return $this->specificAllowedStatements;
68 return $this->blockSubStatements;
76 return $this->cmdParts;
86 return $this->defaultLrsEndpoint;
91 return $this->defaultLrsKey;
96 return $this->defaultLrsSecret;
101 return $this->fallbackLrsEndpoint;
106 return $this->fallbackLrsKey;
111 return $this->fallbackLrsSecret;
116 $this->xapiProxyRequest = $xapiProxyRequest;
121 return $this->xapiProxyRequest;
126 $this->xapiProxyResponse = $xapiProxyResponse;
131 return $this->xapiProxyResponse;
137 if (!is_array($this->specificAllowedStatements) && !$this->blockSubStatements) {
138 $this->log()->debug($this->msg(
"all statement are allowed"));
141 $obj = json_decode($body,
false);
143 if (is_object($obj) && isset($obj->verb)) {
144 $this->log()->debug($this->msg(
"json is object and statement"));
145 $isSubStatement = $this->isSubStatementCheck($obj);
146 $verb = $obj->verb->id;
147 if ($this->blockSubStatements && $isSubStatement) {
148 $this->log()->debug($this->msg(
"sub-statement is NOT allowed, fake response - " . $verb));
149 $this->xapiProxyResponse->fakeResponseBlocked(
null);
152 if (!is_array($this->specificAllowedStatements)) {
155 if (in_array($verb, $this->specificAllowedStatements)) {
156 $this->log()->debug($this->msg(
"statement is allowed, do nothing - " . $verb));
159 $this->log()->debug($this->msg(
"statement is NOT allowed, fake response - " . $verb));
160 $this->xapiProxyResponse->fakeResponseBlocked(
null);
164 if (is_array($obj) && count($obj) > 0 && isset($obj[0]->verb)) {
165 $this->log()->debug($this->msg(
"json is array of statements"));
168 foreach ($obj as $i => $singleObj) {
169 $ret[] = $singleObj->id;
171 $isSubStatement = $this->isSubStatementCheck($singleObj);
172 $verb = $singleObj->verb->id;
173 if ($this->blockSubStatements && $isSubStatement) {
174 $this->log()->debug($this->msg(
"sub-statement is NOT allowed - " . $verb));
176 if (!is_array($this->specificAllowedStatements) || (is_array($this->specificAllowedStatements) && in_array($verb, $this->specificAllowedStatements))) {
177 $this->log()->debug($this->msg(
"statement is allowed - " . $verb));
183 $this->log()->debug($this->msg(
"no allowed statements in array - fake response..."));
184 $this->xapiProxyResponse->fakeResponseBlocked(
"");
186 } elseif (count($up) !== count($ret)) {
187 $this->log()->debug($this->msg(
"mixed with allowed and unallowed statements"));
188 return array($up,$ret);
199 $obj = json_decode($body,
false);
201 if (json_last_error() != JSON_ERROR_NONE) {
203 $this->log()->error($this->msg(json_last_error_msg()));
208 if (is_object($obj)) {
209 if (is_array($this->replacedValues)) {
210 foreach ($this->replacedValues as $key => $value) {
211 $this->setValue($obj, (
string) $key, (
string) $value);
214 $this->handleStatementEvaluation($obj);
217 if (is_array($obj)) {
218 for ($i = 0; $i < count($obj); $i++) {
219 if (is_array($this->replacedValues)) {
220 foreach ($this->replacedValues as $key => $value) {
221 $this->setValue($obj[$i], (
string) $key, (
string) $value);
224 $this->handleStatementEvaluation($obj[$i]);
227 return json_encode($obj);
235 $this->setStatus($xapiStatement);
241 $statementEvaluation = new \ilXapiStatementEvaluation($this->log(), $object);
242 $statementEvaluation->evaluateStatement($xapiStatement, $this->authToken->getUsrId());
246 $this->authToken->getObjId(),
247 $this->authToken->getUsrId()
251 if ($xapiStatement->verb->id == self::TERMINATED_VERB) {
253 $this->authToken->delete();
260 $path_components = explode(
'.', $path);
261 if (count($path_components) == 1) {
262 if (property_exists($obj, $path_components[0])) {
263 $obj->{$path_components[0]} = $value;
266 if (property_exists($obj, $path_components[0])) {
267 $this->setValue($obj->{array_shift($path_components)}, implode(
'.', $path_components), $value);
296 $objActivityId = $object->getActivityId();
297 $statementActivityId = $obj->object->id;
298 if ($statementActivityId != $objActivityId) {
299 $this->log()->debug($this->msg(
"statement object id " . $statementActivityId .
" != activityId " . $objActivityId));
300 $this->log()->debug($this->msg(
"is Substatement"));
303 $this->log()->debug($this->msg(
"is not Substatement"));
XapiProxyResponse $xapiProxyResponse
setXapiProxyRequest(XapiProxyRequest $xapiProxyRequest)
__construct(string $client, string $token, ?bool $plugin=false)
setXapiProxyResponse(XapiProxyResponse $xapiProxyResponse)
XapiProxyRequest $xapiProxyRequest
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
specificAllowedStatements()
setValue(object &$obj, string $path, string $value)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
handleStatementEvaluation(object $xapiStatement)
__construct(Container $dic, ilPlugin $plugin)
processStatements(\Psr\Http\Message\RequestInterface $request, $body)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
setRequestParams(Request $request)
isSubStatementCheck(object $obj)