ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\HTTP\Request\RequestFactoryImpl Class Reference
+ Inheritance diagram for ILIAS\HTTP\Request\RequestFactoryImpl:
+ Collaboration diagram for ILIAS\HTTP\Request\RequestFactoryImpl:

Public Member Functions

 __construct (private ?string $forwarded_header=null, private ?string $forwarded_proto=null)
 
 create ()
 Creates a new ServerRequest object with the help of the underlying library. More...
 

Private Attributes

const DEFAULT_FORWARDED_HEADER = 'X-Forwarded-Proto'
 
const DEFAULT_FORWARDED_PROTO = 'https'
 

Detailed Description

Definition at line 38 of file RequestFactoryImpl.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\HTTP\Request\RequestFactoryImpl::__construct ( private ?string  $forwarded_header = null,
private ?string  $forwarded_proto = null 
)

Definition at line 43 of file RequestFactoryImpl.php.

46  {
47  }

Member Function Documentation

◆ create()

ILIAS\HTTP\Request\RequestFactoryImpl::create ( )

Creates a new ServerRequest object with the help of the underlying library.

Implements ILIAS\HTTP\Request\RequestFactory.

Definition at line 49 of file RequestFactoryImpl.php.

49  : ServerRequestInterface
50  {
51  $server_request = ServerRequest::fromGlobals();
52 
53  if ($this->forwarded_header !== null && $this->forwarded_proto !== null) {
54  if (in_array(
55  $this->forwarded_proto,
56  $server_request->getHeader($this->forwarded_header),
57  true
58  )) {
59  return $server_request->withUri($server_request->getUri()->withScheme($this->forwarded_proto));
60  }
61 
62  // alternative if ini settings are used which look like X_FORWARDED_PROTO
63  $header_names = array_keys($server_request->getHeaders());
64  foreach ($header_names as $header_name) {
65  if (str_replace("-", "_", strtoupper($header_name)) !== $this->forwarded_header) {
66  continue;
67  }
68  if (!in_array($this->forwarded_proto, $server_request->getHeader($header_name), true)) {
69  continue;
70  }
71  return $server_request->withUri($server_request->getUri()->withScheme($this->forwarded_proto));
72  }
73  }
74 
75  return $server_request;
76  }

Field Documentation

◆ DEFAULT_FORWARDED_HEADER

const ILIAS\HTTP\Request\RequestFactoryImpl::DEFAULT_FORWARDED_HEADER = 'X-Forwarded-Proto'
private

Definition at line 40 of file RequestFactoryImpl.php.

◆ DEFAULT_FORWARDED_PROTO

const ILIAS\HTTP\Request\RequestFactoryImpl::DEFAULT_FORWARDED_PROTO = 'https'
private

Definition at line 41 of file RequestFactoryImpl.php.


The documentation for this class was generated from the following file: