ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
RequestFactoryImpl.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\HTTP\Request;
20 
23 
39 {
43  private const DEFAULT_FORWARDED_HEADER = 'X-Forwarded-Proto';
47  private const DEFAULT_FORWARDED_PROTO = 'https';
48 
49  public function __construct(
50  private ?string $forwarded_header = null,
51  private ?string $forwarded_proto = null
52  ) {
53  }
54 
55  public function create(): ServerRequestInterface
56  {
57  $server_request = ServerRequest::fromGlobals();
58 
59  if ($this->forwarded_header !== null && $this->forwarded_proto !== null) {
60  if (in_array(
61  $this->forwarded_proto,
62  $server_request->getHeader($this->forwarded_header),
63  true
64  )) {
65  return $server_request->withUri($server_request->getUri()->withScheme($this->forwarded_proto));
66  }
67 
68  // alternative if ini settings are used which look like X_FORWARDED_PROTO
69  $header_names = array_keys($server_request->getHeaders());
70  foreach ($header_names as $header_name) {
71  if (str_replace("-", "_", strtoupper($header_name)) !== $this->forwarded_header) {
72  continue;
73  }
74  if (!in_array($this->forwarded_proto, $server_request->getHeader($header_name), true)) {
75  continue;
76  }
77  return $server_request->withUri($server_request->getUri()->withScheme($this->forwarded_proto));
78  }
79  }
80 
81  return $server_request;
82  }
83 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private ?string $forwarded_header=null, private ?string $forwarded_proto=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
create()
Creates a new ServerRequest object with the help of the underlying library.