ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilECSResult.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const RESULT_TYPE_JSON = 1;
27 public const RESULT_TYPE_URL_LIST = 2;
28
29 private int $http_code = 0;
30 private int $result_type;
31 private $result;
32
33 private array $headers = array();
34
44 public function __construct(string $a_res, int $a_type = self::RESULT_TYPE_JSON)
45 {
46 $this->result_type = $a_type;
47
48 $this->init($a_res, $a_type);
49 }
50
58 public function setHTTPCode(int $a_code): void
59 {
60 $this->http_code = $a_code;
61 }
62
68 public function getHTTPCode(): int
69 {
70 return $this->http_code;
71 }
72
78 public function getResult()
79 {
80 return $this->result;
81 }
82
83 public function getResultType(): int
84 {
85 return $this->result_type;
86 }
87
92 public function setHeaders(array $a_headers): void
93 {
94 $this->headers = $a_headers;
95 }
96
100 public function getHeaders(): array
101 {
102 return $this->headers ?: [];
103 }
104
108 private function init(string $result_string, int $result_type): void
109 {
110 switch ($result_type) {
112 $payload = trim($result_string);
113 if ($payload !== '') {
114 $this->result = json_decode($payload, false, 512, JSON_THROW_ON_ERROR);
115 } else {
116 $this->result = [];
117 }
118 break;
119
121 $this->result = $this->parseUriList($result_string);
122 break;
123 }
124 }
125
131 private function parseUriList(string $a_content): \ilECSUriList
132 {
133 $list = new ilECSUriList();
134 $lines = explode("\n", $a_content);
135 foreach ($lines as $line) {
136 $line = trim($line);
137 if ($line === '') {
138 continue;
139 }
140 $uri_parts = explode("/", $line);
141 $list->add($line, (int) array_pop($uri_parts));
142 }
143
144 return $list;
145 }
146}
getHeaders()
get headers
getResult()
get result
const RESULT_TYPE_URL_LIST
getHTTPCode()
get HTTP code
__construct(string $a_res, int $a_type=self::RESULT_TYPE_JSON)
Constructor.
init(string $result_string, int $result_type)
init result (json_decode)
setHTTPCode(int $a_code)
set HTTP return code
setHeaders(array $a_headers)
Set header.
parseUriList(string $a_content)
Presentation of ecs uril (http://...campusconnect/courselinks)
if(count($parts) !=3) $payload
Definition: ltitoken.php:67