19declare(strict_types=1);
23use GuzzleHttp\Psr7\Request;
24use GuzzleHttp\Psr7\Response;
34 $this->log()->debug($this->msg(
'proxy initialized'));
39 preg_match(self::PARTS_REG, (
string) $request->getUri(), $this->cmdParts);
54 return $this->lrsType;
59 return $this->replacedValues;
64 return $this->specificAllowedStatements;
69 return $this->blockSubStatements;
77 return $this->cmdParts;
87 return $this->defaultLrsEndpoint;
92 return $this->defaultLrsKey;
97 return $this->defaultLrsSecret;
102 return $this->fallbackLrsEndpoint;
107 return $this->fallbackLrsKey;
112 return $this->fallbackLrsSecret;
117 $this->xapiProxyRequest = $xapiProxyRequest;
122 return $this->xapiProxyRequest;
127 $this->xapiProxyResponse = $xapiProxyResponse;
132 return $this->xapiProxyResponse;
138 if (!is_array($this->specificAllowedStatements) && !$this->blockSubStatements) {
139 $this->log()->debug($this->msg(
"all statement are allowed"));
142 $obj = json_decode($body,
false);
144 if (is_object($obj) && isset($obj->verb)) {
145 $this->log()->debug($this->msg(
"json is object and statement"));
146 $isSubStatement = $this->isSubStatementCheck($obj);
147 $verb = $obj->verb->id;
148 if ($this->blockSubStatements && $isSubStatement) {
149 $this->log()->debug($this->msg(
"sub-statement is NOT allowed, fake response - " . $verb));
150 $this->xapiProxyResponse->fakeResponseBlocked(
null);
153 if (!is_array($this->specificAllowedStatements)) {
156 if (in_array($verb, $this->specificAllowedStatements)) {
157 $this->log()->debug($this->msg(
"statement is allowed, do nothing - " . $verb));
160 $this->log()->debug($this->msg(
"statement is NOT allowed, fake response - " . $verb));
161 $this->xapiProxyResponse->fakeResponseBlocked(
null);
165 if (is_array($obj) && count($obj) > 0 && isset($obj[0]->verb)) {
166 $this->log()->debug($this->msg(
"json is array of statements"));
169 foreach ($obj as $i => $singleObj) {
170 $ret[] = $singleObj->id;
172 $isSubStatement = $this->isSubStatementCheck($singleObj);
173 $verb = $singleObj->verb->id;
174 if ($this->blockSubStatements && $isSubStatement) {
175 $this->log()->debug($this->msg(
"sub-statement is NOT allowed - " . $verb));
177 if (!is_array($this->specificAllowedStatements) || (is_array($this->specificAllowedStatements) && in_array($verb, $this->specificAllowedStatements))) {
178 $this->log()->debug($this->msg(
"statement is allowed - " . $verb));
184 $this->log()->debug($this->msg(
"no allowed statements in array - fake response..."));
185 $this->xapiProxyResponse->fakeResponseBlocked(
"");
187 } elseif (count($up) !== count($ret)) {
188 $this->log()->debug($this->msg(
"mixed with allowed and unallowed statements"));
189 return array($up,$ret);
200 $obj = json_decode($body,
false);
202 if (json_last_error() != JSON_ERROR_NONE) {
204 $this->log()->error($this->msg(json_last_error_msg()));
209 if (is_object($obj)) {
210 if (is_array($this->replacedValues)) {
211 foreach ($this->replacedValues as $key => $value) {
212 $this->setValue($obj, (
string) $key, (
string) $value);
215 $this->handleStatementEvaluation($obj);
218 if (is_array($obj)) {
219 for ($i = 0; $i < count($obj); $i++) {
220 if (is_array($this->replacedValues)) {
221 foreach ($this->replacedValues as $key => $value) {
222 $this->setValue($obj[$i], (
string) $key, (
string) $value);
225 $this->handleStatementEvaluation($obj[$i]);
228 return json_encode($obj);
236 $this->setStatus($xapiStatement);
242 $statementEvaluation = new \ilXapiStatementEvaluation($this->log(), $object);
243 $statementEvaluation->evaluateStatement($xapiStatement, $this->authToken->getUsrId());
247 $this->authToken->getObjId(),
248 $this->authToken->getUsrId()
252 if ($xapiStatement->verb->id == self::TERMINATED_VERB) {
254 $this->authToken->delete();
261 $path_components = explode(
'.',
$path);
262 if (count($path_components) == 1) {
263 if (property_exists($obj, $path_components[0])) {
264 $obj->{$path_components[0]} = $value;
267 if (property_exists($obj, $path_components[0])) {
268 $this->setValue($obj->{array_shift($path_components)}, implode(
'.', $path_components), $value);
297 $objActivityId = $object->getActivityId();
298 $statementActivityId = $obj->object->id;
299 if ($statementActivityId != $objActivityId) {
300 $this->log()->debug($this->msg(
"statement object id " . $statementActivityId .
" != activityId " . $objActivityId));
301 $this->log()->debug($this->msg(
"is Substatement"));
304 $this->log()->debug($this->msg(
"is not Substatement"));
isSubStatementCheck(object $obj)
handleStatementEvaluation(object $xapiStatement)
setXapiProxyResponse(XapiProxyResponse $xapiProxyResponse)
processStatements(\Psr\Http\Message\RequestInterface $request, $body)
XapiProxyRequest $xapiProxyRequest
specificAllowedStatements()
setValue(object &$obj, string $path, string $value)
XapiProxyResponse $xapiProxyResponse
setXapiProxyRequest(XapiProxyRequest $xapiProxyRequest)
setRequestParams(Request $request)
__construct(string $client, string $token, ?bool $plugin=false)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc