ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilECSResult.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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) {
111  case self::RESULT_TYPE_JSON:
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 
119  case self::RESULT_TYPE_URL_LIST:
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 }
const RESULT_TYPE_URL_LIST
init(string $result_string, int $result_type)
init result (json_decode)
Presentation of ecs uril (http://...campusconnect/courselinks)
getResult()
get result
setHeaders(array $a_headers)
Set header.
parseUriList(string $a_content)
__construct(string $a_res, int $a_type=self::RESULT_TYPE_JSON)
Constructor.
getHTTPCode()
get HTTP code
setHTTPCode(int $a_code)
set HTTP return code
getHeaders()
get headers