ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
StaticURLRequestBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\StaticURL\Request;
22 
26 
31 {
32  public function buildRequest(Services $http, Factory $refinery, array $handlers): ?Request
33  {
34  // maybe we have a legacy parameter during transition phase
35  $target = $http->wrapper()->query()->has("target")
36  ? $http->wrapper()->query()->retrieve(
37  "target",
38  $refinery->to()->string()
39  )
40  : null;
41  if ($target !== null) {
42  $target_parts = explode('_', (string) $target);
43  $namespace = array_shift($target_parts);
44 
45  $reference_id = is_numeric($target_parts[0]) ? new ReferenceId((int) array_shift($target_parts)) : null;
46  $additional_parameters = [];
47  foreach ($target_parts as $target_part) {
48  $additional_parameters[] = urldecode($target_part);
49  }
50  return new Request(
51  $namespace,
52  $reference_id,
53  $additional_parameters
54  );
55  }
56 
57  // This part is for new urls
58  // everything behind goto.php/ is the requested target
59  $requested_url = (string) $http->request()->getUri();
60 
61  if (str_contains($requested_url, '/go/')) {
62  $offset = strpos($requested_url, '/go/') + strlen('/go/');
63  } else {
64  $offset = strpos($requested_url, '/goto.php/') + strlen('/goto.php/');
65  }
66 
67  $requested_url = substr(
69  $offset
70  );
71  $requested_url_parts = explode('/', $requested_url);
72  $namespace = array_shift($requested_url_parts);
73  $additional_parameters = [];
74  if (isset($requested_url_parts[0]) && is_numeric($requested_url_parts[0])) {
75  $reference_id = new ReferenceId((int) array_shift($requested_url_parts));
76  } else {
77  $reference_id = null;
78  }
79  foreach ($requested_url_parts as $requested_url_part) {
80  $additional_parameters[] = urldecode($requested_url_part);
81  }
82 
83  return new Request(
84  $namespace,
85  $reference_id,
86  $additional_parameters
87  );
88  }
89 }
if($err=$client->getError()) $namespace
$http
Definition: deliver.php:30
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$requested_url
Definition: deliver.php:32
to()
Combined validations and transformations for primitive data types that establish a baseline for furth...
Definition: Factory.php:40
buildRequest(Services $http, Factory $refinery, array $handlers)