ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
RequestFactoryImpl.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\HTTP\Request;
20
21use GuzzleHttp\Psr7\ServerRequest;
22use Psr\Http\Message\ServerRequestInterface;
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}
__construct(private ?string $forwarded_header=null, private ?string $forwarded_proto=null)
create()
Creates a new ServerRequest object with the help of the underlying library.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...