ILIAS  release_8 Revision v8.24
class.ilECSResult.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
24{
25 public const RESULT_TYPE_JSON = 1;
26 public const RESULT_TYPE_URL_LIST = 2;
27
28 private int $http_code = 0;
29 private int $result_type;
30 private $result;
31
32 private array $headers = array();
33
43 public function __construct(string $a_res, int $a_type = self::RESULT_TYPE_JSON)
44 {
45 $this->result_type = $a_type;
46
47 $this->init($a_res, $a_type);
48 }
49
57 public function setHTTPCode(int $a_code): void
58 {
59 $this->http_code = $a_code;
60 }
61
67 public function getHTTPCode(): int
68 {
69 return $this->http_code;
70 }
71
77 public function getResult()
78 {
79 return $this->result;
80 }
81
82 public function getResultType(): int
83 {
84 return $this->result_type;
85 }
86
91 public function setHeaders(array $a_headers): void
92 {
93 $this->headers = $a_headers;
94 }
95
99 public function getHeaders(): array
100 {
101 return $this->headers ?: [];
102 }
103
107 private function init(string $result_string, int $result_type): void
108 {
109 switch ($result_type) {
111 if ($result_string) {
112 $this->result = json_decode($result_string, false, 512, JSON_THROW_ON_ERROR);
113 } else {
114 $this->result = [];
115 }
116 break;
117
119 $this->result = $this->parseUriList($result_string);
120 break;
121 }
122 }
123
129 private function parseUriList(string $a_content): \ilECSUriList
130 {
131 $list = new ilECSUriList();
132 $lines = explode("\n", $a_content);
133 foreach ($lines as $line) {
134 $line = trim($line);
135 if ($line === '') {
136 continue;
137 }
138 $uri_parts = explode("/", $line);
139 $list->add($line, (int) array_pop($uri_parts));
140 }
141
142 return $list;
143 }
144}
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)