ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 if ($result_string) {
113 $this->result = json_decode($result_string, false, 512, JSON_THROW_ON_ERROR);
114 } else {
115 $this->result = [];
116 }
117 break;
118
120 $this->result = $this->parseUriList($result_string);
121 break;
122 }
123 }
124
130 private function parseUriList(string $a_content): \ilECSUriList
131 {
132 $list = new ilECSUriList();
133 $lines = explode("\n", $a_content);
134 foreach ($lines as $line) {
135 $line = trim($line);
136 if ($line === '') {
137 continue;
138 }
139 $uri_parts = explode("/", $line);
140 $list->add($line, (int) array_pop($uri_parts));
141 }
142
143 return $list;
144 }
145}
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)