ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
LegacyRequestBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\StaticURL\Request;
22 
27 
32 {
33  public function buildRequest(\ILIAS\HTTP\Services $http, Factory $refinery, array $handlers): ?Request
34  {
35  // try to get target from query
36  $target = $http->wrapper()->query()->has("target")
37  ? $http->wrapper()->query()->retrieve(
38  "target",
39  $refinery->to()->string()
40  )
41  : null;
42  if ($target !== null) {
43  $target_parts = explode('_', $target);
44  if (isset($target_parts[0]) && array_key_exists($target_parts[0], $handlers)) {
45  return null;
46  }
47 
48  return new Request(
50  null,
51  [LegacyGotoHandler::TARGET => $target]
52  );
53  }
54 
55  // try build target from path (since URL has been rewritten to goto/...)
56  $path = $http->request()->getUri()->getPath();
57  // get everything after /goto.php/ ot /go/
58  if (str_contains($path, StandardURIBuilder::LONG)) {
60  }
61 
62  if (str_contains($path, StandardURIBuilder::SHORT)) {
64  }
66  $target_parts = explode('/', $path);
67  if (isset($target_parts[0]) && array_key_exists($target_parts[0], $handlers)) {
68  return null;
69  }
70  $ref_id = null;
71  if (isset($target_parts[1]) && is_numeric($target_parts[1])) {
72  $ref_id = new ReferenceId((int) $target_parts[1]);
73  $target = $target_parts[2] ?? '';
74  } else {
75  $target = $target_parts[1] ?? '';
76  }
77 
78  return new Request(
80  $ref_id,
81  [LegacyGotoHandler::TARGET => str_replace('/', '_', $path)]
82  );
83  }
84 }
Interface Observer Contains several chained tasks and infos about them.
buildRequest(\ILIAS\HTTP\Services $http, Factory $refinery, array $handlers)
$http
Definition: deliver.php:14
$path
Definition: ltiservices.php:30
$ref_id
Definition: ltiauth.php:66
to()
Combined validations and transformations for primitive data types that establish a baseline for furth...
Definition: Factory.php:42